From 1ce36dd88b33fb54a436d21cb06d880a09cba37b Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Wed, 26 Jun 2024 17:09:34 -0700 Subject: [PATCH] add support for opengraph tags (#598) --- ecma-logo.png | Bin 0 -> 5984 bytes package.json | 2 +- spec/index.html | 2 + src/Spec.ts | 36 ++++++++++++++++++ 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 + 11 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 ecma-logo.png diff --git a/ecma-logo.png b/ecma-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..b65fb8738a2e753e432f7dac1b45f090b1a9611d GIT binary patch literal 5984 zcmZ`-1z40_(_TtILPA17SXy#vVQF^h4v~=Vt|gXkL_$hpK`8<025FI$M!Ka#X_glL z_5Hs8{od=3b6xYCc_!{TGv~>P)=-ltcu4gS000muDnPYR^E`@_a2}wJOMXh}005f4 z9R#AG2!Q}K++D2g9IXI=XNgV;ZOUC5k9*Vws5Fl;-U!3`%{7a)>}B0bpT5yxntVfN zh-fID?Ug6#ARk|vn^TmR?yg|K3AK>!>5zIAfo~suA!u)a?A*LvUUhAv$&uB0!VwJ^ zh;%AUu01&!DB%>(fBHLtNKS8xll*1MW7(tf;nAk3FZJMFZ>w3~BWKqiXPjR)e#htT zt@uy;9NOfHI}5Ycu_z?K>FOS67#2Px!d3ylxlE`%IOg3h>!U!bu)GJhGapR6v5&t@ z6wY!wLO$S56RNMIzCMd5zIG3|EZ(Uzmx>}Y-OUEVtb+vp;?yA^!)_!Tc6L+`$1xcW-iY(IX zBrg97om{VYIOes{T&Wx^fIdn4>Y{C}xt=r!iTl}I0xfXPG=IuR-yKzJT`N6BYgJVM zJBr5vphejMFi{*Dil|To0AM6V0FooIU=X7Air|9}S3?n+NnaHp*4(j})w7=VRrl z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c8)M zXvE~BMjKoQhp=U-`bFb%D2XZuQ(rX=KJ)t#>BcLas^O+D^9OB=*xe@Z9vkO5(OJdO z47}}~v0{tIeQKJAdUZoww31s}6c5WIMKTel{d1H4VSE$(-D85{f^i5#!|q!(uC_{^ z2&f`^pLY^z)QFh5#3nmBBMaqLnLRoeZe03Mmkz#ck&Rk`GmF4hvcYSnf907@XZBiq zxJ$n8%j~j0#&B>h>m5%DHP_DTXVj-f(Aw=Q0hk)TILEAQ$W;aJS)c6{8S<3mpTGA zitvofxK+z4^q&lvkpA)SbNnAeNajdH4IX~}O(Yom_$wq6Qk%^o0{T9^@&g-lGz3Bh z`GnPfONxOeR_$>W9S48y#W$3*`p8xlrj>rcOQ!|Z-1-{>EhSFT#7Xv);7!Kcyb{$S{i()Vi)`cG!e!KYPnGKRe+pD{7zu4>&QuqNs& z+V3RHh9g+|x}b>dqXcX7t5`Qy*`cSjR=l7Yi032tW!;AQBFxxBrbh%9*caHZ@JC3`Jg@SlJPko<| zmlinI4uOg}$ z6+#b;qYqhS(pJQjkwLYbm@X}?qoqty{UWT$WEEy&99%TTx`ZFe8O(o7qsb}N_})Q* zOsF1|OsKkbDh_5Os(EB8{7r`>B!MUaiiazaq0c}>iF!%>AE39AlT+KIT@}Hq0Mt;F LRfAT@n1=orvRfZ~ literal 0 HcmV?d00001 diff --git a/package.json b/package.json index 799f30ef..9b5d1cee 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "build": "tsc -sourceMap -declarationMap", "build-release": "tsc", - "build-spec": "mkdir -p docs && node bin/ecmarkup.js spec/index.html docs/index.html --assets-dir=docs", + "build-spec": "mkdir -p docs && node bin/ecmarkup.js spec/index.html docs/index.html --assets-dir=docs && cp ecma-logo.png docs/", "prepack": "safe-publish-latest && npm run build-release", "format-spec": "node bin/emu-format.js --write spec/index.html", "test": "mocha", 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

@@ -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..ea2c8c5f 100644 --- a/src/Spec.ts +++ b/src/Spec.ts @@ -1438,6 +1438,42 @@ ${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')) { + const description = ( + this.opts.description ?? + (this.doc.querySelector('emu-intro') ?? this.doc.querySelector('emu-clause'))?.textContent + ) + ?.slice(0, 300) + .trim(); + if (description) { + const 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')) { + const title = this.opts.title ?? this.doc.querySelector('title')?.textContent; + if (title) { + const 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')) { + const meta = this.doc.createElement('meta'); + meta.setAttribute('property', 'og:image'); + meta.setAttribute('content', 'https://tc39.es/ecmarkup/ecma-logo.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..934ecd7e 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..19a5d0c4 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..7e842d50 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..73d682e7 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..47262a40 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 @@