Browse Source

Enable use of string payload

master
Peter Stuifzand 3 years ago
parent
commit
0d8034eb5f
  1. 3
      micropub-create.html
  2. 22
      micropub-create.js

3
micropub-create.html

@ -34,8 +34,7 @@
<p>Posts to Micropub endpoints</p>
<p>Connect to your Micropub powered blog and post messages.</p>
<p>Input Parameters:</p>
<p><code>msg.type</code> - Default: 'json'
<p><code>msg.payload</code> - Should be an Micropub object using MF2.</p>
<p><code>msg.payload</code> - Should be an Micropub object using MF2, it will be sent without modification to the endpoint. If the payload is a string, it will be sent as a content value.</p>
<p><code>msg.payload.type</code> - Should be an array with the type.</p>
<p><code>msg.payload.properties</code> - Should be on object with MF2 properties.</p>
<p><code>msg.payload.properties.name</code> - Should be an array with a string.</p>

22
micropub-create.js

@ -6,7 +6,7 @@ module.exports = function (RED) {
this.endpoint = RED.nodes.getNode(config.endpoint);
var node = this;
const node = this;
node.on('input', function (msg) {
try {
@ -14,8 +14,22 @@ module.exports = function (RED) {
micropubEndpoint: node.endpoint.credentials.micropub_endpoint,
token: node.endpoint.credentials.auth_token
});
var location = micropub.postMicropub(msg.payload);
msg.location = location;
let entry = {};
if (typeof msg.payload === 'string') {
entry.type = ['h-entry'];
entry.properties = {
content: [{
value: msg.payload
}]
};
} else if (msg.payload.hasOwnProperty('type') && msg.payload.hasOwnProperty('properties')) {
entry = msg.payload;
}
msg.payload = entry;
msg.location = micropub.postMicropub(entry);
node.send(msg);
} catch (e) {
node.error(e);
@ -24,5 +38,5 @@ module.exports = function (RED) {
}
RED.nodes.registerType("micropub-create", MicropubNode);
}
};
Loading…
Cancel
Save