`;
test("an article: its main content block by block, the furniture gone, facts from the meta", () => {
const d = extractGeneric({ html: ARTICLE, capture: cap("https://blog.example/2014/03/a-post.html", "20140305120000") });
assert.equal(d.kind, "generic");
assert.equal(d.title, "A Post About Bread");
assert.equal(d.author, "Pat Example");
assert.equal(d.publishedAt, "2014-03-04T18:30:00.000Z");
assert.equal(
d.text,
[
"A Post About Bread",
"The first loaf came out flat, and the second, and the third.",
"See the starter post and about.",
"> Bake it until it sounds hollow.",
"- Flour, 500 g",
"- Water, 350 g",
"[Image: A flat loaf]",
" day 1: feed\n day 2: feed",
].join("\n\n"),
);
for (const gone of ["Home", "Blogroll", "Copyright", "script text", "Example Blog"]) {
assert.ok(!d.text.includes(gone), `${gone} is furniture`);
}
assert.deepEqual(d.links, ["https://blog.example/2014/02/starter.html", "https://blog.example/2014/about"]);
assert.deepEqual(d.media, [
{ kind: "image", url: "https://web.archive.org/web/20140305120000im_/https://blog.example/images/loaf.jpg", name: "A flat loaf" },
]);
assert.equal(d.noContent, undefined);
});
test("a body that still carries the Wayback toolbar: the insert, its scripts and rewritten links undone", () => {
const html = `
About Us
The Wayback Machine toolbar text
About us
We are a small group that makes zines about our town, and have since 2009.
`;
assert.ok(!stripWaybackChrome(html).includes("wombat"));
const d = extractGeneric({ html, capture: cap("https://home.example/about", "20150101000000") });
assert.equal(d.title, "About Us");
assert.ok(!d.text.includes("toolbar"), d.text);
assert.ok(d.text.includes("We are a small group that makes zines"));
assert.deepEqual(d.links, ["https://home.example/contact", "https://home.example/links"]);
// A toolbar insert cut short (no END marker) still goes, by its element.
const cut = extractGeneric({
html: `
toolbar
Real words of the page, long enough to count as a paragraph.
`,
capture: cap("https://home.example/", "2015"),
});
assert.ok(!cut.text.includes("toolbar"));
});
test("no or : the densest block wins over the link lists", () => {
const html = `
This is the first paragraph of the real writing, with commas, clauses, and words.
And a second paragraph, which also carries some weight, so the block wins.
Short.
`;
const d = extractGeneric({ html, capture: cap("https://site.example/page", "20100101000000") });
assert.ok(d.text.startsWith("This is the first paragraph"), d.text);
assert.ok(!d.text.includes("A link"));
assert.ok(!d.text.includes("Short."));
// No title anywhere → none.
assert.equal(d.title, undefined);
});
test("dates: JSON-LD,