Skip to content

feat: make json-ld metadata more robust #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -193,7 +193,7 @@
}
const response = await render(url, '', expStatus);
const actHtml = response.body;
console.log(actHtml);

Check warning on line 196 in test/rendering.test.js

View workflow job for this annotation

GitHub Actions / Test

Unexpected console statement
if (expStatus === 200) {
const $actMain = new JSDOM(actHtml).window.document.querySelector(domSelector);
const $expMain = new JSDOM(expHtml).window.document.querySelector(domSelector);
Expand Down Expand Up @@ -414,6 +414,11 @@
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