Skip to content

Commit

Permalink
feat(core/seo): support adding git revision in meta (#4561)
Browse files Browse the repository at this point in the history
  • Loading branch information
dontcallmedom authored Oct 16, 2023
1 parent bf44a98 commit e141c05
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/core/seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,23 @@
* This Module adds a metatag description to the document, based on the
* first paragraph of the abstract.
*/
import { html } from "../core/import-maps.js";

export const name = "core/seo";

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

const firstParagraph = document.querySelector("#abstract p:first-of-type");
if (!firstParagraph) {
return; // no abstract, so nothing to do
Expand Down
11 changes: 11 additions & 0 deletions tests/spec/core/seo-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
makeBasicConfig,
makeDefaultBody,
makeRSDoc,
makeStandardOps,
} from "../SpecHelper.js";

describe("Core — Seo", () => {
Expand Down Expand Up @@ -35,4 +36,14 @@ describe("Core — Seo", () => {
const meta = doc.head.querySelector("meta[name=description]");
expect(meta.content).toBe("Pass");
});

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();
});
});

0 comments on commit e141c05

Please sign in to comment.