Skip to content

Commit a28c408

Browse files
feat: ignore mp- prefixed properties when referencing
1 parent 48842e9 commit a28c408

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const mf2 = {
5454
published: ["2019-02-12T10:00:00.000+00:00"],
5555
url: ["https://my-website.example/bookmarks/lunch"],
5656
"bookmark-of": ["https://their-website.example/notes/lunch"],
57+
"mp-syndicate-to": "https://example.social/@username",
5758
},
5859
},
5960
],
@@ -67,6 +68,7 @@ return jf2WithReferences;
6768
// published: '2019-02-12T10:00:00.000+00:00',
6869
// url: 'https://my-website.example/bookmarks/lunch',
6970
// 'bookmark-of': 'https://their-website.example/notes/lunch',
71+
// 'mp-syndicate-to': 'https://example.social/@username',
7072
// references: {
7173
// 'https://their-website.example/notes/lunch': {
7274
// type: 'entry',
@@ -83,6 +85,9 @@ return jf2WithReferences;
8385
// }
8486
```
8587

88+
> [!NOTE]\
89+
> Values for `url`, and any property prefixed with `mp-`, are excluded from referencing.
90+
8691
## Testing
8792

8893
`npm test`

lib/fetch-references.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ const referenceableUrls = (jf2) => {
1313
for (const key in jf2) {
1414
if (Object.prototype.hasOwnProperty.call(jf2, key)) {
1515
const value = jf2[key];
16+
const referenceableProperty =
17+
typeof value === "string" &&
18+
URL.canParse(value) &&
19+
key !== "url" &&
20+
!key.startsWith("mp-");
1621

17-
if (typeof value === "string" && URL.canParse(value) && key !== "url") {
22+
if (referenceableProperty) {
1823
urls.push(value);
1924
}
2025
}

test/fetch-references.js

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ describe("mf2tojf2", () => {
5151
category: ["foo", "bar"],
5252
url: "https://website.example/bookmarks/repo",
5353
"bookmark-of": "https://github.com/getindiekit/mf2tojf2",
54+
"mp-destination": "https://website.example",
55+
"mp-syndicate-to": "https://example.social/@username",
5456
});
5557
assert.deepEqual(
5658
{
@@ -60,6 +62,8 @@ describe("mf2tojf2", () => {
6062
category: ["foo", "bar"],
6163
url: "https://website.example/bookmarks/repo",
6264
"bookmark-of": "https://github.com/getindiekit/mf2tojf2",
65+
"mp-destination": "https://website.example",
66+
"mp-syndicate-to": "https://example.social/@username",
6367
references: {
6468
"https://github.com/getindiekit/mf2tojf2": {
6569
url: "https://github.com/getindiekit/mf2tojf2",

0 commit comments

Comments
 (0)