diff --git a/gatsby-node.js b/gatsby-node.js index 9a8fc3304..5ca532f28 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -188,7 +188,7 @@ exports.createPages = ({ graphql, actions }) => { const snippets = result.data.allSnippet.edges; snippets.forEach(snippet => { - if(!snippet.archived) { + if (!snippet.node.archived) { createPage({ path: `/snippet${snippet.node.slug}`, component: snippetPage, @@ -210,7 +210,11 @@ exports.createPages = ({ graphql, actions }) => { }); // Create tag pages. - const tags = [...new Set(snippets.map(snippet => snippet.tags.primary))].sort((a,b) => a.localeCompare(b)); + const tags = [...new Set( + snippets.map(snippet => (snippet.tags || {primary: null}).primary) + )] + .filter(Boolean) + .sort((a, b) => a.localeCompare(b)); tags.forEach(tag => { const tagPath = `/tag/${toKebabCase(tag)}/`; diff --git a/src/docs/components/SnippetCard.js b/src/docs/components/SnippetCard.js index e2088ec20..0b02ab6e4 100644 --- a/src/docs/components/SnippetCard.js +++ b/src/docs/components/SnippetCard.js @@ -42,24 +42,18 @@ const CardCorner = ({ difficulty = 'intermediate' }) => ( // =================================================== const FullCard = ({ snippetData, difficulty, isDarkMode }) => { const [examplesOpen, setExamplesOpen] = React.useState(false); - const tags = snippetData.tags; - let cardCodeHtml = `${optimizeAllNodes( - getCodeBlocks(snippetData.html).code, - )}`; - let cardExamplesHtml = `${optimizeAllNodes( - getCodeBlocks(snippetData.html).example, - )}`; + return (

{snippetData.title}

- {tags.map(tag => ( + {snippetData.tags.map(tag => ( {tag} ))}
@@ -83,12 +77,9 @@ const FullCard = ({ snippetData, difficulty, isDarkMode }) => { aria-label='Copy to clipboard' /> - {/* */}
         
diff --git a/src/docs/templates/SnippetPage.js b/src/docs/templates/SnippetPage.js index 996e996f8..9ab06301c 100644 --- a/src/docs/templates/SnippetPage.js +++ b/src/docs/templates/SnippetPage.js @@ -11,14 +11,11 @@ import BackArrowIcon from '../components/SVGs/BackArrowIcon'; // Individual snippet page template // =================================================== const SnippetPage = props => { - const post = props.data.markdownRemark; - const postData = props.data.snippetDataJson.data.find( - v => v.title === post.frontmatter.title, - ); + const snippet = props.data.snippet; return ( <> - + { @@ -52,7 +52,7 @@ export default connect( )(SnippetPage); export const pageQuery = graphql` - query BlogPostBySlug($slug: String!, $scope: String!) { + query SnippetBySlug($slug: String!) { logo: file(absolutePath: { regex: "/logo_reverse_md.png/" }) { id childImageSharp { @@ -61,42 +61,23 @@ export const pageQuery = graphql` } } } - allMarkdownRemark { - edges { - node { - fields { - slug - } - fileAbsolutePath - frontmatter { - title - } - } + snippet (slug: {eq: $slug }) { + title + html { + full + code + example + text } - } - markdownRemark(fields: { slug: { eq: $slug } }) { - id - fields { - slug + code { + src } - excerpt(pruneLength: 160) - html - frontmatter { - title + tags { + all } - } - snippetDataJson(meta: { type: { eq: "snippetArray" }, scope: {eq: $scope} }) { - data { - title - id - attributes { - text - codeBlocks { - es6 - example - } - tags - } + title + text { + short } } }