From 3d3e5dc5e39a601a5f9b225d6409f2cfbdefc138 Mon Sep 17 00:00:00 2001 From: Tobias Bocanegra Date: Thu, 1 Aug 2024 10:53:01 +0200 Subject: [PATCH] feat: make json-ld metadata more robust (#658) --- src/steps/extract-metadata.js | 6 ++++ .../content/page-metadata-jsonld-list.html | 16 ++++++++++ .../content/page-metadata-jsonld-list.md | 29 +++++++++++++++++++ test/rendering.test.js | 5 ++++ 4 files changed, 56 insertions(+) create mode 100644 test/fixtures/content/page-metadata-jsonld-list.html create mode 100644 test/fixtures/content/page-metadata-jsonld-list.md diff --git a/src/steps/extract-metadata.js b/src/steps/extract-metadata.js index e1495e87..5be526d7 100644 --- a/src/steps/extract-metadata.js +++ b/src/steps/extract-metadata.js @@ -43,6 +43,12 @@ function readBlockConfig($block) { const [$name, $value] = $row.children; const name = toMetaName(toString($name)); if (name) { + // special case for json-ld. don't apply any special formatting + if (name.toLowerCase() === 'json-ld') { + config[name] = toString($value).trim(); + return; + } + let value; const $firstChild = childNodes($value)[0]; if ($firstChild) { diff --git a/test/fixtures/content/page-metadata-jsonld-list.html b/test/fixtures/content/page-metadata-jsonld-list.html new file mode 100644 index 00000000..e3e0c285 --- /dev/null +++ b/test/fixtures/content/page-metadata-jsonld-list.html @@ -0,0 +1,16 @@ + + Home | Helix Project Boilerplate + + + + + + + + + + + + + + diff --git a/test/fixtures/content/page-metadata-jsonld-list.md b/test/fixtures/content/page-metadata-jsonld-list.md new file mode 100644 index 00000000..94a7b94a --- /dev/null +++ b/test/fixtures/content/page-metadata-jsonld-list.md @@ -0,0 +1,29 @@ +# JSON LD Test + +This is great. + ++-------------------------------------------------------------------------------------------+ +| Metadata | ++================+==========================================================================+ +| title | Home \| Helix Project Boilerplate | ++----------------+--------------------------------------------------------------------------| +| json-ld | {"@context": "https\://schema.org", | +| | | +| | "@type": "Course", | +| | | +| | "name": "Getting Started with AEM", | +| | | +| | "description": "Setup your first project with AEM for Developers.", | +| | | +| | "provider": { | +| | | +| | "@type": "Organization", | +| | | +| | "name": "Adobe", | +| | | +| | "sameAs": "http\://www\.adobe.com" | +| | | +| | } | +| | | +| | } | ++----------------+--------------------------------------------------------------------------+ diff --git a/test/rendering.test.js b/test/rendering.test.js index ba13690d..9c5b5141 100644 --- a/test/rendering.test.js +++ b/test/rendering.test.js @@ -414,6 +414,11 @@ describe('Rendering', () => { await testRender('page-metadata-jsonld', 'head'); }); + it('injects json ld even for multi-list cells', async () => { + config = DEFAULT_CONFIG_EMPTY; + await testRender('page-metadata-jsonld-list', 'head'); + }); + it('chooses last json-ld if multiple', async () => { config = { ...DEFAULT_CONFIG_EMPTY,