Skip to content

Commit

Permalink
refactor: slightly more efficient means of getting related resources …
Browse files Browse the repository at this point in the history
…for a node
  • Loading branch information
jerelmiller committed Aug 13, 2020
1 parent 753cd77 commit 5c8cc98
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions plugins/gatsby-source-swiftype/src/getRelatedResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ module.exports = async ({ node, siteUrl }, pluginOptions) => {
getPath,
} = pluginOptions;

const data = JSON.parse(fs.readFileSync(file));
const params = getParams({ node });
const pathname = getPath({ node });

if (enabled) {
return search(siteUrl + pathname, params, { engineKey, pageLimit });
return search(siteUrl + pathname, getParams({ node }), {
engineKey,
pageLimit,
});
}

const data = JSON.parse(fs.readFileSync(file));

return data[pathname] || [];
};

0 comments on commit 5c8cc98

Please sign in to comment.