Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add metaformats fallback to fetch-references #23

Merged
merged 3 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/fetch-mf2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import parser from "microformats-parser";
import { mf2 } from "microformats-parser";
import { fetch } from "./fetch.js";

/**
Expand All @@ -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;
};
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"prepare": "husky install"
},
"dependencies": {
"microformats-parser": "^1.4.0",
"microformats-parser": "^2.0.0",
"undici": "^5.9.0"
},
"devDependencies": {
Expand Down
39 changes: 39 additions & 0 deletions tests/fetch-references.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
});
29 changes: 29 additions & 0 deletions tests/fixtures/repo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>getindiekit/mf2tojf2: Convert MF2 to JF2.</title>
<meta name="description" content="Convert MF2 to JF2. Contribute to getindiekit/mf2tojf2 development by creating an account on GitHub.">
<meta name="twitter:image:src" content="https://opengraph.githubassets.com/6d3c627723ff987446e2917808142dfb0e2ccdd9d94db970f9a5aacbb1eb4825/getindiekit/mf2tojf2"/>
<meta name="twitter:site" content="@github"/>
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:title" content="getindiekit/mf2tojf2: Convert MF2 to JF2."/>
<meta name="twitter:description" content="Convert MF2 to JF2. Contribute to getindiekit/mf2tojf2 development by creating an account on GitHub."/>
<meta property="og:image" content="https://opengraph.githubassets.com/6d3c627723ff987446e2917808142dfb0e2ccdd9d94db970f9a5aacbb1eb4825/getindiekit/mf2tojf2"/>
<meta property="og:image:alt" content="Card identifying indieweb/mf2tojf2 repo. Notes 2 contributors, 6 stars, and 2 forks."/>
<meta property="og:image:width" content="1200"/>
<meta property="og:image:height" content="600"/>
<meta property="og:site_name" content="GitHub"/>
<meta property="og:type" content="object"/>
<meta property="og:title" content="getindiekit/mf2tojf2: Convert MF2 to JF2."/>
<meta property="og:url" content="https://github.com/getindiekit/mf2tojf2"/>
<meta property="og:description" content="Convert MF2 to JF2. Contribute to getindiekit/mf2tojf2 development by creating an account on GitHub."/>
<link rel="canonical" href="https://github.com/getindiekit/mf2tojf2">
</head>
<body>
<article>
<h1>MF2 to JF2</h1>
<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>
</article>
</body>
</html>
6 changes: 6 additions & 0 deletions tests/helpers/mock-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down