Skip to content

Commit

Permalink
Add support for configuration key to document git revision in meta
Browse files Browse the repository at this point in the history
This allows to set a git revision of the source used to the generated content. Bikeshed does this, but with 'document-revision' as a meta name - that said, 'revision' is the name recommended in https://wiki.whatwg.org/wiki/MetaExtensions

Typically, this would be set when generating the static HTML (a possible separate improvement to spec-prod)
  • Loading branch information
dontcallmedom committed Oct 13, 2023
1 parent cf7572a commit 839f104
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/w3c/seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ export const requiresCanonicalLink = new Set([
]);

export async function run(conf) {
if (conf.gitRevision) {
// This allows to set a git revision of the source used to produce
// the generated content
// 'revision' is the name recommended in https://wiki.whatwg.org/wiki/MetaExtensions
// typically, this would be set when generating the static HTML
const metaElem = html`<meta name='revision' content="${conf.gitRevision}">`;
document.head.appendChild(metaElem);
}


// Don't include a canonical URL for documents that haven't been published.
if (
(!conf.canonicalURI && !requiresCanonicalLink.has(conf.specStatus)) ||
Expand Down Expand Up @@ -71,7 +81,7 @@ export async function run(conf) {
const linkElem = html`<link rel="canonical" href="${conf.canonicalURI}" />`;
document.head.appendChild(linkElem);
}

if (conf.doJsonLd) {
await addJSONLDInfo(conf, document);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/spec/w3c/seo-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ describe("W3C - SEO", () => {
});
}

it("documents a revision in a meta element when set", async () => {
const gitRevision = "11223344556677889900aabbccddeeffaabbccddeeff";
const doc = await makeRSDoc(
makeStandardOps({ specStatus: "ED", group: "webapps", gitRevision })
);
expect(
doc.querySelector(`meta[name='revision'][content='${gitRevision}']`)
).toBeTruthy();
});


const body = `
<html>
<title>Basic Title</title>
Expand Down

0 comments on commit 839f104

Please sign in to comment.