diff --git a/README.md b/README.md
index ef99e4d..d7d02c8 100644
--- a/README.md
+++ b/README.md
@@ -40,3 +40,7 @@ Will result in a `202 Accepted` - it handles things async. Stores in `.json` fil
Retrieves a JSON array with relevant webmentions stored for that domain. The token should match. See `config.js` to fiddle with it yourself. Environment variables are supported, although I haven't used them yet.
+## TODOs
+
+- `published` date is not well-formatted and blindly taken over from feed
+
diff --git a/src/webmention/receive.js b/src/webmention/receive.js
index 8d360e8..1d77a4e 100644
--- a/src/webmention/receive.js
+++ b/src/webmention/receive.js
@@ -71,23 +71,30 @@ function publishedNow() {
}
function parseBodyAsIndiewebSite(source, target, hEntry) {
+ function shorten(txt) {
+ if(txt.length <= 250) return txt
+ return txt.substring(0, 250) + "..."
+ }
+
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]?.value
+ const picture = hEntry.properties?.author?.[0]?.properties?.photo?.[0]
const summary = hEntry.properties?.summary?.[0]
- const contentEntry = hEntry.properties?.content?.[0]?.value?.substring(0, 250) + "..."
+ const contentEntry = hEntry.properties?.content?.[0]?.value
const publishedDate = hEntry.properties?.published?.[0]
+ const url = hEntry.properties?.url?.[0]
return {
author: {
name: authorPropName ? authorPropName : authorValue,
- picture
+ picture: picture.value ? picture.value : picture
},
- content: summary ? summary : contentEntry,
+ content: summary ? shorten(summary) : shorten(contentEntry),
published: publishedDate ? publishedDate : publishedNow(),
+ url: url ? url : source,
source,
target
- }
+ }
}
function parseBodyAsNonIndiewebSite(source, target, body) {
diff --git a/test/__mocks__/valid-bridgy-source.html b/test/__mocks__/valid-bridgy-source.html
new file mode 100644
index 0000000..fe19e0d
--- /dev/null
+++ b/test/__mocks__/valid-bridgy-source.html
@@ -0,0 +1,60 @@
+
+
+
+
+
+@wouter
The cat pictures are awesome.
+
+
+
+ tag:chat.brainbaking.com,2013:A4nxN8ytch0BW2FVXU
+
+
+
+
+
+
+ Stampeding Longhorn
+
+ StampedingLonghorn
+
+
+
+ https://social.linux.pizza/@StampedingLonghorn/105821099684887793
+
+
+
@wouter
The cat pictures are awesome. for jest tests!
+
+
+
+
+
+
+
+ wouter
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/webmention/receive-process.test.js b/test/webmention/receive-process.test.js
index 88028cd..beadbff 100644
--- a/test/webmention/receive-process.test.js
+++ b/test/webmention/receive-process.test.js
@@ -26,6 +26,29 @@ describe("receive webmention process tests happy path", () => {
return `${dumpdir}/` + md5(`source=${body.source},target=${body.target}`)
}
+ test("receive a brid.gy webmention that has a url and photo without value", async () => {
+ const body = {
+ source: "https://brainbaking.com/valid-bridgy-source.html",
+ target: "https://brainbaking.com/valid-indieweb-target.html"
+ }
+ await receive(body)
+
+ const result = await fsp.readFile(`${asFilename(body)}.json`, 'utf-8')
+ const data = JSON.parse(result)
+
+ expect(data).toEqual({
+ author: {
+ name: "Stampeding Longhorn",
+ picture: "https://cdn.social.linux.pizza/v1/AUTH_91eb37814936490c95da7b85993cc2ff/sociallinuxpizza/accounts/avatars/000/185/996/original/9e36da0c093cfc9b.png"
+ },
+ url: "https://social.linux.pizza/@StampedingLonghorn/105821099684887793",
+ content: "@wouter The cat pictures are awesome. for jest tests!",
+ source: body.source,
+ target: body.target,
+ published: "2021-03-02T16:17:18.000Z"
+ })
+ })
+
test("receive saves a JSON file of indieweb-metadata if all is valid", async () => {
const body = {
source: "https://brainbaking.com/valid-indieweb-source.html",
@@ -41,7 +64,8 @@ describe("receive webmention process tests happy path", () => {
name: "Wouter Groeneveld",
picture: "https://brainbaking.com//img/avatar.jpg"
},
- content: "This is cool, I just found out about valid indieweb target - so cool...",
+ url: "https://brainbaking.com/notes/2021/03/06h12m41s48/",
+ content: "This is cool, I just found out about valid indieweb target - so cool",
source: body.source,
target: body.target,
published: "2021-03-06T12:41:00"
@@ -63,6 +87,7 @@ 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/",
content: "This is cool, this is a summary!",
source: body.source,
target: body.target,
@@ -115,5 +140,4 @@ describe("receive webmention process tests happy path", () => {
expect(data.length).toBe(0)
})
-
})