Skip to content

Commit

Permalink
Merge pull request #525 from hlxsites/feat-517-schema
Browse files Browse the repository at this point in the history
feat: implement schema for library, info & topic pages
  • Loading branch information
mhaack authored Nov 30, 2023
2 parents d1624cb + 5080097 commit ee556c2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 42 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions scripts/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { getMetadata } from './lib-franklin.js';
import { makePublicUrl, setJsonLd } from './scripts.js';

// eslint-disable-next-line import/prefer-default-export
export function buildArticleSchema() {
const data = {
'@context': 'http://schema.org',
'@type': 'Article',
'@id': `https://lifesciences.danaher.com${makePublicUrl(window.location.pathname)}`,
headline: getMetadata('og:title'),
image: getMetadata('og:image'),
datePublished: getMetadata('publishdate'),
publisher: {
'@type': 'Organization',
name: 'Danaher Life Sciences',
logo: {
'@type': 'ImageObject',
url: 'https://lifesciences.danaher.com/content/dam/danaher/brand-logos/danaher/Logo.svg',
},
},
description: getMetadata('description'),
mainEntityOfPage: {
'@type': 'WebPage',
'@id': `https://lifesciences.danaher.com${makePublicUrl(window.location.pathname)}`,
},
};

if (getMetadata('creationdate')) data.datePublished = getMetadata('creationdate');
if (getMetadata('updatedate')) data.dateModified = getMetadata('updatedate');
if (getMetadata('authorname')) {
data.author = {
'@type': 'Person',
name: getMetadata('authorname'),
};
}

setJsonLd(data, 'article');
}
44 changes: 3 additions & 41 deletions templates/blog/blog.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,5 @@
import { buildBlock, getMetadata } from '../../scripts/lib-franklin.js';
import { makePublicUrl, setJsonLd } from '../../scripts/scripts.js';

function buildJsonLd() {
const data = {
'@context': 'http://schema.org',
'@type': 'Article',
'@id': `https://lifesciences.danaher.com${makePublicUrl(window.location.pathname)}`,
headline: getMetadata('og:title'),
image: getMetadata('og:image'),
datePublished: getMetadata('publishdate'),
publisher: {
'@type': 'Organization',
name: 'Danaher Life Sciences',
logo: {
'@type': 'ImageObject',
url: 'https://lifesciences.danaher.com/content/dam/danaher/brand-logos/danaher/Logo.svg',
},
},
description: getMetadata('description'),
mainEntityOfPage: {
'@type': 'WebPage',
'@id': `https://lifesciences.danaher.com${makePublicUrl(window.location.pathname)}`,
},
};

if (getMetadata('creationdate')) data.datePublished = getMetadata('creationdate');
if (getMetadata('updatedate')) data.dateModified = getMetadata('updatedate');
if (getMetadata('authorname')) {
data.author = {
'@type': 'Person',
name: getMetadata('authorname'),
};
}

setJsonLd(
data,
'article',
);
}
import { buildBlock } from '../../scripts/lib-franklin.js';
import { buildArticleSchema } from '../../scripts/schema.js';

export default async function buildAutoBlocks() {
const main = document.querySelector('main');
Expand Down Expand Up @@ -88,5 +50,5 @@ export default async function buildAutoBlocks() {
buildBlock('related-articles', { elems: [] }),
);

buildJsonLd();
buildArticleSchema();
}
5 changes: 5 additions & 0 deletions templates/library/library.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { buildArticleSchema } from '../../scripts/schema.js';

export default async function buildAutoBlocks() {
buildArticleSchema();
}
3 changes: 3 additions & 0 deletions templates/topic/topic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { div } from '../../scripts/dom-builder.js';
import { buildBlock } from '../../scripts/lib-franklin.js';
import { buildArticleSchema } from '../../scripts/schema.js';

export default async function buildAutoBlocks() {
const main = document.querySelector('main');
Expand All @@ -8,4 +9,6 @@ export default async function buildAutoBlocks() {
main.firstElementChild.insertAdjacentElement('afterend', sideNavBlock);
main.querySelector(':scope > div:nth-child(3)')?.prepend(buildBlock('social-media', { elems: [] }));
main.lastElementChild.append(buildBlock('social-media', { elems: [] }));

buildArticleSchema();
}

0 comments on commit ee556c2

Please sign in to comment.