Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Micropub CRUD on contacts #30

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/http/get-micropub/config/post-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
26 changes: 25 additions & 1 deletion src/http/post-micropub/micropub/create.js
Original file line number Diff line number Diff line change
@@ -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 = ''
Expand All @@ -16,6 +26,13 @@ function deriveUrl (post) {
slug = post.properties['mp-slug'][0]
}
}

if (post.channel === 'contacts') {
return `contacts/${post.properties.nickname[0]}`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test input will need to change as we've not done it quite this way

}

console.log(JSON.stringify(post));

const published = new Date(post.properties.published[0])
const yyyy = published.getFullYear().toString()
const m = (published.getMonth() + 1).toString()
Expand Down Expand Up @@ -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
}

Expand Down
9 changes: 0 additions & 9 deletions src/http/post-micropub/micropub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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']
Expand Down
5 changes: 5 additions & 0 deletions src/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const reservedUrls = `
notes
articles
bookmarks
contacts
photos
checkins
reposts
Expand All @@ -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) {
Expand Down