Skip to content

Commit d4f8315

Browse files
aciccarellopaulrobertlloydaimee-gm
committed
feat: add metaformats fallback to fetch-references (#23)
* add metaformats fallback to fetch-references * update microformats-parser --------- Co-authored-by: Paul Robert Lloyd <[email protected]> Co-authored-by: Aimee Gamble-Milner <[email protected]>
1 parent eb1c25e commit d4f8315

File tree

6 files changed

+83
-10
lines changed

6 files changed

+83
-10
lines changed

lib/fetch-mf2.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import parser from "microformats-parser";
1+
import { mf2 } from "microformats-parser";
22
import { fetch } from "./fetch.js";
33

44
/**
@@ -15,9 +15,8 @@ export const fetchMf2 = async (url) => {
1515
throw new Error(response.statusText);
1616
}
1717

18-
const mf2 = parser.mf2(body, {
18+
return mf2(body, {
1919
baseUrl: url,
20+
experimental: { metaformats: true },
2021
});
21-
22-
return mf2;
2322
};

package-lock.json

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"prepare": "husky install"
3333
},
3434
"dependencies": {
35-
"microformats-parser": "^1.4.0",
35+
"microformats-parser": "^2.0.0",
3636
"undici": "^5.9.0"
3737
},
3838
"devDependencies": {

tests/fetch-references.test.js

+39
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,42 @@ test("Fetches JF2 properties for each referenced URL", async () => {
4141
expected,
4242
);
4343
});
44+
45+
test("Uses metaformats fallback for each referenced URL", async () => {
46+
const expected = await fetchReferences({
47+
type: "entry",
48+
name: "A cool git repo",
49+
published: "2019-02-12T10:00:00.000+00:00",
50+
category: ["foo", "bar"],
51+
url: "https://website.example/bookmarks/repo",
52+
"bookmark-of": "https://github.com/getindiekit/mf2tojf2",
53+
});
54+
console.log(expected);
55+
assert.deepEqual(
56+
{
57+
type: "entry",
58+
name: "A cool git repo",
59+
published: "2019-02-12T10:00:00.000+00:00",
60+
category: ["foo", "bar"],
61+
url: "https://website.example/bookmarks/repo",
62+
"bookmark-of": "https://github.com/getindiekit/mf2tojf2",
63+
references: {
64+
"https://github.com/getindiekit/mf2tojf2": {
65+
url: "https://github.com/getindiekit/mf2tojf2",
66+
type: "entry",
67+
name: "getindiekit/mf2tojf2: Convert MF2 to JF2.",
68+
summary:
69+
"Convert MF2 to JF2. Contribute to getindiekit/mf2tojf2 development by creating an account on GitHub.",
70+
featured: [
71+
{
72+
alt: "Card identifying indieweb/mf2tojf2 repo. Notes 2 contributors, 6 stars, and 2 forks.",
73+
url: "https://opengraph.githubassets.com/6d3c627723ff987446e2917808142dfb0e2ccdd9d94db970f9a5aacbb1eb4825/getindiekit/mf2tojf2",
74+
},
75+
],
76+
publication: "GitHub",
77+
},
78+
},
79+
},
80+
expected,
81+
);
82+
});

tests/fixtures/repo.html

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>getindiekit/mf2tojf2: Convert MF2 to JF2.</title>
6+
<meta name="description" content="Convert MF2 to JF2. Contribute to getindiekit/mf2tojf2 development by creating an account on GitHub.">
7+
<meta name="twitter:image:src" content="https://opengraph.githubassets.com/6d3c627723ff987446e2917808142dfb0e2ccdd9d94db970f9a5aacbb1eb4825/getindiekit/mf2tojf2"/>
8+
<meta name="twitter:site" content="@github"/>
9+
<meta name="twitter:card" content="summary_large_image"/>
10+
<meta name="twitter:title" content="getindiekit/mf2tojf2: Convert MF2 to JF2."/>
11+
<meta name="twitter:description" content="Convert MF2 to JF2. Contribute to getindiekit/mf2tojf2 development by creating an account on GitHub."/>
12+
<meta property="og:image" content="https://opengraph.githubassets.com/6d3c627723ff987446e2917808142dfb0e2ccdd9d94db970f9a5aacbb1eb4825/getindiekit/mf2tojf2"/>
13+
<meta property="og:image:alt" content="Card identifying indieweb/mf2tojf2 repo. Notes 2 contributors, 6 stars, and 2 forks."/>
14+
<meta property="og:image:width" content="1200"/>
15+
<meta property="og:image:height" content="600"/>
16+
<meta property="og:site_name" content="GitHub"/>
17+
<meta property="og:type" content="object"/>
18+
<meta property="og:title" content="getindiekit/mf2tojf2: Convert MF2 to JF2."/>
19+
<meta property="og:url" content="https://github.com/getindiekit/mf2tojf2"/>
20+
<meta property="og:description" content="Convert MF2 to JF2. Contribute to getindiekit/mf2tojf2 development by creating an account on GitHub."/>
21+
<link rel="canonical" href="https://github.com/getindiekit/mf2tojf2">
22+
</head>
23+
<body>
24+
<article>
25+
<h1>MF2 to JF2</h1>
26+
<p>JF2 is a simpler JSON serialization of microformats2 intended to be easier to consume than the standard <a href="https://microformats.org/wiki/microformats2" rel="nofollow">microformats JSON representation</a>.</p>
27+
</article>
28+
</body>
29+
</html>

tests/helpers/mock-agent.js

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ export const mockAgent = () => {
1111
.intercept({ path: "/notes/lunch" })
1212
.reply(200, getFixture("bookmark.html"));
1313

14+
// Get page without mf2
15+
agent
16+
.get("https://github.com")
17+
.intercept({ path: "/getindiekit/mf2tojf2" })
18+
.reply(200, getFixture("repo.html"));
19+
1420
// Get bookmark (Not Found)
1521
agent
1622
.get("https://website.example")

0 commit comments

Comments
 (0)