Editorial Workflows

MicroPub

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: Publishes the current document to a Micropub endpoint using the current IndieAuth authorization set up using the "IndieAuth" workflow.

Adds YAML Front Matter variables as extra Micropub properties and if the first content of a Markdown document (ignoring any YAML Front Matter) is a first level header, then that header is extracted as the Micropub "name" property.

Requires an up to date Micropub endpoint that accepts HTML as "content[html]" rather than just "content".

Strongly inspired by the "RV: Publish Jekyll Post" workflow.

Shared by: VoxPelli

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Sub-Workflow ?
Workflow
Can Stop Main Workflow
ON
Set Variable ?
Variable Name
indie_token
Value
Input
Set Variable ?
Variable Name
micropub_endpoint_file
Value
/.micropub-endpoint
Get File Contents ?
File Name
%var:micropub_endpoint_file
In Dropbox
OFF
If File Does Not Exist
  • Empty Output
  • Stop Workflow
Set Variable ?
Variable Name
micropub_endpoint
Value
Input
Show Alert ?
Title
Publish to this MicroPub endpoint?
Message
micropub_endpoint
Button 1
Yes
Output Value
micropub_endpoint
Button 2
No
Output Value
Button 3
(don't show)
Output Value
Show Cancel Button
ON
If… ?
Run the block if
Input
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Request Text Input ?
Title
Specify a MicroPub endpoint
Initial Text
micropub_endpoint
  • Single Line
  • Multiple Lines
Keyboard Options:
Set Variable ?
Variable Name
micropub_endpoint
Value
Input
Set File Contents ?
File Name
%var:micropub_endpoint_file
In Dropbox
OFF
New Text
micropub_endpoint
If File Does Not Exist
  • Create
  • Stop Workflow
…End If
If… ?
Run the block if
micropub_endpoint
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
ON
Message
No MicroPub endpoint set
…End If
Get Current File Name ?
Include Folder
OFF
Include Extension
OFF
Set Variable ?
Variable Name
micropub_slug
Value
Input
Set Variable ?
Variable Name
micropub_yaml_regexp
Value
^(?:---\n)((?:.|\n)+)---\n
Document Text ?
Folded Text
  • Include
  • Replace with:
Find ?
Search for
micropub_yaml_regexp
Match Group (RegEx)
1
Search Type
  • Regular Expression
  • Case-insensitive Search (A = a)
  • Case-sensitive Search (A ≠ a)
Output
  • Found Text
  • Range of Text (from:to)
Set Variable ?
Variable Name
micropub_yaml
Value
Input
Document Text ?
Folded Text
  • Include
  • Replace with:
Find / Replace ?
Find
micropub_yaml_regexp
  • Case-insensitive (A = a)
  • Case-sensitive (A ≠ a)
  • Regular Expression
Replace with
If… ?
Run the block if
%editor:syntax-mode
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
markdown
Find ?
Search for
^#\s+(.+)$
Match Group (RegEx)
1
Search Type
  • Regular Expression
  • Case-insensitive Search (A = a)
  • Case-sensitive Search (A ≠ a)
Output
  • Found Text
  • Range of Text (from:to)
Set Variable ?
Variable Name
micropub_name
Value
Input
Document Text ?
Folded Text
  • Include
  • Replace with:
Find / Replace ?
Find
micropub_yaml_regexp
  • Case-insensitive (A = a)
  • Case-sensitive (A ≠ a)
  • Regular Expression
Replace with
Find / Replace ?
Find
^#\s+(.+)$
  • Case-insensitive (A = a)
  • Case-sensitive (A ≠ a)
  • Regular Expression
Replace with
Convert Markdown ?
Markdown Extras: Footnotes
ON
…Auto-Links
ON
…Strikethrough (~~x~~)
ON
…Superscript (^x)
ON
…Tables
ON
…Smart Quotes etc.
ON
…Strip Metadata Headers
OFF
…End If
Run Python Script ?
Source Code
#coding: utf-8
import workflow, console, requests, clipboard, yaml, datetime

token = workflow.get_variable('indie_token')
endpoint = workflow.get_variable('micropub_endpoint')
slug = workflow.get_variable('micropub_slug')
name = workflow.get_variable('micropub_name')
yamlData = workflow.get_variable('micropub_yaml')
content = workflow.get_input()

if yamlData:
	yamlData = yaml.safe_load(yamlData)

headers = {}
headers['Authorization'] = 'bearer ' + token

if yamlData:
	data = yamlData
else:
	data = {}

data['h'] = 'entry'
# data['slug'] = slug
data['content[html]'] = content

try:
	data['published'] = data['published']
except:
	data['published'] = datetime.datetime.now().isoformat()

if name is not None and name != '':
	data['name'] = name

console.show_activity()
result = requests.post(endpoint, headers=headers, data=data);
console.hide_activity()

if result.status_code != 201:
	console.hud_alert('Failed to publish post with status code: %d' % result.status_code, 'error')
	workflow.stop()

if result.headers['location'] is not None:
	location = result.headers['location']

	clipboard.set(location)
	workflow.set_output(location);

	yamlData = workflow.get_variable('micropub_yaml')
	if yamlData:
		yamlData = yaml.load(yamlData)
	if not yamlData:
		yamlData = {}
	yamlData['url'] = location;
	yamlData['published'] = data['published'];
	yamlData = yaml.dump(yamlData, default_flow_style=False);
	workflow.set_variable('micropub_yaml', yamlData)
	
else:
	console.hud_alert('Published post', 'success')
If… ?
Run the block if
Input
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Set Variable ?
Variable Name
micropub_url
Value
Input
Document Text ?
Folded Text
  • Include
  • Replace with:
Find ?
Search for
micropub_yaml_regexp
Match Group (RegEx)
1
Search Type
  • Regular Expression
  • Case-insensitive Search (A = a)
  • Case-sensitive Search (A ≠ a)
Output
  • Found Text
  • Range of Text (from:to)
Run Python Script ?
Source Code
#coding: utf-8
import workflow, editor, console

pos = workflow.get_input()
content = workflow.get_variable('micropub_yaml');

pos = workflow.get_input().split(':')

if pos[0] == '0':
	content = '---\n' + content + '---\n\n'

editor.replace_text(int(pos[0]), int(pos[1]), content)
	
Show HUD ?
HUD Text
Published post and copied URL to clipboard
Duration
  • 1 Second
  • 2 Seconds
  • 3 Seconds
Icon
  • "Success"
  • "Error"
Share Text or URL ?
Text
micropub_urlget
Share as
  • Text
  • URL
…End If