I would like to create a separate search page where the user enters a keyword on any page and then jumps to a page like /search/
or /search.html
to display the results. The place where the user’s search behavior occurs may not be the search page, so I’m currently unsure how to get the search results and pass the data. I can think of a couple of solutions, but they all have problems that I can’t solve:
-
Get the URL query parameter as a keyword, search using
Fuse.js
, and then pass the results via input to the template. Since the template generates the results before the Javascript is executed, this solution is clearly impractical I guess. -
Generate results with
Fuse.js
when the user clicks the search button and sets them into.Site.Scratch
, and the next search template gets the data and generates the corresponding results. This seems to work, but I’m not sure how to put the result data into.Site.Scratch
after the Javascript works it out. -
Forget about the
Fuse.js
search and create a search myself in the search page template using the JSON data format used byFuse.js
and display the results. The problem with this is that I haven’t found any way that allows me to get the URL query parameter for the current page (violate Hugo’s goal as a static site generation tool?), and as a result, I can’t do any searches either.
Will any of the above solutions work if I know more about Hugo? Or is there any workaround that will do the job?