Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds gatsby-source-swiftype to theme #185

Merged
merged 2 commits into from
Jan 4, 2021
Merged

Conversation

zstix
Copy link
Contributor

@zstix zstix commented Dec 30, 2020

Description

This PR copies the gatsby-source-swiftype plugin that we created for the developer site to the theme and exposes an optional swiftype option that can be passed to the theme by any site using the theme. This will allow us to use this logic for both the developer site and the new docs site.

Reviewer Notes

I'm not 100% that we can have local plugins in a theme like this. Once this is merged and released, I'll work on swapping the developer site over to use the plugin via the theme (I'll link that PR here for transparency).

Related Issue(s)

createNodeId,
});

createParentChildLink({ parent: node, child: child });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that in order to get the related resources we'll query for the children of the node?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is just copying what we had before. I didn't write the original code, but I believe we need to establish a relationship so that we can query related content for a specific page.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This creates a childrenRelatedPages (if I remember correctly) field on the parent so that you can query for it for the current page.

pluginOptions
) => {
const { createNode, createParentChildLink } = actions;
const { filterNode = () => false, getPath } = pluginOptions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this filterNode function do? how does this inline function work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is being used as a default value in case filterNode isn't specified. If we use this plugin without filterNode, it will just be a function that always returns false.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason that filterNode returns false rather than true is that we want to avoid executing searches on Swiftype for pages that aren't explicitly set as needing related resources. This helps us avoid the cost of executing a query against Swiftype for pages that we don't use this for.

Copy link
Contributor

@caylahamann caylahamann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this all looks good to me! just two clarifying questions, and the one suggestion that I have is that we change the name of the plugin to gatsby-source-related-resources? It just makes sense to me since we are sourcing the related resources, but feel free to challenge me on this!

@zstix
Copy link
Contributor Author

zstix commented Jan 4, 2021

@caylahamann Let me know if you have any additional questions on this PR.

cc: @jerelmiller (this PR brings the work you did on the developer site into the theme so that we have the option of getting related content on other sites)

@jerelmiller
Copy link
Contributor

TODO: Write docs

@zstix zstix merged commit b297ac6 into develop Jan 4, 2021
@zstix zstix deleted the zstix/source-swiftype branch January 4, 2021 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants