From f1c1cc2f72bc27083d37b466ae1f683361661d21 Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Thu, 6 Jun 2024 21:55:35 -0700 Subject: [PATCH 1/6] add support for opengraph tags --- spec/index.html | 2 ++ src/Spec.ts | 35 +++++++++++++++++++ src/ecmarkup.ts | 1 + .../generated-reference/copyright.html | 2 +- .../proposal-copyright.html | 2 +- .../generated-reference/shortname.html | 2 +- test/baselines/generated-reference/test.html | 4 ++- test/baselines/generated-reference/title.html | 2 +- test/baselines/sources/title.html | 1 + 9 files changed, 46 insertions(+), 5 deletions(-) diff --git a/spec/index.html b/spec/index.html index 9aafb1d5..ded4e569 100644 --- a/spec/index.html +++ b/spec/index.html @@ -3,6 +3,7 @@ Ecmarkup
 repository: https://github.com/tc39/ecmarkup
+desription: An HTML superset/Markdown subset source format for ECMAScript and related specifications
 copyright: false
 markEffects: true
 
@@ -69,6 +70,7 @@

Options

`version`Document version, for example "6<sup>th</sup> Edition" (which renders like "6th Edition") or "Draft 1". `date`Timestamp of document rendering, used for various pieces of boilerplate. Defaults to the value of the `SOURCE_DATE_EPOCH` environment variable (as a number of second since the POSIX epoch) if it exists, otherwise to the current date and time. `shortname`Document shortname, for example "ECMA-262". If present and `status` is "draft", `version` defaults to "Draft shortname". + `description`Brief description to be used for link previews in social media and the like. `location`URL of this document. Used in conjunction with the biblio file to support inbound references from other documents. `copyright`Emit copyright and software license information. Boolean, default true. `contributors`Contributors to this specification, i.e. those who own the copyright. If your proposal includes text from any Ecma specification, this should include "Ecma International". diff --git a/src/Spec.ts b/src/Spec.ts index a3865d07..1dab8640 100644 --- a/src/Spec.ts +++ b/src/Spec.ts @@ -1438,6 +1438,41 @@ ${this.opts.multipage ? `
  • Navigate to/from multipagem this.doc.head.prepend(node) + : (node: HTMLMetaElement) => metas[metas.length - 1].after(node); + if (!metas.some(n => n.getAttribute('property') === 'og:description')) { + let description = + this.opts.description ?? + (this.doc.querySelector('emu-intro') ?? this.doc.querySelector('emu-clause'))?.textContent + ?.slice(0, 300) + .trim(); + if (description) { + let meta = this.doc.createElement('meta'); + meta.setAttribute('property', 'og:description'); + meta.setAttribute('content', description); + insertMetaTag(meta); + } + } + if (!metas.some(n => n.getAttribute('property') === 'og:title')) { + let title = this.opts.title ?? this.doc.querySelector('title')?.textContent; + if (title) { + let meta = this.doc.createElement('meta'); + meta.setAttribute('property', 'og:title'); + meta.setAttribute('content', title); + insertMetaTag(meta); + } + } + if (!metas.some(n => n.getAttribute('property') === 'og:image')) { + let meta = this.doc.createElement('meta'); + meta.setAttribute('property', 'og:image'); + meta.setAttribute('content', 'https://tc39.es/ecmarkup/ecma-header.png'); + insertMetaTag(meta); + } } private buildCopyrightBoilerplate() { diff --git a/src/ecmarkup.ts b/src/ecmarkup.ts index dace1fff..5ee57920 100644 --- a/src/ecmarkup.ts +++ b/src/ecmarkup.ts @@ -27,6 +27,7 @@ export interface Options { version?: string; title?: string; shortname?: string; + description?: string; stage?: string | null; copyright?: boolean; date?: Date; diff --git a/test/baselines/generated-reference/copyright.html b/test/baselines/generated-reference/copyright.html index 01eb7e25..c43ba41a 100644 --- a/test/baselines/generated-reference/copyright.html +++ b/test/baselines/generated-reference/copyright.html @@ -1,5 +1,5 @@ -test title!
    +test title!
    • Toggle shortcuts help?
    • Toggle "can call user code" annotationsu
    • diff --git a/test/baselines/generated-reference/proposal-copyright.html b/test/baselines/generated-reference/proposal-copyright.html index fd61877d..48917049 100644 --- a/test/baselines/generated-reference/proposal-copyright.html +++ b/test/baselines/generated-reference/proposal-copyright.html @@ -1,5 +1,5 @@ -test title!
      +test title!
      • Toggle shortcuts help?
      • Toggle "can call user code" annotationsu
      • diff --git a/test/baselines/generated-reference/shortname.html b/test/baselines/generated-reference/shortname.html index 7191e309..155fb4fd 100644 --- a/test/baselines/generated-reference/shortname.html +++ b/test/baselines/generated-reference/shortname.html @@ -1,5 +1,5 @@ -test title!
        +test title!
        • Toggle shortcuts help?
        • Toggle "can call user code" annotationsu
        • diff --git a/test/baselines/generated-reference/test.html b/test/baselines/generated-reference/test.html index 226d38f8..6b25dade 100644 --- a/test/baselines/generated-reference/test.html +++ b/test/baselines/generated-reference/test.html @@ -1,5 +1,7 @@ - + Ecmarkup Test Document
          diff --git a/test/baselines/generated-reference/title.html b/test/baselines/generated-reference/title.html index 994acf7e..38ad4f4f 100644 --- a/test/baselines/generated-reference/title.html +++ b/test/baselines/generated-reference/title.html @@ -1,5 +1,5 @@ -test title!
          +test title!
          • Toggle shortcuts help?
          • Toggle "can call user code" annotationsu
          • diff --git a/test/baselines/sources/title.html b/test/baselines/sources/title.html index 2ce8aec2..df9ac95e 100644 --- a/test/baselines/sources/title.html +++ b/test/baselines/sources/title.html @@ -1,5 +1,6 @@