travis-r6s / gridsome-plugin-flexsearch

Add lightning fast search to Gridsome with FlexSearch
24 stars 7 forks source link

Image src is wrong #47

Closed backurdi closed 3 years ago

backurdi commented 4 years ago

I have built an app using forestry, I use the @gridsome/source-filesystem to get the data. It works fine when I just fetch the data using graphql. But when I get the data using gridsome-plugin-flexsearch then the src is wrong, it returns the src on my local machine. I think it has something to do with the src of the data.

Expected data (As returned when just fetching data with graphql) /assets/static/uploads/content.svg?width=879&fit=cover&key=035634c

Returned data (From gridsome-plugin-flexsearch) /Users/bachirkurdi/Documents/cyNy/uploads/content.svg

My graphql config for the data and search { use: "@gridsome/source-filesystem", options: { path: "blog/**/*.md", typeName: "BlogPost", resolveAbsolutePaths: true, remark: { externalLinksTarget: "_blank", externalLinksRel: ["nofollow", "noopener", "noreferrer"], }, }, }, { use: "@gridsome/source-filesystem", options: { path: "employees/**/*.md", typeName: "Employees", resolveAbsolutePaths: true, remark: { externalLinksTarget: "_blank", externalLinksRel: ["nofollow", "noopener", "noreferrer"], }, }, }, { use: "gridsome-plugin-flexsearch", options: { searchFields: ["title"], collections: [ { typeName: "BlogPost", fields: ["id", "path", "title", "excerpt", "image"], }, ], }, },

The searchResult function: searchResults() { const searchTerm = this.searchTerm; if ( searchTerm.length > 2 && this.$search.search({ query: searchTerm, limit: 5 }).length > 0 ) { return this.$search.search({ query: searchTerm, limit: 5 }); } else { return this.$page.posts.edges; } }

Thank you a lot in advance 😄

travis-r6s commented 4 years ago

@backurdi That's strange, but thanks for reporting it - i'll take a look at this.

backurdi commented 4 years ago

Thank you @thetre97, looking forward to hear what you find 😄

travis-r6s commented 3 years ago

Sorry for not replying earlier, but this is to do with Gridsome's asset pipeline, which runs after this plugin gets data from the store - so it will only get the relative path to the image, never the transformed image.

Unfortunately, I'm not sure what I can do here.

VeliV commented 3 years ago

Would it be possible to run the the plugin after the build is done?

travis-r6s commented 3 years ago

I do intend to update this plugin when I get a bit of time, to use the internal graphql function to query data, instead of getting it from the store. That way, it will get the correct image data, and resolve any relations, use custom resolvers etc as well - which will help solve #56, and #51

VeliV commented 3 years ago

That's be great :) I have a hobby site (https://panzercraft.com/) that relies heavily on images. Been playign around with adding search there, but as the site is so image heavy, not being able to get the images show up when searching is a show stopper.

travis-r6s commented 3 years ago

@backurdi @VeliV I have just made some changes to this plugin on the graphql branch - if you have the time, would you be able to test this, and check it works for you?