Skip to content

Commit

Permalink
chore: rename getPath to getParams that will be used to populate swif…
Browse files Browse the repository at this point in the history
…t params
jerelmiller committed Aug 13, 2020

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 27c1481 commit 7a13ad7
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion gatsby-config.js
Original file line number Diff line number Diff line change
@@ -48,7 +48,9 @@ module.exports = {
file: `${__dirname}/src/data/related-pages.json`,
engineKey: 'Ad9HfGjDw4GRkcmJjUut',
pageLimit: 5,
getPath: ({ node }) => node.frontmatter.path,
getParams: ({ node }) => ({
path: node.frontmatter.path,
}),
filterNode: ({ node }) =>
node.internal.type === 'Mdx' &&
node.frontmatter.template === 'GuideTemplate',
16 changes: 12 additions & 4 deletions plugins/gatsby-source-swiftype/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ exports.onPreBootstrap = ({ reporter }, pluginOptions) => {
exports.onCreateNode = async ({ node, getNodesByType }, pluginOptions) => {
const {
filterNode = () => false,
getPath,
getParams,
pageLimit,
engineKey,
} = pluginOptions;
@@ -32,15 +32,23 @@ exports.onCreateNode = async ({ node, getNodesByType }, pluginOptions) => {

const [{ siteMetadata }] = getNodesByType('Site');
const { siteUrl } = siteMetadata;
const pathname = getPath({ node });
const { path: pathname, filters = {}, ...params } = getParams({ node });
const { page: pageFilters = {} } = filters;
const url = new URL(pathname, siteUrl);

const params = {
const allParams = {
...params,
engine_key: engineKey,
per_page: pageLimit,
filters: {
...filters,
page: {
url: [`!${appendTrailingSlash(url)}`, `!${stripTrailingSlash(url)}`],
...pageFilters,
url: [
`!${appendTrailingSlash(url)}`,
`!${stripTrailingSlash(url)}`,
...(pageFilters.url || []),
],
},
},
};

0 comments on commit 7a13ad7

Please sign in to comment.