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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding search with gatsby-image #9435

Closed
krismorf opened this issue Oct 26, 2018 · 1 comment
Closed

Adding search with gatsby-image #9435

krismorf opened this issue Oct 26, 2018 · 1 comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@krismorf
Copy link
Contributor

krismorf commented Oct 26, 2018

Question

What's the best way to implement search functionality on my site while taking advantage of gatsby-transformer-sharp?

I have a card component which is also my search result component馃憞

<Card
  title={node.frontmatter.title}
  image={node.image.childImageSharp.fluid}
  ...
/>

How can I include image.childImageSharp.fluid in my index?

What I tried

  1. Created index with gatsby-plugin-elasticlunr-search: Impossible to query node.frontmatter.image.childImageSharp since it uses onCreateNode which is before the image optimization. This answer suggests creating my index manually but I'm not sure which gatsby API to use.
  2. Created index with gatsby-plugin-lunr: This plugin uses onPostBuild so I figured it can take advantage of that. But it's similar to gatsby-plugin-elasticlunr-search, the plugin queries node.internal.type = MarkdownRemark and looks for entries in the markdown files. In my case node.frontmatter.image = "img/image.jpg".
  3. Tried creating my own index but couldn't. I couldn't find any guides related to this.

At the moment I'm using gatsby-plugin-lunr which returns "img/image.jpg".
Is anyone struggling with the same issue? How can I go from here?

Previous discussions: #6230 #6112 #1075 #9295 #332

@krismorf krismorf added question type: question or discussion Issue discussing or asking a question about Gatsby and removed question labels Oct 26, 2018
@krismorf
Copy link
Contributor Author

krismorf commented Nov 1, 2018

OK, so I managed to build my lunr index using remark images.

If anyone is wondering how I did it:
In my gatsby-node.js I used the same graphql query that creates my pages, to also create my search index and create a json file, similar to what gatsby-plugin-lunr does. After that I added the json file to my gatsby-browser.js, again similar to the plugin above.

@krismorf krismorf closed this as completed Nov 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

2 participants