diff --git a/gatsby-node.js b/gatsby-node.js index 84cfa7850..59a1444d3 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -1,4 +1,3 @@ -const siteConfig = require('./site-config'); const { createFilePath } = require('gatsby-source-filesystem'); const appInsights = require('applicationinsights'); const makePluginData = require('./src/helpers/plugin-data'); @@ -98,14 +97,10 @@ exports.createPages = async ({ graphql, actions }) => { } frontmatter { index - redirects - experts - consulting } parent { ... on File { name - relativeDirectory } } } @@ -114,16 +109,19 @@ exports.createPages = async ({ graphql, actions }) => { filter: { frontmatter: { type: { in: ["rule"] } } } ) { nodes { + excerpt(format: HTML, pruneLength: 500) fields { slug } frontmatter { uri title - archivedreason related redirects + archivedreason + guid } + htmlAst } } } @@ -131,28 +129,14 @@ exports.createPages = async ({ graphql, actions }) => { const categoryTemplate = require.resolve('./src/templates/category.js'); const ruleTemplate = require.resolve('./src/templates/rule.js'); - result.data.categories.nodes.forEach((node) => { - // Find any categories that can't resolve a rule - node.frontmatter.index.forEach((inCat) => { - var match = false; - - result.data.rules.nodes.forEach((rulenode) => { - if (rulenode.frontmatter.uri == inCat) { - match = true; - } - if (rulenode.frontmatter.redirects) { - rulenode.frontmatter.redirects.forEach((redirect) => { - if (redirect == inCat) { - match = true; - } - }); - } - }); - - if (match == false) { - // eslint-disable-next-line no-console - console.log(node.parent.name + ' cannot find rule ' + inCat); + let indexedRule = []; + result.data.rules.nodes.forEach((rule) => { + if ( + node.frontmatter.index.includes(rule.frontmatter.uri) && + !rule.frontmatter.archivedreason + ) { + indexedRule.push(rule); } }); @@ -162,15 +146,15 @@ exports.createPages = async ({ graphql, actions }) => { component: categoryTemplate, context: { slug: node.fields.slug, - index: node.frontmatter.index, - redirects: node.frontmatter.redirects, + pageRules: indexedRule, }, }); }); + const orphanedRules = []; + result.data.rules.nodes.forEach((node) => { - // Find any rules missing a category - var match = false; + let match = false; if (!node.frontmatter.archivedreason) { result.data.categories.nodes.forEach((catNode) => { catNode.frontmatter.index.forEach((inCat) => { @@ -182,13 +166,9 @@ exports.createPages = async ({ graphql, actions }) => { } else { match = true; } + if (match == false) { - // eslint-disable-next-line no-console - console.log( - 'https://www.ssw.com.au/rules/' + - node.frontmatter.uri + - ' is missing a category' - ); + orphanedRules.push(node.frontmatter.uri); } // Create the page for the rule @@ -206,11 +186,20 @@ exports.createPages = async ({ graphql, actions }) => { }); }); - const profilePage = require.resolve('./src/pages/profile.js'); + // const profilePage = require.resolve('./src/pages/profile.js'); + // createPage({ + // path: `${siteConfig.pathPrefix}/people/`, + // matchPath: `${siteConfig.pathPrefix}/people/:gitHubUsername`, + // component: profilePage, + // }); + + const orphanedPage = require.resolve('./src/templates/orphaned.js'); createPage({ - path: `${siteConfig.pathPrefix}/people/`, - matchPath: `${siteConfig.pathPrefix}/people/:gitHubUsername`, - component: profilePage, + path: '/orphaned/', + component: orphanedPage, + context: { + index: orphanedRules, + }, }); }; diff --git a/src/pages/archived.js b/src/pages/archived.js index f2fee0687..eb8b327a1 100644 --- a/src/pages/archived.js +++ b/src/pages/archived.js @@ -170,17 +170,11 @@ function ArchivedWithQuery(props) { } ) { nodes { - html frontmatter { type title index } - parent { - ... on File { - name - } - } } } topCategories: allMarkdownRemark( @@ -190,7 +184,6 @@ function ArchivedWithQuery(props) { } ) { nodes { - html frontmatter { type title @@ -211,7 +204,6 @@ function ArchivedWithQuery(props) { } ) { nodes { - html frontmatter { type title @@ -221,7 +213,6 @@ function ArchivedWithQuery(props) { parent { ... on File { name - relativeDirectory } } } diff --git a/src/pages/index.js b/src/pages/index.js index b07243ccf..9186904dc 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -17,10 +17,6 @@ import { config } from '@fortawesome/fontawesome-svg-core'; config.autoAddCss = false; const Index = ({ data, location }) => { - const notArchivedRules = data.rules.nodes.filter( - (r) => !r.frontmatter.archivedreason - ); - return (
@@ -54,7 +50,7 @@ const Index = ({ data, location }) => { ); @@ -122,11 +118,6 @@ function IndexWithQuery(props) { title index } - parent { - ... on File { - name - } - } } } topCategories: allMarkdownRemark( @@ -162,7 +153,6 @@ function IndexWithQuery(props) { type title index - archivedreason } parent { ... on File { @@ -173,7 +163,9 @@ function IndexWithQuery(props) { } } rules: allMarkdownRemark( - filter: { frontmatter: { type: { eq: "rule" } } } + filter: { + frontmatter: { archivedreason: { eq: null }, type: { eq: "rule" } } + } ) { nodes { frontmatter { diff --git a/src/pages/profile.js b/src/pages/profile.js index 292466250..cc2a59c23 100644 --- a/src/pages/profile.js +++ b/src/pages/profile.js @@ -153,9 +153,6 @@ function ProfileWithQuery(props) { title uri guid - authors { - title - } } htmlAst } diff --git a/src/templates/category.js b/src/templates/category.js index 81b947086..bad074808 100644 --- a/src/templates/category.js +++ b/src/templates/category.js @@ -29,7 +29,7 @@ const appInsights = new ApplicationInsights({ appInsights.loadAppInsights(); -export default function Category({ data }) { +export default function Category({ data, pageContext }) { const linkRef = useRef(); const category = data.markdownRemark; @@ -48,13 +48,7 @@ export default function Category({ data }) { greyBox: GreyBox, }; - var rules = data.rule.nodes - .filter((r) => { - return !r.frontmatter.archivedreason; - }) - .filter((r) => { - return category.frontmatter.index.includes(r.frontmatter.uri); - }); + const rules = pageContext.pageRules; return (
@@ -156,7 +150,7 @@ export default function Category({ data }) {
    {category.frontmatter.index.map((r, i) => { - var rule = rules.find((rr) => rr.frontmatter.uri == r); + let rule = rules.find((rr) => rr.frontmatter.uri == r); if (!rule) { return; } @@ -311,7 +305,7 @@ Category.propTypes = { }; export const query = graphql` - query ($slug: String!, $index: [String]!) { + query ($slug: String!) { markdownRemark(fields: { slug: { eq: $slug } }) { htmlAst frontmatter { @@ -330,19 +324,5 @@ export const query = graphql` } } } - rule: allMarkdownRemark(filter: { frontmatter: { uri: { in: $index } } }) { - nodes { - excerpt(format: HTML, pruneLength: 500) - frontmatter { - uri - archivedreason - title - guid - consulting - experts - } - htmlAst - } - } } `; diff --git a/src/pages/orphaned.js b/src/templates/orphaned.js similarity index 72% rename from src/pages/orphaned.js rename to src/templates/orphaned.js index 5e1c10079..1e3e9e646 100644 --- a/src/pages/orphaned.js +++ b/src/templates/orphaned.js @@ -1,9 +1,8 @@ import React, { useRef, useState, useEffect } from 'react'; -import { useStaticQuery, graphql } from 'gatsby'; +import { graphql } from 'gatsby'; import PropTypes from 'prop-types'; import { config } from '@fortawesome/fontawesome-svg-core'; import Breadcrumb from '../components/breadcrumb/breadcrumb'; -import Tooltip from '../components/tooltip/tooltip'; import RadioButton from '../components/radio-button/radio-button'; import { Link } from 'gatsby'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; @@ -44,39 +43,7 @@ const Orphaned = ({ data }) => { setSelectedOption(e.target.value); }; - /** - * Get all rules that don't have an associated category - * @param {Object} rules All rule nodes - * @param {Object} categories All category nodes - * @return {array} All rules without an associated category - */ - const findOrphanedRules = (rules, categories) => { - const orphanedRules = []; - - rules.nodes.forEach((node) => { - // Find any rules missing a category - var match = false; - if (!node.frontmatter.archivedreason) { - categories.nodes.forEach((catNode) => { - catNode.frontmatter.index.forEach((inCat) => { - if (node.frontmatter.uri == inCat) { - match = true; - } - }); - }); - } else { - match = true; - } - if (match == false) { - orphanedRules.push(node); - } - }); - - return orphanedRules; - }; - - const category = data.categories.nodes[0]; - const rules = findOrphanedRules(data.rules, data.categories); + const rules = data.rules.nodes; return (
    @@ -91,20 +58,6 @@ const Orphaned = ({ data }) => { {' - '} {rules.length} {rules.length > 1 ? 'Rules' : 'Rule'} - - - - - -
    @@ -272,89 +225,20 @@ Orphaned.propTypes = { location: PropTypes.object.isRequired, }; -function OrphanedWithQuery(props) { - const data = useStaticQuery(graphql` - query OrphanedQuery { - main: allMarkdownRemark( - filter: { - fileAbsolutePath: { regex: "/(categories)/" } - frontmatter: { type: { eq: "main" } } - } - ) { - nodes { - html - frontmatter { - type - title - index - } - parent { - ... on File { - name - } - } - } - } - topCategories: allMarkdownRemark( - filter: { - fileAbsolutePath: { regex: "/(categories)/" } - frontmatter: { type: { eq: "top-category" } } - } - ) { - nodes { - html - frontmatter { - type - title - index - } - parent { - ... on File { - name - relativeDirectory - } - } - } - } - categories: allMarkdownRemark( - filter: { - fileAbsolutePath: { regex: "/(categories)/" } - frontmatter: { type: { eq: "category" } } - } - ) { - nodes { - html - frontmatter { - type - title - archivedreason - index - } - parent { - ... on File { - name - relativeDirectory - } - } - } - } - rules: allMarkdownRemark( - filter: { frontmatter: { type: { eq: "rule" } } } - ) { - nodes { - frontmatter { - uri - archivedreason - title - } - html - excerpt(format: HTML, pruneLength: 500) +export default Orphaned; + +export const query = graphql` + query ($index: [String]!) { + rules: allMarkdownRemark(filter: { frontmatter: { uri: { in: $index } } }) { + nodes { + frontmatter { + uri + archivedreason + title } + html + excerpt(format: HTML, pruneLength: 500) } } - `); - - return ; -} - -export default OrphanedWithQuery; + } +`;