diff --git a/helpers/fixtures/jf2/note-slug-missing-no-name.jf2 b/helpers/fixtures/jf2/note-slug-missing-no-name.jf2 deleted file mode 100644 index c6375e3af..000000000 --- a/helpers/fixtures/jf2/note-slug-missing-no-name.jf2 +++ /dev/null @@ -1,4 +0,0 @@ -{ - "type": "entry", - "content": "I ate a cheese sandwich, which was nice." -} diff --git a/packages/endpoint-micropub/lib/jf2.js b/packages/endpoint-micropub/lib/jf2.js index 0bf4ac19c..8ac83ddd8 100644 --- a/packages/endpoint-micropub/lib/jf2.js +++ b/packages/endpoint-micropub/lib/jf2.js @@ -1,4 +1,4 @@ -import { getDate, randomString, slugify } from "@indiekit/util"; +import { getDate, md5, slugify } from "@indiekit/util"; import { fetchReferences, mf2tojf2, @@ -236,7 +236,7 @@ export const getVideoProperty = (properties, me) => { */ export const getSlugProperty = (properties, separator) => { const suggested = properties["mp-slug"]; - const { name } = properties; + const { name, published } = properties; let string; if (suggested) { @@ -244,9 +244,7 @@ export const getSlugProperty = (properties, separator) => { } else if (name) { string = excerptString(name, 5); } else { - string = randomString(5) - .replace("_", "0") // Slugify function strips any leading underscore - .replace(separator, "0"); // Don’t include slug separator character + string = md5(published).slice(0, 5); } return slugify(string, { separator }); diff --git a/packages/endpoint-micropub/test/unit/jf2.js b/packages/endpoint-micropub/test/unit/jf2.js index d7bf0997b..e336ecee1 100644 --- a/packages/endpoint-micropub/test/unit/jf2.js +++ b/packages/endpoint-micropub/test/unit/jf2.js @@ -323,7 +323,7 @@ describe("endpoint-micropub/lib/jf2", () => { it("Derives slug by generating random string", () => { const properties = JSON.parse( - getFixture("jf2/note-slug-missing-no-name.jf2"), + getFixture("jf2/note-published-provided.jf2"), ); const result = getSlugProperty(properties, "-");