Skip to content

Commit

Permalink
refactor: move path back to getPath function
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Aug 13, 2020
1 parent 8052577 commit 65b83c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ module.exports = {
file: `${__dirname}/src/data/related-pages.json`,
engineKey: 'Ad9HfGjDw4GRkcmJjUut',
pageLimit: 5,
getPath: ({ node }) => node.frontmatter.path,
getParams: ({ node }) => {
const { tags, title } = node.frontmatter;

return {
path: node.frontmatter.path,
q: tags ? tags.map(quote).join(' OR ') : title,
search_fields: {
page: ['tags^10', 'body^5', 'title^1.5', '*'],
Expand Down
17 changes: 12 additions & 5 deletions plugins/gatsby-source-swiftype/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exports.onCreateNode = async ({ node, getNodesByType }, pluginOptions) => {
const {
filterNode = () => false,
getParams,
getPath,
pageLimit,
engineKey,
} = pluginOptions;
Expand All @@ -15,18 +16,24 @@ exports.onCreateNode = async ({ node, getNodesByType }, pluginOptions) => {
return;
}

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

const params = getParams({ node });
const pathname = getPath({ node });
const url = new URL(pathname, siteUrl);

const { page: pageFilters = {} } = params.filters || {};

const allParams = {
...params,
engine_key: engineKey,
per_page: pageLimit,
filters: {
...filters,
...params.filters,
page: {
...pageFilters,
url: [
Expand Down

0 comments on commit 65b83c6

Please sign in to comment.