{"action":"created","issue":{"url":"https://api.github.com/repos/humanseelabs/gatsby-plugin-lunr/issues/8","repository_url":"https://api.github.com/repos/humanseelabs/gatsby-plugin-lunr","labels_url":"https://api.github.com/repos/humanseelabs/gatsby-plugin-lunr/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/humanseelabs/gatsby-plugin-lunr/issues/8/comments","events_url":"https://api.github.com/repos/humanseelabs/gatsby-plugin-lunr/issues/8/events","html_url":"https://github.com/humanseelabs/gatsby-plugin-lunr/issues/8","id":374029939,"node_id":"MDU6SXNzdWUzNzQwMjk5Mzk=","number":8,"title":"Possible to use with gatsby-remark-images?","user":{"login":"kmorf","id":42035849,"node_id":"MDQ6VXNlcjQyMDM1ODQ5","avatar_url":"https://avatars3.githubusercontent.com/u/42035849?v=4","gravatar_id":"","url":"https://api.github.com/users/kmorf","html_url":"https://github.com/kmorf","followers_url":"https://api.github.com/users/kmorf/followers","following_url":"https://api.github.com/users/kmorf/following{/other_user}","gists_url":"https://api.github.com/users/kmorf/gists{/gist_id}","starred_url":"https://api.github.com/users/kmorf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kmorf/subscriptions","organizations_url":"https://api.github.com/users/kmorf/orgs","repos_url":"https://api.github.com/users/kmorf/repos","events_url":"https://api.github.com/users/kmorf/events{/privacy}","received_events_url":"https://api.github.com/users/kmorf/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-10-25T16:25:18Z","updated_at":"2018-12-14T11:44:04Z","closed_at":"2018-11-06T14:06:07Z","author_association":"NONE","body":"Is it possible to use with gatsby-remark-images?"},"comment":{"url":"https://api.github.com/repos/humanseelabs/gatsby-plugin-lunr/issues/comments/447301250","html_url":"https://github.com/humanseelabs/gatsby-plugin-lunr/issues/8#issuecomment-447301250","issue_url":"https://api.github.com/repos/humanseelabs/gatsby-plugin-lunr/issues/8","id":447301250,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NzMwMTI1MA==","user":{"login":"kmorf","id":42035849,"node_id":"MDQ6VXNlcjQyMDM1ODQ5","avatar_url":"https://avatars3.githubusercontent.com/u/42035849?v=4","gravatar_id":"","url":"https://api.github.com/users/kmorf","html_url":"https://github.com/kmorf","followers_url":"https://api.github.com/users/kmorf/followers","following_url":"https://api.github.com/users/kmorf/following{/other_user}","gists_url":"https://api.github.com/users/kmorf/gists{/gist_id}","starred_url":"https://api.github.com/users/kmorf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kmorf/subscriptions","organizations_url":"https://api.github.com/users/kmorf/orgs","repos_url":"https://api.github.com/users/kmorf/repos","events_url":"https://api.github.com/users/kmorf/events{/privacy}","received_events_url":"https://api.github.com/users/kmorf/received_events","type":"User","site_admin":false},"created_at":"2018-12-14T11:44:04Z","updated_at":"2018-12-14T11:44:04Z","author_association":"NONE","body":"@LekoArts I used parts of the plugin to build the index myself in my `gatsby-node.js`, but needs to be optimized for scaling. Something like the below. You can see it in action in https://gyft.shop/\r\n\r\n<details>\r\n <summary>gatsby-node.js</summary>\r\n\r\n```js\r\nconst path = require('path')\r\nconst fs = require('fs')\r\nconst lunr = require('lunr')\r\nconst { createFilePath } = require('gatsby-source-filesystem')\r\n\r\nexports.createPages = ({ actions, graphql }) => {\r\n  const { createPage } = actions\r\n  const fullIndex = {}\r\n\r\n  return new Promise((resolve, reject) => {\r\n    const giftPage = path.resolve('./src/templates/gift.js')\r\n    resolve(\r\n      graphql(\r\n        `\r\n          query Name {\r\n            giftData: allMarkdownRemark(\r\n              filter: { frontmatter: { templateKey: { eq: \"gift\" } } }\r\n            ) {\r\n              edges {\r\n                node {\r\n                  id\r\n                  fields {\r\n                    slug\r\n                  }\r\n                  frontmatter {\r\n                    title\r\n                    tags\r\n                    price\r\n                    image {\r\n                      childImageSharp {\r\n                        fluid(maxWidth: 400, maxHeight: 265) {\r\n                          src\r\n                        }\r\n                      }\r\n                    }\r\n                  }\r\n                }\r\n              }\r\n            }\r\n          }\r\n        `\r\n      ).then(result => {\r\n        if (result.errors) {\r\n          console.log(result.errors)\r\n          reject(result.errors)\r\n        }\r\n\r\n        const gifts = result.data.giftData.edges\r\n\r\n        const store = {}\r\n        const index = lunr(function() {\r\n          this.ref('id')\r\n          this.field('title')\r\n          this.field('slug')\r\n          this.field('price')\r\n          this.field('image')\r\n          this.field('tags')\r\n\r\n          gifts.forEach(edge => {\r\n            const id = edge.node.id\r\n            const doc = {\r\n              id: id,\r\n              title: edge.node.frontmatter.title,\r\n              slug: edge.node.fields.slug,\r\n              price: edge.node.frontmatter.price,\r\n              image: edge.node.frontmatter.image.childImageSharp.fluid.src,\r\n              tags: edge.node.frontmatter.tags,\r\n            }\r\n            this.add(doc)\r\n            store[id] = doc\r\n          })\r\n        })\r\n        fullIndex['en'] = { index, store }\r\n        fs.writeFileSync(`public/search_index.json`, JSON.stringify(fullIndex))\r\n\r\n        // Gifts pages\r\n        gifts.forEach((edge, index) => {\r\n          const id = edge.node.id\r\n          const previous =\r\n            index === gifts.length - 1 ? null : gifts[index + 1].node\r\n          const next = index === 0 ? null : gifts[index - 1].node\r\n\r\n          createPage({\r\n            path: edge.node.fields.slug,\r\n            tags: edge.node.frontmatter.tags,\r\n            component: giftPage,\r\n            context: {\r\n              id,\r\n              slug: edge.node.fields.slug,\r\n              previous,\r\n              next,\r\n            },\r\n          })\r\n        })\r\n      })\r\n    )\r\n  })\r\n}\r\n```\r\n</details>\r\n\r\n<details>\r\n <summary>gatsby-browser.js</summary>\r\n\r\n```js\r\nconst lunr = require('lunr')\r\n\r\nexports.onClientEntry = () => {\r\n  fetch(`${__PATH_PREFIX__}/search_index.json`)\r\n    .then(function(response) {\r\n      return response.json()\r\n    })\r\n    .then(function(fullIndex) {\r\n      window.__LUNR__ = Object.keys(fullIndex).reduce(\r\n        (prev, key) => ({\r\n          ...prev,\r\n          [key]: {\r\n            index: lunr.Index.load(fullIndex[key].index),\r\n            store: fullIndex[key].store,\r\n          },\r\n        }),\r\n        {}\r\n      )\r\n    })\r\n    .catch(e => console.log('Failed fetch search index'))\r\n}\r\n\r\n```\r\n</details>"}}
{"actor":{"display_login":"kmorf"}}