also grab the name property from microformat2

This commit is contained in:
Wouter Groeneveld 2021-03-09 16:18:03 +01:00
parent 94939baaf3
commit 336f05bbb2
2 changed files with 15 additions and 4 deletions

View File

@ -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>(.*?)<\/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
}

View File

@ -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"