Skip to content

Commit

Permalink
gatsby create page fix;
Browse files Browse the repository at this point in the history
this fixes unintended rendering of certain pages in the dir:
static-site/src/pages. Gatsby auto-creates pages
from js,jsx pages in this directory. This issue was raised here:
nextstrain#299 (comment)
In some cases, we want to call createPage in static-site/gatsby-node.js
to create multiple other pages under a certain URL, so this
puts those in static-site/src/sections as a workaround to avoid
rendering of pages at a URL matching the exact name of the
file (such as nextstrain.org/influenza-page). These
files are intended to help render pages matching
a specified URL (such as nextstrain.org/influenza/*).
  • Loading branch information
eharkins committed Apr 16, 2021
1 parent 4d1cfc1 commit 2f2f955
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions static-site/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,14 @@ exports.createPages = ({graphql, actions}) => {
});

// Create page detailing all things SARS-CoV-2
// Note that this is in src/sections, not src/pages. This is because we don't
// want to render anything at the exact url of nextstrain.org/sars-cov-2-page
// and Gatsby auto-creates such pages from any jsx file in the src/pages directory.
// Many of the pages created here are in src/sections for the same reason.
createPage({
path: "/sars-cov-2",
matchPath: "/sars-cov-2/*",
component: path.resolve("src/pages/sars-cov-2-page.jsx")
component: path.resolve("src/sections/sars-cov-2-page.jsx")
});

/* NOTE: we are using "influenza" URLs for dev purposes only. This will be switched to "flu"
Expand All @@ -209,20 +213,20 @@ exports.createPages = ({graphql, actions}) => {
createPage({
path: "/influenza",
matchPath: "/influenza/*",
component: path.resolve("src/pages/influenza-page.jsx")
component: path.resolve("src/sections/influenza-page.jsx")
});

// search pages
createPage({
path: `/search`,
component: path.resolve("src/pages/sequence-search-list.jsx"),
component: path.resolve("src/sections/sequence-search-list.jsx"),
context: {searchPages}
});
searchPages.forEach(({urlName, displayName, jsonUrl}) => {
console.log(`created page at /search/${urlName}`);
createPage({
path: `/search/${urlName}`,
component: path.resolve("src/pages/sequence-search.jsx"),
component: path.resolve("src/sections/sequence-search.jsx"),
context: {urlName, displayName, jsonUrl}
});
});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 2f2f955

Please sign in to comment.