diff --git a/index.js b/index.js index f909106..071264d 100644 --- a/index.js +++ b/index.js @@ -16,9 +16,17 @@ function getDependencyVersion(dependencyName) { } const mf2version = getDependencyVersion("microformats-parser"); -function htmlToMf2(url, html, res) { +function readExperimental(params) { + const experimental = {}; + for (const flag of ["lang", "textContent", "metaformats"]) { + if (params[flag] === "true") experimental[flag] = true; + } + return Object.keys(experimental).length > 0 ? { experimental } : {}; +} + +function htmlToMf2(url, html, experimental, res) { try { - const body = mf2(html, { baseUrl: url }); + const body = mf2(html, { baseUrl: url, ...experimental }); res .header("content-type", "application/json; charset=UTF-8") .send(JSON.stringify(body, null, 2)); @@ -35,6 +43,7 @@ app.use(express.static("public")); app.get("/", async (req, res) => { if (req.query.url) { const url = req.query.url; + const experimental = readExperimental(req.query); await fetch(url, { headers: { accept: "text/html, text/mf2+html", @@ -42,16 +51,17 @@ app.get("/", async (req, res) => { method: "GET", }).then(async (response) => { const html = await response.text(); - htmlToMf2(url, html, res); + htmlToMf2(url, html, experimental, res); }); } else { res.render("index.html.ejs", { - version: `${pkg.version} (lib: ${mf2version})`, + site_version: pkg.version, + mf2_version: mf2version, }); } }); app.post("/", express.urlencoded({ extended: false }), (req, res) => { - htmlToMf2(req.body.url, req.body.html, res); + htmlToMf2(req.body.url, req.body.html, {}, res); }); app.listen(port, () => { diff --git a/package.json b/package.json index bee8087..a6dbdc7 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,6 @@ "microformats-parser": "^2.0.6" }, "devDependencies": { - "prettier": "^3.9.5" + "prettier": "^3.9.6" } } diff --git a/views/index.html.ejs b/views/index.html.ejs index 511a013..59e468b 100644 --- a/views/index.html.ejs +++ b/views/index.html.ejs @@ -1,5 +1,5 @@ - - + + Node Microformats Parser - - + -
-

Microformats Parser (Node) <%- version -%>

- -
-
- - -
- - -
- -

OR parse just a snippet of HTML

- -
-
- - -
- -
- - -
- - -
- -
- -

- Drag this link to your bookmarks toolbar to parse a page with one - click!
-

- mf2 parser - -
+
+

Microformats Parser (Node)

+ +
+
+

Parse a URL

+ +
+
+ + +
+ +
+ + Experimental options + +
+ + +
+ Include the lang attribute on microformats and + e-* properties. +
+
+
+ + +
+ Collapse consecutive whitespace and treat + <br>/<p> as line breaks. +
+
+
+ + +
+ Fall back to <meta> tags to infer content, + following the separate + metaformats + spec. +
+
+
+ + +
+
+ +
+

OR parse just a snippet of HTML

+ +
+
+ + +
+ +
+ + +
+ + +
+
+ +
+
+

Bookmarklet

+

+ Drag this link to your bookmarks toolbar to parse a page with one + click! +

+ mf2 parser +
+
+
-
+ + + diff --git a/yarn.lock b/yarn.lock index a0a98d6..f5bd096 100644 --- a/yarn.lock +++ b/yarn.lock @@ -359,10 +359,10 @@ path-to-regexp@^8.0.0: resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-8.4.2.tgz#795c420c4f7ca45c5b887366f622ee0c9852cccd" integrity sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA== -prettier@^3.9.5: - version "3.9.5" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.9.5.tgz#4fec97736e33b9d0b620b48914fe93b530e835ad" - integrity sha512-/FVl766LpUfB5vXgCYOYa0MeV/441Ia99AeICQIQFTY/Nw0roZwULcXpku5i1/m5kt/baz+s4Zogspd839HSMg== +prettier@^3.9.6: + version "3.9.6" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.9.6.tgz#b3ea5146515d40fc53f18aa63f74dfab1e10dbf6" + integrity sha512-OpN0zzVdiaiAhxpuuj5efpIS4sY9j7bY6uR5mnj5yPzGkdkjNKSJeUThPb60Jw29QuAZgA4o+/iB49kFiaBX6g== proxy-addr@^2.0.7: version "2.0.7"