diff --git a/gatsby-config.js b/gatsby-config.js index 1c98cb4..2b348d2 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -23,6 +23,7 @@ module.exports = { ], }, }, + `gatsby-plugin-layout`, { resolve: `gatsby-transformer-remark`, plugins: [`gatsby-remark-prismjs`], diff --git a/gatsby-node.js b/gatsby-node.js index 31093c5..d07b343 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -6,6 +6,9 @@ const fs = require("fs") const requiredArticleFrontmatter = ["authors", "date"] +const LAYOUT_RESOURCES = "resources" +const LAYOUT_REGULAR = "regular" + let users = [] try { users = JSON.parse(fs.readFileSync("./users.json", "utf-8")) @@ -51,6 +54,7 @@ const createResources = async ({ createPage, graphql }) => { component: languageResources, context: { file: node.relativePath, + layout: LAYOUT_RESOURCES, }, }) }) @@ -84,6 +88,15 @@ exports.onCreateNode = async ({ node, getNode, actions }) => { } } +exports.onCreatePage = ({ page, actions }) => { + const { createPage } = actions + + page.context.layout = page.path.match(/resources/) + ? LAYOUT_RESOURCES + : LAYOUT_REGULAR + createPage(page) +} + exports.createPages = ({ actions, graphql }) => { const { createPage } = actions return createResources({ createPage, graphql }) diff --git a/package-lock.json b/package-lock.json index 77d8f02..6d47f9a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7729,6 +7729,14 @@ "slash": "^1.0.0" } }, + "gatsby-plugin-layout": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/gatsby-plugin-layout/-/gatsby-plugin-layout-1.1.2.tgz", + "integrity": "sha512-nXtF5SJbx+qcSQBXLnpq3YeaPN0LEbkkH3HOJcoFfynzY0cKH4o09+IO3WGxoV/XLBjcxc3OxZFwBqQaeL6Keg==", + "requires": { + "@babel/runtime": "^7.0.0" + } + }, "gatsby-plugin-manifest": { "version": "2.2.4", "resolved": "https://registry.npmjs.org/gatsby-plugin-manifest/-/gatsby-plugin-manifest-2.2.4.tgz", diff --git a/package.json b/package.json index bd2b5ca..16d9004 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "dependencies": { "gatsby": "^2.13.39", "gatsby-image": "^2.2.6", + "gatsby-plugin-layout": "^1.1.2", "gatsby-plugin-manifest": "^2.2.4", "gatsby-plugin-mdx": "^1.0.17", "gatsby-plugin-offline": "^2.2.4", diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx new file mode 100644 index 0000000..06f1b38 --- /dev/null +++ b/src/layouts/index.tsx @@ -0,0 +1,18 @@ +import React, { PropsWithChildren } from "react" +import { Layout } from "../components/Layout" +import { ResourcesLayout } from "../components/ResourcesLayout" + +export default function BaseLayout({ + children, + pageContext, +}: PropsWithChildren<{ + pageContext: { + layout?: string + } +}>) { + if (pageContext.layout === "resources") { + return {children} + } + + return {children} +} diff --git a/src/pages/404.tsx b/src/pages/404.tsx index 788f166..4891f4f 100644 --- a/src/pages/404.tsx +++ b/src/pages/404.tsx @@ -1,15 +1,14 @@ -import React from "react" +import React, { Fragment } from "react" -import { Layout } from "../components/Layout" import { SEO } from "../components/SEO" function NotFoundPage() { return ( - + NOT FOUND You just hit a route that doesn't exist... the sadness. - + ) } diff --git a/src/pages/about.tsx b/src/pages/about.tsx index 8cef3cc..902626b 100644 --- a/src/pages/about.tsx +++ b/src/pages/about.tsx @@ -1,7 +1,6 @@ -import React from "react" +import React, { Fragment } from "react" import { graphql } from "gatsby" import { Markdown } from "../components/Markdown" -import { Layout } from "../components/Layout" import { MarkdownRemark, Query } from "../generated/graphql" import { SEO } from "../components/SEO" @@ -9,10 +8,10 @@ function AboutPage({ data }: ComponentQuery<{ md: MarkdownRemark }>) { const { md } = data return ( - + - + ) } diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 589c218..d793505 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,19 +1,18 @@ -import React from "react" +import React, { Fragment } from "react" import { Link } from "gatsby" -import { Layout } from "../components/Layout" import { SEO } from "../components/SEO" function IndexPage() { return ( - + Hi people Welcome to your new Gatsby site. Now go build something great. Go to page 2 - + ) } diff --git a/src/pages/resources.tsx b/src/pages/resources.tsx index 36c62be..c171d75 100644 --- a/src/pages/resources.tsx +++ b/src/pages/resources.tsx @@ -1,14 +1,13 @@ -import React from "react" +import React, { Fragment } from "react" -import { ResourcesLayout } from "../components/ResourcesLayout" import { SEO } from "../components/SEO" function ResourcesPage() { return ( - + the resources - + ) } diff --git a/src/pages/rules.tsx b/src/pages/rules.tsx index 7ab8758..d0ddfe2 100644 --- a/src/pages/rules.tsx +++ b/src/pages/rules.tsx @@ -1,7 +1,6 @@ -import React from "react" +import React, { Fragment } from "react" import { graphql } from "gatsby" import { Markdown } from "../components/Markdown" -import { Layout } from "../components/Layout" import { MarkdownRemark, Query } from "../generated/graphql" import { SEO } from "../components/SEO" @@ -9,10 +8,10 @@ function RulesPage({ data }: ComponentQuery<{ md: MarkdownRemark }>) { const { md } = data return ( - + - + ) } diff --git a/src/templates/languagePost.tsx b/src/templates/languagePost.tsx index 8d3b15e..c808d59 100644 --- a/src/templates/languagePost.tsx +++ b/src/templates/languagePost.tsx @@ -1,8 +1,7 @@ -import React from "react" +import React, { Fragment } from "react" import { graphql } from "gatsby" import { Markdown } from "../components/Markdown" import { SEO } from "../components/SEO" -import { ResourcesLayout } from "../components/ResourcesLayout" import { ResourceHeader } from "../components/ResourceHeader" // @todo maybe find alternative type for data @@ -10,7 +9,7 @@ function LanguagePost({ data }: any) { const { html, fields, frontmatter, timeToRead } = data.file.post console.log(data) return ( - + - + ) }
You just hit a route that doesn't exist... the sadness.
Welcome to your new Gatsby site.
Now go build something great.