Skip to content

Commit

Permalink
feat: ignore mp- prefixed properties when referencing
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Jan 16, 2024
1 parent 48842e9 commit 8893998
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const mf2 = {
published: ["2019-02-12T10:00:00.000+00:00"],
url: ["https://my-website.example/bookmarks/lunch"],
"bookmark-of": ["https://their-website.example/notes/lunch"],
"mp-syndicate-to": "https://example.social/@username",
},
},
],
Expand All @@ -67,6 +68,7 @@ return jf2WithReferences;
// published: '2019-02-12T10:00:00.000+00:00',
// url: 'https://my-website.example/bookmarks/lunch',
// 'bookmark-of': 'https://their-website.example/notes/lunch',
// 'mp-syndicate-to': 'https://example.social/@username',
// references: {
// 'https://their-website.example/notes/lunch': {
// type: 'entry',
Expand All @@ -83,6 +85,9 @@ return jf2WithReferences;
// }
```

> [!NOTE]\
> Values for `url`, and any property prefixed with `mp-`, are excluded from being referenced.
## Testing

`npm test`
Expand Down
7 changes: 6 additions & 1 deletion lib/fetch-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ const referenceableUrls = (jf2) => {
for (const key in jf2) {
if (Object.prototype.hasOwnProperty.call(jf2, key)) {
const value = jf2[key];
const referenceableProperty =
typeof value === "string" &&
URL.canParse(value) &&
key !== "url" &&
!key.startsWith("mp-");

if (typeof value === "string" && URL.canParse(value) && key !== "url") {
if (referenceableProperty) {
urls.push(value);
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/fetch-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ describe("mf2tojf2", () => {
category: ["foo", "bar"],
url: "https://website.example/bookmarks/repo",
"bookmark-of": "https:/getindiekit/mf2tojf2",
"mp-destination": "https://website.example",
"mp-syndicate-to": "https://example.social/@username",
});
assert.deepEqual(
{
Expand All @@ -60,6 +62,8 @@ describe("mf2tojf2", () => {
category: ["foo", "bar"],
url: "https://website.example/bookmarks/repo",
"bookmark-of": "https:/getindiekit/mf2tojf2",
"mp-destination": "https://website.example",
"mp-syndicate-to": "https://example.social/@username",
references: {
"https:/getindiekit/mf2tojf2": {
url: "https:/getindiekit/mf2tojf2",
Expand Down

0 comments on commit 8893998

Please sign in to comment.