Skip to content

Commit

Permalink
feat(endpoint-micropub): add jam to post type discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Jan 20, 2024
1 parent 0778519 commit 6e6cfa2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/endpoint-micropub/lib/post-type-discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down
21 changes: 21 additions & 0 deletions packages/endpoint-micropub/test/unit/post-type-discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6e6cfa2

Please sign in to comment.