Skip to content

Search functionality#11

Open
C-Loftus wants to merge 3 commits intoodilia-app:mainfrom
C-Loftus:search_functionality
Open

Search functionality#11
C-Loftus wants to merge 3 commits intoodilia-app:mainfrom
C-Loftus:search_functionality

Conversation

@C-Loftus
Copy link
Copy Markdown
Contributor

This PR adds search functionality. It does this by statically generating an index JSON file when hugo is ran. The search bar then can use a regex to search through it.

It is a naive search algorithm but it is better than nothing and helps to search for keywords. I adapted the code from https://decovar.dev/blog/2020/01/05/hugo-search/ I put the source at the top of the js file

I am a bit stuck on getting the accessibility working. Orca at least reads out the last search result. Not sure if that is sufficient or what the best practices are.

Also made a minor change in the date for one blog post that incorrectly formatted and prevented builds. Also added a gitignore

@C-Loftus
Copy link
Copy Markdown
Contributor Author

One thing I will say is that while working on this it did sorta strike me that this style of search functionality might be better handled with a dedicated npm package since handling a lot of the edge cases of searching is non-trivial.

Depends what your future long term goals are with this site; just trying to make sure that things are easy to iterate on/ maintain in the future .

@TTWNO
Copy link
Copy Markdown
Member

TTWNO commented Jan 26, 2025

A dependency on an NPM package would not be ideal. This is meant to basically be a static site.

Is it possible to index on a new page? Personally pop-up search is totally overrated and I don't mind being directed to a new page for results.

@C-Loftus
Copy link
Copy Markdown
Contributor Author

Sure, whatever you prefer. Just wanted to call that out as an option.

I tried implementing the result outputs on a separate page, which I think is a good and reasonable idea, but I couldn't get it working. I don't know how to get the hugo template to render /search. Created a separate PR in #12 which anyone can feel free to edit or take code from.

@TTWNO
Copy link
Copy Markdown
Member

TTWNO commented Jan 26, 2025

Yeah Hugo is a PITA sometimes. Not as untuitive as other SSGs. Will take a look this evening.

@C-Loftus
Copy link
Copy Markdown
Contributor Author

Sounds good. No rush on this at all. Just trying to make something helpful for others.

Wrote up a little description of the challenge in #12 i presume it is something simple since im not too familiar with hugo

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.

2 participants