From 336f05bbb2594c0ac82f4f249a90b86002d34bdf Mon Sep 17 00:00:00 2001 From: wgroeneveld Date: Tue, 9 Mar 2021 16:18:03 +0100 Subject: [PATCH] also grab the name property from microformat2 --- src/webmention/receive.js | 12 +++++++++--- test/webmention/receive-process.test.js | 7 ++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/webmention/receive.js b/src/webmention/receive.js index 1d77a4e..213ce8a 100644 --- a/src/webmention/receive.js +++ b/src/webmention/receive.js @@ -76,12 +76,14 @@ function parseBodyAsIndiewebSite(source, target, hEntry) { return txt.substring(0, 250) + "..." } + const name = hEntry.properties?.name?.[0] const authorPropName = hEntry.properties?.author?.[0]?.properties?.name?.[0] const authorValue = hEntry.properties?.author?.[0]?.value const picture = hEntry.properties?.author?.[0]?.properties?.photo?.[0] const summary = hEntry.properties?.summary?.[0] const contentEntry = hEntry.properties?.content?.[0]?.value const publishedDate = hEntry.properties?.published?.[0] + const uid = hEntry.properties?.uid?.[0] const url = hEntry.properties?.url?.[0] return { @@ -89,23 +91,27 @@ function parseBodyAsIndiewebSite(source, target, hEntry) { name: authorPropName ? authorPropName : authorValue, picture: picture.value ? picture.value : picture }, + name: name, content: summary ? shorten(summary) : shorten(contentEntry), published: publishedDate ? publishedDate : publishedNow(), - url: url ? url : source, + // Mastodon uids start with "tag:server", but we do want indieweb uids from other sources + url: uid && uid.startsWith("http") ? uid : (url ? url : source), source, target } } function parseBodyAsNonIndiewebSite(source, target, body) { - const content = body.match(/(.*?)<\/title>/)?.splice(1, 1)[0] + const title = body.match(/<title>(.*?)<\/title>/)?.splice(1, 1)[0] return { author: { name: source }, - content, + name: title, + content: title, published: publishedNow(), + url: source, source, target } diff --git a/test/webmention/receive-process.test.js b/test/webmention/receive-process.test.js index beadbff..7c27902 100644 --- a/test/webmention/receive-process.test.js +++ b/test/webmention/receive-process.test.js @@ -43,6 +43,7 @@ describe("receive webmention process tests happy path", () => { }, url: "https://social.linux.pizza/@StampedingLonghorn/105821099684887793", content: "@wouter The cat pictures are awesome. for jest tests!", + name: "@wouter The cat pictures are awesome. for jest tests!", source: body.source, target: body.target, published: "2021-03-02T16:17:18.000Z" @@ -66,6 +67,7 @@ describe("receive webmention process tests happy path", () => { }, url: "https://brainbaking.com/notes/2021/03/06h12m41s48/", content: "This is cool, I just found out about valid indieweb target - so cool", + name: "I just learned about https://www.inklestudios.com/...", source: body.source, target: body.target, published: "2021-03-06T12:41:00" @@ -87,7 +89,8 @@ describe("receive webmention process tests happy path", () => { name: "Wouter Groeneveld", picture: "https://brainbaking.com//img/avatar.jpg" }, - url: "https://brainbaking.com/notes/2021/03/06h12m41s48/", + url: "https://brainbaking.com/notes/2021/03/06h12m41s48/", + name: "I just learned about https://www.inklestudios.com/...", content: "This is cool, this is a summary!", source: body.source, target: body.target, @@ -110,6 +113,8 @@ describe("receive webmention process tests happy path", () => { name: "https://brainbaking.com/valid-nonindieweb-source.html", }, content: "Diablo 2 Twenty Years Later: A Retrospective | Jefklaks Codex", + name: "Diablo 2 Twenty Years Later: A Retrospective | Jefklaks Codex", + url: body.source, source: body.source, target: body.target, published: "2020-01-01T01:00:00"