Skip to content

Commit 2ea5a8c

Browse files
feat(endpoint-micropub): use md5 hash of published date as final option for a slug
this means the value stays the same, and doesn’t change each time a post is re-created
1 parent b09a8c4 commit 2ea5a8c

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

helpers/fixtures/jf2/note-slug-missing-no-name.jf2

-4
This file was deleted.

packages/endpoint-micropub/lib/jf2.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getDate, randomString, slugify } from "@indiekit/util";
1+
import { getDate, md5, slugify } from "@indiekit/util";
22
import {
33
fetchReferences,
44
mf2tojf2,
@@ -236,17 +236,15 @@ export const getVideoProperty = (properties, me) => {
236236
*/
237237
export const getSlugProperty = (properties, separator) => {
238238
const suggested = properties["mp-slug"];
239-
const { name } = properties;
239+
const { name, published } = properties;
240240

241241
let string;
242242
if (suggested) {
243243
string = suggested;
244244
} else if (name) {
245245
string = excerptString(name, 5);
246246
} else {
247-
string = randomString(5)
248-
.replace("_", "0") // Slugify function strips any leading underscore
249-
.replace(separator, "0"); // Don’t include slug separator character
247+
string = md5(published).slice(0, 5);
250248
}
251249

252250
return slugify(string, { separator });

packages/endpoint-micropub/test/unit/jf2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ describe("endpoint-micropub/lib/jf2", () => {
323323

324324
it("Derives slug by generating random string", () => {
325325
const properties = JSON.parse(
326-
getFixture("jf2/note-slug-missing-no-name.jf2"),
326+
getFixture("jf2/note-published-provided.jf2"),
327327
);
328328
const result = getSlugProperty(properties, "-");
329329

0 commit comments

Comments
 (0)