From 6387e8614cbfb7f92988cd959e5bd289cccf4621 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Wed, 18 Dec 2024 12:57:47 -0700 Subject: [PATCH 1/2] Fix Terminus Changelog (#9351) * add a console log for releases * fix broken console logging * Apply Prettier formatting * update the graphql query to fix sorting * Apply Prettier formatting * remove the graphql filter * Apply Prettier formatting * don't display releases older than a year * Apply Prettier formatting * arbitrary change to trigger build * filter releases earlier * Apply Prettier formatting * maybe fix filtering * Apply Prettier formatting * maybe fix filtering again * Apply Prettier formatting * change the title and remove the heading * Align title in template file * Align title in template file --------- Co-authored-by: Pantheon Bot Co-authored-by: Rachel --- source/content/terminus/11-updates.md | 4 +- src/components/releases.js | 78 +++++++++++++++------------ src/components/terminusVersion.js | 28 +++++----- src/templates/terminusCommand.js | 2 +- src/templates/terminuspage.js | 2 +- 5 files changed, 64 insertions(+), 50 deletions(-) diff --git a/source/content/terminus/11-updates.md b/source/content/terminus/11-updates.md index 40b3724594..4d20bb6d60 100644 --- a/source/content/terminus/11-updates.md +++ b/source/content/terminus/11-updates.md @@ -1,6 +1,6 @@ --- title: Terminus Guide -subtitle: Current Terminus Release, Changelog, and Updates +subtitle: Terminus Changelog description: Stay up to date on the latest Terminus version. terminuspage: true type: terminuspage @@ -16,8 +16,6 @@ product: [terminus] integration: [--] --- - - ## Changelog diff --git a/src/components/releases.js b/src/components/releases.js index 36f6c33776..e8d7474728 100644 --- a/src/components/releases.js +++ b/src/components/releases.js @@ -1,49 +1,61 @@ -import React from "react" -import { StaticQuery, graphql } from "gatsby" -import { MDXRenderer } from "gatsby-plugin-mdx" -import { MDXProvider } from "@mdx-js/react" +import React from 'react'; +import { StaticQuery, graphql } from 'gatsby'; +import { MDXRenderer } from 'gatsby-plugin-mdx'; +import { MDXProvider } from '@mdx-js/react'; +import { subYears, parseISO, isAfter } from 'date-fns'; -import { headline1, headline2, headline3 } from "./releaseHeadlines" +import { headline1, headline2, headline3 } from './releaseHeadlines'; const shortcodes = { h1: headline1, h2: headline2, h3: headline3, -} +}; -const Releases = ({ data }) => ( - <> - {data.allTerminusReleasesJson.edges.map((release, i) => { - return ( -
-

- {release.node.tag_name} -

- - - {release.node.fields.markdownBody.childMdx.body} - - -
-
- ) - })} - -) +const Releases = ({ data }) => { + const oneYearAgo = subYears(new Date(), 1); -export default props => ( + // Safe Filtering: Ensure `published_at` exists before filtering + const filteredReleases = data.allTerminusReleasesJson.edges.filter( + (release) => { + const publishedDate = release.node.published_at; + return publishedDate && isAfter(parseISO(publishedDate), oneYearAgo); + }, + ); + + return ( + <> + {filteredReleases.length > 0 ? ( + filteredReleases.map((release, i) => ( +
+

+ {release.node.tag_name} +

+ + + {release.node.fields.markdownBody.childMdx.body} + + +
+
+ )) + ) : ( +

No recent releases found.

+ )} + + ); +}; + +export default (props) => ( ( } } `} - render={data => } + render={(data) => } /> -) +); diff --git a/src/components/terminusVersion.js b/src/components/terminusVersion.js index 53229fbe7e..52910b2408 100644 --- a/src/components/terminusVersion.js +++ b/src/components/terminusVersion.js @@ -1,22 +1,26 @@ -import React from "react" -import { useStaticQuery, graphql } from "gatsby" +import React from 'react'; +import { useStaticQuery, graphql } from 'gatsby'; function TerminusVersion({ text }) { - const { terminusReleasesJson } = useStaticQuery( - graphql` - query { - terminusReleasesJson { - tag_name + const { allTerminusReleasesJson } = useStaticQuery(graphql` + query { + allTerminusReleasesJson(sort: { fields: [published_at], order: DESC }) { + edges { + node { + tag_name + } } } - ` - ) + } + `); + + const latestRelease = allTerminusReleasesJson.edges[0].node.tag_name; return (

- {text} {terminusReleasesJson.tag_name} + {text} {latestRelease}

- ) + ); } -export default TerminusVersion +export default TerminusVersion; diff --git a/src/templates/terminusCommand.js b/src/templates/terminusCommand.js index a2f17aadd4..faeb4a32de 100644 --- a/src/templates/terminusCommand.js +++ b/src/templates/terminusCommand.js @@ -70,7 +70,7 @@ const items = [ { id: 'docs-terminus-updates', link: '/terminus/updates', - title: 'Current Terminus Release and Changelog', + title: 'Terminus Changelog', }, { diff --git a/src/templates/terminuspage.js b/src/templates/terminuspage.js index c4ed59adfc..810cc76461 100644 --- a/src/templates/terminuspage.js +++ b/src/templates/terminuspage.js @@ -70,7 +70,7 @@ const items = [ { id: 'docs-terminus-updates', link: '/terminus/updates', - title: 'Current Terminus Release and Changelog', + title: 'Terminus Changelog', }, { From 603eedb812402a56f516406bdb1cf3f1fd3aabb0 Mon Sep 17 00:00:00 2001 From: Steve Persch Date: Wed, 18 Dec 2024 14:18:34 -0600 Subject: [PATCH 2/2] running prettier on big gatsby files (#9358) --- gatsby-browser.js | 54 ++++---- gatsby-node.js | 311 +++++++++++++++++++++++----------------------- gatsby-ssr.js | 43 ++++--- 3 files changed, 215 insertions(+), 193 deletions(-) diff --git a/gatsby-browser.js b/gatsby-browser.js index 794bf32399..e3cff6793b 100644 --- a/gatsby-browser.js +++ b/gatsby-browser.js @@ -1,53 +1,57 @@ -import React from "react" -import { location, globalHistory } from "@reach/router" +import React from 'react'; +import { location, globalHistory } from '@reach/router'; // Import PDS Global wrapper for applying global context providers. -import { GlobalWrapper } from "@pantheon-systems/pds-toolkit-react" -import { MOBILE_MENU_BREAKPOINT } from './src/vars/responsive' +import { GlobalWrapper } from '@pantheon-systems/pds-toolkit-react'; +import { MOBILE_MENU_BREAKPOINT } from './src/vars/responsive'; // Import PDS core styles. -import "./node_modules/@pantheon-systems/pds-toolkit-react/_dist/css/pds-core.css" -import "./node_modules/@pantheon-systems/pds-toolkit-react/_dist/css/pds-layouts.css" -import "./node_modules/@pantheon-systems/pds-toolkit-react/_dist/css/pds-components.css" +import './node_modules/@pantheon-systems/pds-toolkit-react/_dist/css/pds-core.css'; +import './node_modules/@pantheon-systems/pds-toolkit-react/_dist/css/pds-layouts.css'; +import './node_modules/@pantheon-systems/pds-toolkit-react/_dist/css/pds-components.css'; // Global styles -import "./src/styles/main.css" -import "./src/styles/custom-glyphicons.css" -import "./src/styles/pds-additions.css" +import './src/styles/main.css'; +import './src/styles/custom-glyphicons.css'; +import './src/styles/pds-additions.css'; // custom typefaces -import "prismjs/themes/prism-okaidia.css" +import 'prismjs/themes/prism-okaidia.css'; // Code block line numbering -import "prismjs/plugins/line-numbers/prism-line-numbers.css" +import 'prismjs/plugins/line-numbers/prism-line-numbers.css'; // Code block shell prompt -import "./src/styles/codeBlocks.css" +import './src/styles/codeBlocks.css'; // TOC generator -import "tocbot/dist/tocbot.css" -import "tocbot/dist/tocbot.min.js" +import 'tocbot/dist/tocbot.css'; +import 'tocbot/dist/tocbot.min.js'; //Segment export const onRouteUpdate = () => { - window.locations = window.locations || [document.referrer] - locations.push(window.location.href) - window.previousPath = locations[locations.length - 2] + window.locations = window.locations || [document.referrer]; + locations.push(window.location.href); + window.previousPath = locations[locations.length - 2]; window.analytics && window.analytics.page({ url: window.location.href, referrer: window.previousPath, title: document.title, - }) + }); //console.log("Title: ", document.title) //For debugging -} +}; // Trigger resize event once rendered export const onInitialClientRender = () => { - window.dispatchEvent(new Event("resize")) -} + window.dispatchEvent(new Event('resize')); +}; -// Global context providers +// Global context providers. export const wrapRootElement = ({ element }) => { - return {element} -} + return ( + + {element} + + ); +}; diff --git a/gatsby-node.js b/gatsby-node.js index 369bcc6896..d431b78b56 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -1,7 +1,7 @@ -const path = require(`path`) -const crypto = require("crypto") -const matter = require("gray-matter") -var fs = require("fs-extra") +const path = require(`path`); +const crypto = require('crypto'); +const matter = require('gray-matter'); +var fs = require('fs-extra'); /* For additional reference material, see @@ -13,37 +13,37 @@ into web pages. It is prime for refactoring. /** This helper function determines what slug a piece of content will use */ const calculateSlug = (node, getNode) => { - const fileName = getNode(node.parent).name // Sets the filename from GraphQL + const fileName = getNode(node.parent).name; // Sets the filename from GraphQL if (node.frontmatter.permalink) { //If the "permalink" frontmatter value is present... return node.frontmatter.permalink // return it. - .replace(":basename", fileName) // If permalink includes ":basename", prepend the filename to the slug - .replace("docs", "") // If it includes "docs", remove it. Docs is added by the pathPrefix in gatsby-config.js + .replace(':basename', fileName) // If permalink includes ":basename", prepend the filename to the slug + .replace('docs', ''); // If it includes "docs", remove it. Docs is added by the pathPrefix in gatsby-config.js } // I'm honestly not sure about this. If Alex isn't around and you need to know, ask Octahedroid. if (fileName === undefined) { - return `${fileName}` + return `${fileName}`; } // This section creates the changelog slug based on the YYYY-MM-DD-MONTH.md template - if (getNode(node.parent).absolutePath.includes("changelogs")) { + if (getNode(node.parent).absolutePath.includes('changelogs')) { // If the file is in the changelogs directory... - const split = fileName.split("-") // split the file name where hyphenated... - return `changelog/${split[0]}/${split[1]}` // and return a slug of changelog/YYYY/MM + const split = fileName.split('-'); // split the file name where hyphenated... + return `changelog/${split[0]}/${split[1]}`; // and return a slug of changelog/YYYY/MM } // This section creates the releasenotes slug based on the YYYY-MM-DD-slug.md template - if (getNode(node.parent).absolutePath.includes("releasenotes")) { + if (getNode(node.parent).absolutePath.includes('releasenotes')) { // If the file is in the releasenotes directory... // split the file name where hyphenated. - const split = fileName.split("-") + const split = fileName.split('-'); // set a const to remaining slug based on the keys from split that are not the date. - const remainingSlug = split.slice(3).join("-") - return `release-notes/${split[0]}/${split[1]}/${remainingSlug}` // and return a slug of releasenotes/YYYY/MM/slug + const remainingSlug = split.slice(3).join('-'); + return `release-notes/${split[0]}/${split[1]}/${remainingSlug}`; // and return a slug of releasenotes/YYYY/MM/slug } - return `${fileName}` // Otherwise, as long as there is a filename in GraphQL, use it as the slug. -} + return `${fileName}`; // Otherwise, as long as there is a filename in GraphQL, use it as the slug. +}; /* This helper function helps determine which template should be applied to a piece of content */ const calculateTemplate = (node, defaultTemplate) => { @@ -54,11 +54,11 @@ const calculateTemplate = (node, defaultTemplate) => { node.frontmatter.layout !== null ) { // If the node has the layout value in frontmatter... - return node.frontmatter.layout // use that value. + return node.frontmatter.layout; // use that value. } - return defaultTemplate // Otherwise, use the default template argument value. -} + return defaultTemplate; // Otherwise, use the default template argument value. +}; /* These helper functions are used to provide multi-page guide pages with the previous and next pages in the guide, to be used in the construction of the table of contents. @@ -67,43 +67,43 @@ const calculatePrevious = (guide) => { // The function accepts as an argument the node of the guide page in question if (!guide.previous) { // If the page doesn't have a value for the "previous" field in GraphQL - return null // return nothing. + return null; // return nothing. } // Also return nothing if the guide_directory value doesn't exist. if ( guide.node.fields.guide_directory !== guide.previous.fields.guide_directory ) { - return null + return null; } // Otherwise, return the slug of the page identified as previous by GraphQL. How it determines which one is previous, unclear to me at this time. - return guide.previous.fields.slug -} + return guide.previous.fields.slug; +}; // Same as above. const calculateNext = (guide) => { if (!guide.next) { - return null + return null; } if (guide.node.fields.guide_directory !== guide.next.fields.guide_directory) { - return null + return null; } - return guide.next.fields.slug -} + return guide.next.fields.slug; +}; const digest = (str) => str != null - ? crypto.createHash("md5").update(str).digest("hex") - : crypto.createHash("md5").update(" ").digest("hex") + ? crypto.createHash('md5').update(str).digest('hex') + : crypto.createHash('md5').update(' ').digest('hex'); exports.onCreateWebpackConfig = ({ actions }) => { actions.setWebpackConfig({ resolve: { - modules: [path.resolve(__dirname, "src"), "node_modules"], + modules: [path.resolve(__dirname, 'src'), 'node_modules'], }, - }) -} + }); +}; exports.createSchemaCustomization = ({ actions, schema }) => { actions.createFieldExtension({ @@ -112,13 +112,13 @@ exports.createSchemaCustomization = ({ actions, schema }) => { return { resolve(source, args, context, info) { if (source[info.fieldName] == null) { - return false + return false; } - return source[info.fieldName] + return source[info.fieldName]; }, - } + }; }, - }) + }); actions.createTypes(` type Mdx implements Node { @@ -128,11 +128,11 @@ exports.createSchemaCustomization = ({ actions, schema }) => { type Frontmatter { draft: Boolean @defaultFalse } - `) -} + `); +}; exports.createPages = ({ graphql, actions }) => { - const { createPage } = actions + const { createPage } = actions; return graphql(` { @@ -195,15 +195,17 @@ exports.createPages = ({ graphql, actions }) => { } } - - allIframeEmbeds: allMdx(limit: 10, filter: {fileAbsolutePath: {regex: "/iframeembeds/"}}) { - edges { - node { - slug - body - } + allIframeEmbeds: allMdx( + limit: 10 + filter: { fileAbsolutePath: { regex: "/iframeembeds/" } } + ) { + edges { + node { + slug + body } } + } allReleaseNotes: allMdx( filter: { fileAbsolutePath: { regex: "/releasenotes/" } } @@ -300,29 +302,29 @@ exports.createPages = ({ graphql, actions }) => { } `).then((result) => { if (result.errors) { - throw result.errors + throw result.errors; } // Create doc pages. - const docs = result.data.allDocs.edges + const docs = result.data.allDocs.edges; docs.forEach((doc) => { - const template = calculateTemplate(doc.node, "doc") + const template = calculateTemplate(doc.node, 'doc'); createPage({ path: doc.node.fields.slug, component: path.resolve(`./src/templates/${template}.js`), context: { slug: doc.node.fields.slug, }, - }) - }) + }); + }); // Create guide pages. - const guides = result.data.allGuides.edges + const guides = result.data.allGuides.edges; guides.forEach((guide) => { if (guide.node.fields.guide_directory !== null) { - const previous = calculatePrevious(guide) - const next = calculateNext(guide) - const template = calculateTemplate(guide.node, "guide") + const previous = calculatePrevious(guide); + const next = calculateNext(guide); + const template = calculateTemplate(guide.node, 'guide'); createPage({ path: guide.node.fields.slug, component: path.resolve(`./src/templates/${template}.js`), @@ -332,27 +334,27 @@ exports.createPages = ({ graphql, actions }) => { previous, next, }, - }) + }); } else { - const template = calculateTemplate(guide.node, "doc") + const template = calculateTemplate(guide.node, 'doc'); createPage({ path: guide.node.fields.slug, component: path.resolve(`./src/templates/${template}.js`), context: { slug: guide.node.fields.slug, }, - }) + }); } - }) + }); // Create changelog pages. - const changelogs = result.data.allChangelogs.edges + const changelogs = result.data.allChangelogs.edges; changelogs.forEach((changelog) => { const previous = changelog.previous ? changelog.previous.fields.slug || null - : null - const next = changelog.next ? changelog.next.fields.slug || null : null - const template = calculateTemplate(changelog.node, "changelog") + : null; + const next = changelog.next ? changelog.next.fields.slug || null : null; + const template = calculateTemplate(changelog.node, 'changelog'); createPage({ path: changelog.node.fields.slug, component: path.resolve(`./src/templates/${template}.js`), @@ -361,25 +363,25 @@ exports.createPages = ({ graphql, actions }) => { next: previous, previous: next, }, - }) - }) + }); + }); // Create changelog pagination. - const postsPerPage = 6 - const numPages = Math.ceil(changelogs.length / postsPerPage) + const postsPerPage = 6; + const numPages = Math.ceil(changelogs.length / postsPerPage); Array.from({ length: numPages }).forEach((_, i) => { - const currentPage = i + 1 + const currentPage = i + 1; const next = currentPage === 1 ? null : currentPage === 2 - ? `/changelog/` - : `/changelog/page/${currentPage - 1}` + ? `/changelog/` + : `/changelog/page/${currentPage - 1}`; const previous = - currentPage < numPages ? `/changelog/page/${currentPage + 1}` : null + currentPage < numPages ? `/changelog/page/${currentPage + 1}` : null; createPage({ path: i === 0 ? `/changelog/` : `/changelog/page/${i + 1}`, - component: path.resolve("./src/templates/changelogs.js"), + component: path.resolve('./src/templates/changelogs.js'), context: { limit: postsPerPage, skip: i * postsPerPage, @@ -388,14 +390,14 @@ exports.createPages = ({ graphql, actions }) => { previous, next, }, - }) - }) + }); + }); // Create Terminus Command pages - const terminusCommands = result.data.dataJson.commands + const terminusCommands = result.data.dataJson.commands; terminusCommands.forEach((command) => { - const slugRegExp = /:/g - const slug = command.name.replace(slugRegExp, "-") + const slugRegExp = /:/g; + const slug = command.name.replace(slugRegExp, '-'); createPage({ path: `terminus/commands/${slug}`, component: path.resolve(`./src/templates/terminusCommand.js`), @@ -403,33 +405,35 @@ exports.createPages = ({ graphql, actions }) => { slug: slug, name: command.name, }, - }) - }) + }); + }); // Create release notes without pagination. At a later date, we may want to add pagination. // And can reused the code above. createPage({ path: `/release-notes/`, - component: path.resolve("./src/templates/releaseNotesListing/index.js"), - }) + component: path.resolve('./src/templates/releaseNotesListing/index.js'), + }); // Create release notes pages for pagination. - const releaseNotesPostsPerPage = 8 - const releaseNotesNumPages = Math.ceil(result.data.allReleaseNotes.edges.length / releaseNotesPostsPerPage) + const releaseNotesPostsPerPage = 8; + const releaseNotesNumPages = Math.ceil( + result.data.allReleaseNotes.edges.length / releaseNotesPostsPerPage, + ); Array.from({ length: releaseNotesNumPages }).forEach((_, i) => { - const path2 = `/release-notes/${i+1}/`; + const path2 = `/release-notes/${i + 1}/`; createPage({ path: path2, - component: path.resolve("./src/templates/releaseNotesListing/index.js"), + component: path.resolve('./src/templates/releaseNotesListing/index.js'), context: { limit: releaseNotesPostsPerPage, skip: i * releaseNotesPostsPerPage, numPages: releaseNotesNumPages, i, }, - }) - }) + }); + }); // terminusCommands.forEach(command => { // const slugRegExp = /:/g @@ -445,27 +449,26 @@ exports.createPages = ({ graphql, actions }) => { // }) // Create each release note page. - const releaseNotes = result.data.allReleaseNotes.edges + const releaseNotes = result.data.allReleaseNotes.edges; releaseNotes.forEach((releaseNote) => { - const template = calculateTemplate(releaseNote.node, "releaseNotePage") + const template = calculateTemplate(releaseNote.node, 'releaseNotePage'); createPage({ path: releaseNote.node.fields.slug, component: path.resolve(`./src/templates/${template}.js`), context: { slug: releaseNote.node.fields.slug, }, - }) - }) + }); + }); // Create iframeembed page const iframeEmbeds = result.data.allIframeEmbeds.edges; iframeEmbeds.forEach((iframeEmbed) => { - // There's an odd bug where the slug value is inconsistent, even for the same file // across different gatsby builds. This is a workaround. // if the slug does not contain "iframeembeds" the add it - if (!iframeEmbed.node.slug.includes("iframeembeds")) { - iframeEmbed.node.slug = `iframeembeds/${iframeEmbed.node.slug}` + if (!iframeEmbed.node.slug.includes('iframeembeds')) { + iframeEmbed.node.slug = `iframeembeds/${iframeEmbed.node.slug}`; } createPage({ @@ -475,11 +478,11 @@ exports.createPages = ({ graphql, actions }) => { slug: iframeEmbed.node.slug, body: iframeEmbed.node.body, }, - }) - }) + }); + }); // Create contributor pages. - const contributors = result.data.allContributorYaml.edges + const contributors = result.data.allContributorYaml.edges; contributors.forEach((contributor) => { createPage({ path: `contributors/${contributor.node.yamlId}`, @@ -487,11 +490,11 @@ exports.createPages = ({ graphql, actions }) => { context: { id: contributor.node.yamlId, }, - }) - }) + }); + }); // Create topics pages. - const topics = result.data.allLandingsYaml.edges + const topics = result.data.allLandingsYaml.edges; topics.forEach((topic) => { createPage({ path: topic.node.path, @@ -499,153 +502,153 @@ exports.createPages = ({ graphql, actions }) => { context: { id: topic.node.id, }, - }) - }) + }); + }); - return null - }) -} + return null; + }); +}; exports.onCreateNode = ({ node, getNode, actions }) => { - const { createNode, createNodeField } = actions + const { createNode, createNodeField } = actions; - if (node.internal.owner === "gatsby-transformer-yaml") { + if (node.internal.owner === 'gatsby-transformer-yaml') { Object.keys(node).forEach((item) => { - if (!item.endsWith("Markdown")) { - return + if (!item.endsWith('Markdown')) { + return; } const textNode = { id: `${node.id}-${item}`, parent: node.id, - dir: path.resolve("./"), + dir: path.resolve('./'), internal: { type: `${node.internal.type}${item}`, - mediaType: "text/markdown", + mediaType: 'text/markdown', content: node[item], contentDigest: digest(node[item]), }, - } - createNode(textNode) + }; + createNode(textNode); createNodeField({ node, name: `${item}___NODE`, value: textNode.id, - }) - }) + }); + }); } // MDX content if (node.internal.type === `Mdx`) { - const sourceInstanceName = getNode(node.parent).sourceInstanceName - if (sourceInstanceName === "content") { - const editPath = `source/content/${getNode(node.parent).relativePath}` + const sourceInstanceName = getNode(node.parent).sourceInstanceName; + if (sourceInstanceName === 'content') { + const editPath = `source/content/${getNode(node.parent).relativePath}`; // Add editPath field createNodeField({ name: `editPath`, node, value: editPath, - }) + }); } // Add slug field - const slug = calculateSlug(node, getNode) + const slug = calculateSlug(node, getNode); createNodeField({ name: `slug`, node, value: slug, - }) + }); - if (slug.includes("guides/")) { - if (getNode(node.parent).relativeDirectory !== "guides") { + if (slug.includes('guides/')) { + if (getNode(node.parent).relativeDirectory !== 'guides') { // Add guide_directory field createNodeField({ name: `guide_directory`, node, value: `${getNode(node.parent).relativeDirectory}`, - }) + }); } } if ( - sourceInstanceName === "changelogs" || - sourceInstanceName === "releasenotes" + sourceInstanceName === 'changelogs' || + sourceInstanceName === 'releasenotes' ) { const content = matter(node.internal.content, { excerpt: true, - excerpt_separator: "", - }) - const excerpt = content.excerpt || "" + excerpt_separator: '', + }); + const excerpt = content.excerpt || ''; createNodeField({ name: `excerpt`, node, value: excerpt, - }) + }); const textNode = { id: `${node.id}-MarkdownBody`, parent: node.id, - dir: path.resolve("./"), + dir: path.resolve('./'), internal: { type: `${node.internal.type}MarkdownBody`, - mediaType: "text/markdown", + mediaType: 'text/markdown', content: excerpt, contentDigest: digest(excerpt), }, - } - createNode(textNode) + }; + createNode(textNode); // Create markdownBody___NODE field createNodeField({ node, - name: "markdownBody___NODE", + name: 'markdownBody___NODE', value: textNode.id, - }) + }); } } // Releases and Changelog Content - var nodeString = node.internal.type.toString() - var isReleaseJson = nodeString.includes("ReleasesJson") - if (isReleaseJson && !nodeString.includes("MarkdownBody")) { + var nodeString = node.internal.type.toString(); + var isReleaseJson = nodeString.includes('ReleasesJson'); + if (isReleaseJson && !nodeString.includes('MarkdownBody')) { //console.log("Creating markdownBody for ", node.internal.type.toString()) // For debugging // Add original_id as int to filter using GraphQL createNodeField({ name: `original_id`, node, value: parseInt(node.id), - }) + }); // Add text/markdown node children to Release and Changelog nodes const textNode = { id: `${node.id}-MarkdownBody`, parent: node.id, - dir: path.resolve("./"), + dir: path.resolve('./'), internal: { type: `${node.internal.type}MarkdownBody`, - mediaType: "text/markdown", - content: node.body || "", + mediaType: 'text/markdown', + content: node.body || '', contentDigest: digest(node.body), }, - } - createNode(textNode) + }; + createNode(textNode); // Create markdownBody___NODE field createNodeField({ node, - name: "markdownBody___NODE", + name: 'markdownBody___NODE', value: textNode.id, - }) + }); } -} +}; // This block moves script files from source to the public (build artifact) directory. exports.onPreBootstrap = () => { - const scriptsCopyFrom = `${__dirname}//source/scripts` - const scriptsCopyTo = `${__dirname}/public/scripts` + const scriptsCopyFrom = `${__dirname}//source/scripts`; + const scriptsCopyTo = `${__dirname}/public/scripts`; - fs.copySync(scriptsCopyFrom, scriptsCopyTo) -} + fs.copySync(scriptsCopyFrom, scriptsCopyTo); +}; -/* todo should there be an error thrown if a release note category is set that is not allowed */ +/* todo Should there be an error thrown if a release note category is set that is not allowed? */ /* todo, infer published date from file name. And throw an error if there are files that don't follow the pattern. */ diff --git a/gatsby-ssr.js b/gatsby-ssr.js index c256b36a8b..2c636681a8 100644 --- a/gatsby-ssr.js +++ b/gatsby-ssr.js @@ -1,26 +1,41 @@ -import React from 'react' +import React from 'react'; // Import PDS Global wrapper for applying global context providers. -import { GlobalWrapper } from "@pantheon-systems/pds-toolkit-react" -import { MOBILE_MENU_BREAKPOINT } from './src/vars/responsive' +import { GlobalWrapper } from '@pantheon-systems/pds-toolkit-react'; +import { MOBILE_MENU_BREAKPOINT } from './src/vars/responsive'; /* * Add global scripts to ensure Bootstrap and jQuery JS is included */ export const onRenderBody = ({ setPostBodyComponents }) => { setPostBodyComponents([ -