Skip to content

Commit

Permalink
feat: make json-ld metadata more robust (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
tripodsan authored Aug 1, 2024
1 parent 1dd871a commit 3d3e5dc
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/steps/extract-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions test/fixtures/content/page-metadata-jsonld-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<head>
<title>Home | Helix Project Boilerplate</title>
<link rel="canonical" href="https://helix-pages.com/page-metadata-jsonld-list">
<meta property="og:title" content="Home | Helix Project Boilerplate">
<meta property="og:url" content="https://helix-pages.com/page-metadata-jsonld-list">
<meta property="og:image" content="https://helix-pages.com/default-meta-image.png?width=1200&#x26;format=pjpg&#x26;optimize=medium">
<meta property="og:image:secure_url" content="https://helix-pages.com/default-meta-image.png?width=1200&#x26;format=pjpg&#x26;optimize=medium">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Home | Helix Project Boilerplate">
<meta name="twitter:image" content="https://helix-pages.com/default-meta-image.png?width=1200&#x26;format=pjpg&#x26;optimize=medium">
<script type="application/ld+json">{"@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"}}</script>
<link id="favicon" rel="icon" type="image/svg+xml" href="/icons/spark.svg">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/scripts.js" type="module"></script>
<link rel="stylesheet" href="/styles.css">
</head>
29 changes: 29 additions & 0 deletions test/fixtures/content/page-metadata-jsonld-list.md
Original file line number Diff line number Diff line change
@@ -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" |
| | |
| | } |
| | |
| | } |
+----------------+--------------------------------------------------------------------------+
5 changes: 5 additions & 0 deletions test/rendering.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3d3e5dc

Please sign in to comment.