diff --git a/src/http/get-micropub/config/post-types.js b/src/http/get-micropub/config/post-types.js index 7cb1473..a614e08 100644 --- a/src/http/get-micropub/config/post-types.js +++ b/src/http/get-micropub/config/post-types.js @@ -33,6 +33,22 @@ module.exports = [ type: 'bookmark', name: 'Bookmark' }, + { + type: 'contact', + name: 'Contacts', + properties: [ + 'name', + 'nickname', + 'url', + 'photo', + 'rel=twitter' + ], + 'required-properties': [ + 'name', + 'nickname', + 'url' + ] + }, { type: 'photo', name: 'Photo' diff --git a/src/http/post-micropub/micropub/create.js b/src/http/post-micropub/micropub/create.js index 55aed91..cc231c6 100644 --- a/src/http/post-micropub/micropub/create.js +++ b/src/http/post-micropub/micropub/create.js @@ -1,5 +1,15 @@ const arc = require('@architect/functions') -const { reservedUrls } = require('@architect/shared/utils') +const { derivePostType, reservedUrls } = require('@architect/shared/utils') + +function setChannel (post) { + if ('mp-channel' in post.properties) { + post.channel = post.properties['mp-channel'][0] + } else if (post['post-type'] === 'contact') { + post.channel = 'contacts' + } else if (!('channel' in post)) { + post.channel = 'posts' // default channel is posts + } +} function deriveUrl (post) { let slug = '' @@ -16,6 +26,13 @@ function deriveUrl (post) { slug = post.properties['mp-slug'][0] } } + + if (post.channel === 'contacts') { + return `contacts/${post.properties.nickname[0]}` + } + + console.log(JSON.stringify(post)); + const published = new Date(post.properties.published[0]) const yyyy = published.getFullYear().toString() const m = (published.getMonth() + 1).toString() @@ -75,7 +92,14 @@ function formatPost (body) { : new Date().toISOString()] // store type as simple value post.type = post.type[0] + + post['post-type'] = derivePostType(post) + console.log({post}); + setChannel(post) + console.log({post}); + post.url = deriveUrl(post) + console.log({post}); return post } diff --git a/src/http/post-micropub/micropub/index.js b/src/http/post-micropub/micropub/index.js index 21527d5..0e6196a 100644 --- a/src/http/post-micropub/micropub/index.js +++ b/src/http/post-micropub/micropub/index.js @@ -10,11 +10,6 @@ const undelete = require('./undelete') function setRootProperties (post) { // set published to utc date without seconds post.published = new Date(post.properties.published[0]).toISOString().replace(/\.000Z$/, 'Z') - if ('mp-channel' in post.properties) { - post.channel = post.properties['mp-channel'][0] - } else if (!('channel' in post)) { - post.channel = 'posts' // default channel is posts - } } function sanitise (post) { @@ -59,10 +54,6 @@ async function action (scope, body) { // remove unwanted properties sanitise(res.post) - // derive the post type - res.post['post-type'] = derivePostType(res.post) - - // find syndication options let syndicateTo if ('mp-syndicate-to' in body) { syndicateTo = body['mp-syndicate-to'] diff --git a/src/shared/utils.js b/src/shared/utils.js index 2673388..3c4ce57 100644 --- a/src/shared/utils.js +++ b/src/shared/utils.js @@ -3,6 +3,7 @@ const reservedUrls = ` notes articles bookmarks + contacts photos checkins reposts @@ -14,6 +15,10 @@ const reservedUrls = ` `.trim().split(/\s+/) function derivePostType (post) { + if (post.type === 'h-card') { + return 'contact' + } + // See https://www.w3.org/TR/post-type-discovery/ let content = '' if ('content' in post.properties) {