Skip to content

Commit

Permalink
fix: always use mp-slug key for slug property
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Jan 3, 2021
1 parent b67a7d8 commit 49a2bf1
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 14 deletions.
5 changes: 5 additions & 0 deletions packages/endpoint-media/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export const renderPath = (path, properties, timeZoneSetting) => {
// Add day of the year (NewBase60) token
tokens.D60 = newbase60.DateToSxg(dateObject); // eslint-disable-line new-cap

// Add slug token if 'mp-slug' property
if (properties['mp-slug']) {
tokens.slug = properties['mp-slug'];
}

// Add UUID token
tokens.uuid = uuidv4();

Expand Down
4 changes: 2 additions & 2 deletions packages/endpoint-media/tests/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ test('Generates random alpha-numeric string, 5 characters long', t => {

test('Renders path from URI template and properties', t => {
const properties = {
slug: 'foo',
published: '2020-01-01'
published: '2020-01-01',
'mp-slug': 'foo'
};
const template = '{yyyy}/{MM}/{uuid}/{slug}';
const result = renderPath(template, properties);
Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint-micropub/lib/microformats.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const getMf2 = (publication, mf2) => {
}

mf2.properties.published = getPublishedProperty(mf2, timeZone);
mf2.properties.slug = getSlugProperty(mf2, slugSeparator);
mf2.properties['mp-slug'] = getSlugProperty(mf2, slugSeparator);

if (mf2.properties.content) {
mf2.properties.content = getContentProperty(mf2);
Expand Down
5 changes: 5 additions & 0 deletions packages/endpoint-micropub/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ export const renderPath = (path, properties, timeZoneSetting) => {
// Add day of the year (NewBase60) token
tokens.D60 = newbase60.DateToSxg(dateObject); // eslint-disable-line new-cap

// Add slug token if 'mp-slug' property
if (properties['mp-slug']) {
tokens.slug = properties['mp-slug'];
}

// Add UUID token
tokens.uuid = uuidv4();

Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint-micropub/tests/lib/microformats.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test('Gets Microformats2 object (few properties)', t => {
const result = getMf2(t.context.publication, mf2);
t.is(result.type[0], 'h-entry');
t.is(result.properties.name[0], 'Lunchtime');
t.is(result.properties.slug[0], 'lunchtime');
t.is(result.properties['mp-slug'][0], 'lunchtime');
t.deepEqual(result.properties.content, [{
value: 'I ate a *cheese* sandwich, which was nice.',
html: '<p>I ate a <em>cheese</em> sandwich, which was nice.</p>'
Expand Down
10 changes: 5 additions & 5 deletions packages/endpoint-micropub/tests/lib/post-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test.beforeEach(t => {
content: 'hello world',
published: '2019-08-17T23:56:38.977+01:00',
category: ['foo', 'bar'],
slug: 'baz',
'mp-slug': 'baz',
'mp-syndicate-to': 'https://archive.org/',
'post-type': 'note',
url
Expand All @@ -27,7 +27,7 @@ test.beforeEach(t => {
content: ['hello world'],
published: ['2019-08-17T23:56:38.977+01:00'],
category: ['foo', 'bar'],
slug: ['baz'],
'mp-slug': ['baz'],
'mp-syndicate-to': ['https://archive.org/']
}
}
Expand All @@ -46,12 +46,12 @@ test('Creates post data', async t => {
properties: {
published: ['2020-07-26T20:10:57.062Z'],
name: ['Foo'],
slug: ['foo']
'mp-slug': ['foo']
}
};
const result = await postData.create(t.context.publication, mf2);
t.is(result.properties['post-type'], 'note');
t.is(result.properties.slug, 'foo');
t.is(result.properties['mp-slug'], 'foo');
t.is(result.properties.type, 'entry');
t.is(result.properties.url, 'https://website.example/notes/2020/07/26/foo');
});
Expand All @@ -62,7 +62,7 @@ test('Throws error creating post data without publication configuration', async
properties: {
published: ['2020-07-26T20:10:57.062Z'],
name: ['Foo'],
slug: ['foo']
'mp-slug': ['foo']
}
};
const error = await t.throwsAsync(postData.create(false, mf2));
Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint-micropub/tests/lib/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test.beforeEach(t => {
content: ['hello world'],
published: ['2019-08-17T23:56:38.977+01:00'],
category: ['foo', 'bar'],
slug: ['baz']
'mp-slug': ['baz']
};
});

Expand Down
4 changes: 2 additions & 2 deletions packages/endpoint-micropub/tests/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ test('Generates random alpha-numeric string, 5 characters long', t => {

test('Renders path from URI template and properties', t => {
const properties = {
slug: 'foo',
published: '2020-01-01'
published: '2020-01-01',
'mp-slug': 'foo'
};
const template = '{yyyy}/{MM}/{uuid}/{slug}';
const result = renderPath(template, properties);
Expand Down
4 changes: 2 additions & 2 deletions packages/endpoint-syndicate/tests/fixtures/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ export const posts = {
findOne: async () => ({
properties: {
name: 'Item in database',
slug: '12345',
published: '2020-10-17T19:41:39Z',
url: 'https://paulrobertlloyd.github.io/indiekit-sandbox/notes/2020/10/17/12345',
'mp-slug': '12345',
'mp-syndicate-to': 'https://social.example/'
},
mf2: {
type: ['h-entry'],
properties: {
name: ['Item in database'],
slug: ['12345'],
published: ['2020-10-17T19:41:39Z'],
url: ['https://paulrobertlloyd.github.io/indiekit-sandbox/notes/2020/10/17/12345'],
'mp-slug': ['12345'],
'mp-syndicate-to': ['https://social.example/']
}
}
Expand Down

0 comments on commit 49a2bf1

Please sign in to comment.