diff --git a/gatsby-node.js b/gatsby-node.js index 255557c589db2b..8e173faf84c789 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -12,6 +12,16 @@ const { paginate } = require("gatsby-awesome-pagination"); const { createFilePath } = require("gatsby-source-filesystem"); const RelatedPostsFactory = require("./src/components/Related-Posts/relatedPostsFactory"); const config = require("./gatsby-config"); +const { toEditUrl } = require("./src/utils/edit-link.js"); + +exports.onCreatePage = ({ page }) => { + const editUrl = toEditUrl(page.component, __dirname); + if (editUrl) { + page.context = { ...page.context, editUrl }; + } + return page; +}; + const { getExcludedCollections, isFullSiteBuild, @@ -61,7 +71,11 @@ exports.createPages = async ({ actions, graphql, reporter }) => { `Duplicate page path "${page.path}" from ${previous} and ${page.component}. Give one of them a unique title or permalink.`, ); } - return actions.createPage(page); + + const editUrl = toEditUrl(page.component, __dirname); + return actions.createPage( + editUrl ? { ...page, context: { ...page.context, editUrl } } : page, + ); }; const envCreatePage = (props) => { diff --git a/package.json b/package.json index 3989cdfcedee5d..caf0d09da54bf8 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "lint": "eslint --fix .", "checklint": "eslint .", "check:contributing-versions": "node .github/scripts/check-contributing-versions.cjs", - "test:unit": "node --test src/utils/build-collections.test.js src/utils/page-path-guard.test.js src/utils/resources-url.test.js", + "test:unit": "node --test src/utils/build-collections.test.js src/utils/page-path-guard.test.js src/utils/edit-link.test.js src/utils/resources-url.test.js", "pretest": "eslint --ignore-path .gitignore .", "deploy": "gatsby build && gh-pages -d public -b master", "noIndex": "gatsby build && echo 'User-agent: *\nDisallow: /' > public/robots.txt", diff --git a/page-wrapper.js b/page-wrapper.js index 34dc1c2d21f9da..869ab799ebf632 100644 --- a/page-wrapper.js +++ b/page-wrapper.js @@ -1,8 +1,8 @@ import React from "react"; import Layout from "./src/components/layout.js"; -export const wrapPageElement = ({ element }) => ( - +export const wrapPageElement = ({ element, props }) => ( + {element} -); \ No newline at end of file +); diff --git a/src/components/layout.js b/src/components/layout.js index b7aa355292edcc..3702d474670af9 100644 --- a/src/components/layout.js +++ b/src/components/layout.js @@ -16,7 +16,7 @@ import Footer from "../sections/General/Footer"; import { GlobalStyle } from "../sections/app.style"; import CookieConsent from "./CookieConsent"; -const Layout = ({ children }) => { +const Layout = ({ children, pageContext }) => { return ( <> @@ -26,13 +26,14 @@ const Layout = ({ children }) => { {children} -