From 6e6cfa214b5a82f3027f2051d18f2f0d7707802e Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Fri, 19 Jan 2024 23:55:45 +0000 Subject: [PATCH] feat(endpoint-micropub): add jam to post type discovery --- .../lib/post-type-discovery.js | 6 ++++++ .../test/unit/post-type-discovery.js | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/packages/endpoint-micropub/lib/post-type-discovery.js b/packages/endpoint-micropub/lib/post-type-discovery.js index 0061aeb8b..c886a730f 100644 --- a/packages/endpoint-micropub/lib/post-type-discovery.js +++ b/packages/endpoint-micropub/lib/post-type-discovery.js @@ -20,6 +20,7 @@ export const getPostType = (properties) => { basePostTypes.set("quotation-of", "quotation"); basePostTypes.set("like-of", "like"); basePostTypes.set("checkin", "checkin"); + basePostTypes.set("jam-of", "jam"); basePostTypes.set("listen-of", "listen"); basePostTypes.set("read-of", "read"); basePostTypes.set("watch-of", "watch"); @@ -51,6 +52,11 @@ export const getPostType = (properties) => { content = properties.summary; } + // Check of post could be a jam + if (content.includes("http", 2) && content.startsWith("🎵 ")) { + return "jam"; + } + // Check if post could be an article if (propertiesMap.has("name") && propertiesMap.has("content")) { const name = properties.name.trim(); diff --git a/packages/endpoint-micropub/test/unit/post-type-discovery.js b/packages/endpoint-micropub/test/unit/post-type-discovery.js index 966735336..3b06f7125 100644 --- a/packages/endpoint-micropub/test/unit/post-type-discovery.js +++ b/packages/endpoint-micropub/test/unit/post-type-discovery.js @@ -32,6 +32,27 @@ describe("endpoint-media/lib/post-type-discovery", () => { assert.equal(result, "note"); }); + it("Discovers jam post type (from content)", () => { + const result = getPostType({ + type: "entry", + content: + "🎵 https://music.apple.com/gb/album/love-story-taylors-version/1552791073?i=1552791427", + }); + + assert.equal(result, "jam"); + }); + + it("Discovers jam post type (from property)", () => { + const result = getPostType({ + type: "entry", + name: "Jam title", + "jam-of": + "https://music.apple.com/gb/album/love-story-taylors-version/1552791073?i=1552791427", + }); + + assert.equal(result, "jam"); + }); + it("Discovers article post type", () => { const result = getPostType({ type: "entry",