Skip to content

Commit

Permalink
Add frontmatter data for site crawling into a datastore.
Browse files Browse the repository at this point in the history
Limit to docs and guides.
  • Loading branch information
Kyle Taylor committed Jan 31, 2024
1 parent 9e748bc commit 100e009
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/layout/seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ function SEO({
tags,
reviewed,
type,
audience,
product,
integration,
cms
}) {
const { site } = useStaticQuery(
graphql`
Expand Down Expand Up @@ -74,6 +78,43 @@ function SEO({
// Fix categories for og:article:section.
// Spec says there should only be one value, or multiple tags. Limit to 1 for now.
const category = (categories && categories.length > 0) ? categories[0][0].toUpperCase() + categories[0].slice(1) : "Other";

// Helper function for metadata.
function formatMetadata(field) {
return (Array.isArray(field) && field[0] !== "--" && field.length > 0) ? field.join(", ") : "";
}

// Add specific metadata for crawling the site to create a structured datastore.
const audienceFormatted = formatMetadata(audience);
const cmsFormatted = formatMetadata(cms);
const productFormatted = formatMetadata(product);
const integrationFormatted = formatMetadata(integration);

// Prepare data for custom datastore.
const crawlDatastore = {
title: title,
description: description,
categories: categories,
keywords: keywords,
image: metaImage,
type: type,
audience: audienceFormatted,
cms: cmsFormatted,
product: productFormatted,
integration: integrationFormatted
};

// Convert to array of objects with name and content
const datastore = Object.entries(crawlDatastore).map(([key, value]) => {
return {
name: `pantheon-${key}`,
content: value
};
});

// Merge with existing metadata.
meta = meta.concat(datastore);

return (
<Helmet
htmlAttributes={{
Expand Down
8 changes: 8 additions & 0 deletions src/templates/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ class DocTemplate extends React.Component {
keywords={node.frontmatter.tags}
reviewed={isoDate.frontmatter.reviewed}
type={node.frontmatter.type}
audience={node.frontmatter.audience}
product={node.frontmatter.product}
integration={node.frontmatter.integration}
cms={node.frontmatter.cms}

/>
<main id="docs-main" tabIndex="-1">
<Container
Expand Down Expand Up @@ -184,6 +189,9 @@ export const pageQuery = graphql`
showtoc
tags
type
audience
product
integration
}
fileAbsolutePath
}
Expand Down
7 changes: 7 additions & 0 deletions src/templates/guide.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ class GuideTemplate extends React.Component {
image={"/images/assets/terminus-thumbLarge.png"}
reviewed={isoDate.frontmatter.reviewed}
type={node.frontmatter.type}
product={node.frontmatter.product}
cms={node.frontmatter.cms}
audience={node.frontmatter.audience}
integration={node.frontmatter.integration}
/>
<Navbar
slot="guide-menu"
Expand Down Expand Up @@ -195,6 +199,9 @@ export const pageQuery = graphql`
reviewed(formatString: "MMMM DD, YYYY")
tags
type
audience
product
integration
}
fileAbsolutePath
}
Expand Down

0 comments on commit 100e009

Please sign in to comment.