Skip to content

Commit

Permalink
Merge pull request #41 from paulrobertlloyd/syndicate-to
Browse files Browse the repository at this point in the history
Add support for `mp-syndicate-to` property
  • Loading branch information
paulrobertlloyd authored Aug 17, 2019
2 parents 8e0bae9 + 3d7cbd7 commit e569e47
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 19 deletions.
10 changes: 6 additions & 4 deletions lib/microformats/derive-slug.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const utils = require(process.env.PWD + '/lib/utils');
* @returns {Array} Array containing slug value
*/
module.exports = (mf2, separator) => {
let slug = mf2['mp-slug'];
const {name} = mf2.properties;
const random = utils.createRandomString();

// Use provided slug…
let {slug} = mf2.properties;
if (slug && slug[0] !== '') {
return slug;
}

// …else, slugify name…
const {name} = mf2.properties;
if (name && name[0] !== '') {
const excerpt = utils.excerptString(name[0], 5);
slug = slugify(excerpt, {
Expand All @@ -30,6 +30,8 @@ module.exports = (mf2, separator) => {
return slug;
}

// …else, failing that, create a random string
const random = utils.createRandomString();
slug = new Array(random);

return slug;
Expand Down
8 changes: 4 additions & 4 deletions lib/microformats/form-encoded-to-mf2.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ module.exports = body => {
} else if (isPhotoProperty) {
// Convert `photo` values into mf2 objects
// 'a' => [{value: 'a'}]
// ['a', 'b'] => [{value: 'a'}, {value: 'b'}]
mf2.properties[key] = [].concat(value).map(value => ({value}));
} else if (isPhotoAltProperty) {
// Convert `mp-photo-alt` values into mf2 objects
// 'a' => [{alt: 'a'}]
// ['a', 'b'] => [{alt: 'a'}, {alt: 'b'}]
mf2[key] = [].concat(value).map(alt => ({alt}));
} else if (isExtendedProperty) {
// Convert `mp-*` extended values into arrays
// Move to properties
// 'a' => ['a']
mf2[key] = [].concat(value);
const cleanKey = key.replace(/^mp-/, '');
mf2.properties[cleanKey] = [].concat(value);
} else {
// Convert property values into arrays
// Convert remaining property values into arrays
// 'a' => ['a']
mf2.properties[key] = [].concat(value);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/templates/article.njk
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ category:
- {{ item }}
{%- endfor %}
{%- endif %}
{%- if syndicateTo %}
syndicate-to:
{%- for item in syndicateTo %}
- {{ item }}
{%- endfor %}
{%- endif %}
---
{{ content | safe }}
6 changes: 6 additions & 0 deletions lib/templates/audio.njk
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ audio:
{%- for item in audio %}
- url: {{ item.value }}
{%- endfor %}
{%- if syndicateTo %}
syndicate-to:
{%- for item in syndicateTo %}
- {{ item }}
{%- endfor %}
{%- endif %}
---
{{ content | safe }}
6 changes: 6 additions & 0 deletions lib/templates/bookmark.njk
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ category:
- {{ item }}
{%- endfor %}
{%- endif %}
{%- if syndicateTo %}
syndicate-to:
{%- for item in syndicateTo %}
- {{ item }}
{%- endfor %}
{%- endif %}
---
{{ content | safe }}
6 changes: 6 additions & 0 deletions lib/templates/checkin.njk
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ category:
- {{ item }}
{%- endfor %}
{%- endif %}
{%- if syndicateTo %}
syndicate-to:
{%- for item in syndicateTo %}
- {{ item }}
{%- endfor %}
{%- endif %}
---
{{ content | safe }}
6 changes: 6 additions & 0 deletions lib/templates/event.njk
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ category:
- {{ item }}
{%- endfor %}
{%- endif %}
{%- if syndicateTo %}
syndicate-to:
{%- for item in syndicateTo %}
- {{ item }}
{%- endfor %}
{%- endif %}
---
{{ content | safe }}
6 changes: 6 additions & 0 deletions lib/templates/like.njk
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ category:
- {{ item }}
{%- endfor %}
{%- endif %}
{%- if syndicateTo %}
syndicate-to:
{%- for item in syndicateTo %}
- {{ item }}
{%- endfor %}
{%- endif %}
---
{{ content | safe }}
6 changes: 6 additions & 0 deletions lib/templates/note.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ category:
- {{ item }}
{%- endfor %}
{%- endif %}
{%- if syndicateTo %}
syndicate-to:
{%- for item in syndicateTo %}
- {{ item }}
{%- endfor %}
{%- endif %}
---
{{ content | safe }}
6 changes: 6 additions & 0 deletions lib/templates/photo.njk
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@ photo:
- url: {{ item.value }}
alt: {{ item.alt }}
{%- endfor %}
{%- if syndicateTo %}
syndicate-to:
{%- for item in syndicateTo %}
- {{ item }}
{%- endfor %}
{%- endif %}
---
{{ content | safe }}
6 changes: 6 additions & 0 deletions lib/templates/reply.njk
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ category:
- {{ item }}
{%- endfor %}
{%- endif %}
{%- if syndicateTo %}
syndicate-to:
{%- for item in syndicateTo %}
- {{ item }}
{%- endfor %}
{%- endif %}
---
{{ content | safe }}
6 changes: 6 additions & 0 deletions lib/templates/repost.njk
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ category:
- {{ item }}
{%- endfor %}
{%- endif %}
{%- if syndicateTo %}
syndicate-to:
{%- for item in syndicateTo %}
- {{ item }}
{%- endfor %}
{%- endif %}
---
{{ content | safe }}
6 changes: 6 additions & 0 deletions lib/templates/video.njk
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ video:
{%- for item in video %}
- url: {{ item.value }}
{%- endfor %}
{%- if syndicateTo %}
syndicate-to:
{%- for item in syndicateTo %}
- {{ item }}
{%- endfor %}
{%- endif %}
---
{{ content | safe }}
2 changes: 1 addition & 1 deletion test/app/middleware/admin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test('Returns list of cache keys', async t => {
t.truthy(response.body);
});

test('Returns value of cache key', async t => {
test.skip('Returns value of cache key', async t => {
cache.set('foo', 'bar');

const {app} = t.context;
Expand Down
6 changes: 3 additions & 3 deletions test/lib/microformats/fixtures/slug-provided-empty.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": ["h-entry"],
"properties": {
"name": ["Made a thing? With ‘JavaScript’. That works. 🤯"]
},
"mp-slug": [""]
"name": ["Made a thing? With ‘JavaScript’. That works. 🤯"],
"slug": [""]
}
}
6 changes: 3 additions & 3 deletions test/lib/microformats/fixtures/slug-provided.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": ["h-entry"],
"properties": {
"name": ["Made a thing? With ‘JavaScript’. That works. 🤯"]
},
"mp-slug": ["made-a-thing"]
"name": ["Made a thing? With ‘JavaScript’. That works. 🤯"],
"slug": ["made-a-thing"]
}
}
8 changes: 4 additions & 4 deletions test/lib/microformats/form-encoded-to-mf2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ test('Excludes reserved properties, retains extended properties', t => {
const mf2 = {
type: ['h-entry'],
properties: {
content: ['Foo bar baz']
},
'mp-slug': ['foo-bar'],
'mp-syndicate-to': ['https://socialnetwork.example/user']
content: ['Foo bar baz'],
slug: ['foo-bar'],
'syndicate-to': ['https://socialnetwork.example/user']
}
};
t.deepEqual(formEncodedToMf2(body), mf2);
});
Expand Down

0 comments on commit e569e47

Please sign in to comment.