diff --git a/lib/fetch-mf2.js b/lib/fetch-mf2.js index f5bb480..95b2e08 100644 --- a/lib/fetch-mf2.js +++ b/lib/fetch-mf2.js @@ -1,4 +1,4 @@ -import parser from "microformats-parser"; +import { mf2 } from "microformats-parser"; import { fetch } from "./fetch.js"; /** @@ -15,9 +15,8 @@ export const fetchMf2 = async (url) => { throw new Error(response.statusText); } - const mf2 = parser.mf2(body, { + return mf2(body, { baseUrl: url, + experimental: { metaformats: true }, }); - - return mf2; }; diff --git a/package-lock.json b/package-lock.json index 2953db4..24ad098 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.3", "license": "MIT", "dependencies": { - "microformats-parser": "^1.4.0", + "microformats-parser": "^1.5.1", "undici": "^5.9.0" }, "devDependencies": { @@ -5046,14 +5046,14 @@ } }, "node_modules/microformats-parser": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/microformats-parser/-/microformats-parser-1.4.1.tgz", - "integrity": "sha512-BSg9Y/Aik8hvvme/fkxnXMRvTKuVwOeTapeZdaPQ+92DEubyM31iMtwbgFZ1383om643UvfYY5G23E9s1FY2KQ==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/microformats-parser/-/microformats-parser-1.5.1.tgz", + "integrity": "sha512-Bn4jlYuIIN5NK/5eAJLk7rRYjjbeF29bLpXjQLHl4mmrMs3bynZ683hNC4o/YAbKg8kekrv0973GmCYD2fcb6w==", "dependencies": { "parse5": "^6.0.0" }, "engines": { - "node": ">=10" + "node": ">=14" } }, "node_modules/micromatch": { diff --git a/package.json b/package.json index 274423a..490f1e2 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "prepare": "husky install" }, "dependencies": { - "microformats-parser": "^1.4.0", + "microformats-parser": "^2.0.0", "undici": "^5.9.0" }, "devDependencies": { diff --git a/tests/fetch-references.test.js b/tests/fetch-references.test.js index d36e021..a410fa5 100644 --- a/tests/fetch-references.test.js +++ b/tests/fetch-references.test.js @@ -41,3 +41,42 @@ test("Fetches JF2 properties for each referenced URL", async () => { expected, ); }); + +test("Uses metaformats fallback for each referenced URL", async () => { + const expected = await fetchReferences({ + type: "entry", + name: "A cool git repo", + published: "2019-02-12T10:00:00.000+00:00", + category: ["foo", "bar"], + url: "https://website.example/bookmarks/repo", + "bookmark-of": "https://github.com/getindiekit/mf2tojf2", + }); + console.log(expected); + assert.deepEqual( + { + type: "entry", + name: "A cool git repo", + published: "2019-02-12T10:00:00.000+00:00", + category: ["foo", "bar"], + url: "https://website.example/bookmarks/repo", + "bookmark-of": "https://github.com/getindiekit/mf2tojf2", + references: { + "https://github.com/getindiekit/mf2tojf2": { + url: "https://github.com/getindiekit/mf2tojf2", + type: "entry", + name: "getindiekit/mf2tojf2: Convert MF2 to JF2.", + summary: + "Convert MF2 to JF2. Contribute to getindiekit/mf2tojf2 development by creating an account on GitHub.", + featured: [ + { + alt: "Card identifying indieweb/mf2tojf2 repo. Notes 2 contributors, 6 stars, and 2 forks.", + url: "https://opengraph.githubassets.com/6d3c627723ff987446e2917808142dfb0e2ccdd9d94db970f9a5aacbb1eb4825/getindiekit/mf2tojf2", + }, + ], + publication: "GitHub", + }, + }, + }, + expected, + ); +}); diff --git a/tests/fixtures/repo.html b/tests/fixtures/repo.html new file mode 100644 index 0000000..13667c4 --- /dev/null +++ b/tests/fixtures/repo.html @@ -0,0 +1,29 @@ + + + + + getindiekit/mf2tojf2: Convert MF2 to JF2. + + + + + + + + + + + + + + + + + + +
+

MF2 to JF2

+

JF2 is a simpler JSON serialization of microformats2 intended to be easier to consume than the standard microformats JSON representation.

+
+ + diff --git a/tests/helpers/mock-agent.js b/tests/helpers/mock-agent.js index 474f553..9dc5abf 100644 --- a/tests/helpers/mock-agent.js +++ b/tests/helpers/mock-agent.js @@ -11,6 +11,12 @@ export const mockAgent = () => { .intercept({ path: "/notes/lunch" }) .reply(200, getFixture("bookmark.html")); + // Get page without mf2 + agent + .get("https://github.com") + .intercept({ path: "/getindiekit/mf2tojf2" }) + .reply(200, getFixture("repo.html")); + // Get bookmark (Not Found) agent .get("https://website.example")