Skip to content

Add a search bar to the documentation site - #236

Open
jiheunha wants to merge 11 commits into
JGCRI:gh-pagesfrom
jiheunha:feature/add-search
Open

Add a search bar to the documentation site#236
jiheunha wants to merge 11 commits into
JGCRI:gh-pagesfrom
jiheunha:feature/add-search

Conversation

@jiheunha

Copy link
Copy Markdown

Hi, thank you for maintaining such thorough documentation for GCAM. It has been a huge help.

One thing I kept running into is that the docs site has no search box, so finding a specific function or explanation usually meant visiting many pages. This PR adds a search bar to make that easier.

Summary

  • Adds a search box to the top of every documentation page.
  • When a user types a query, matching pages appear in a dropdown list with a short preview of the matching text.
  • Pages from older archived versions (vX.Y) are labeled with a version badge and sorted below current docs so they do not get in the way.
  • Clicking a result opens that page, scrolls to the first match.
  • Everything runs in the browser with plain JavaScript, no extra build steps or external libraries needed.
  • The search index rebuilds automatically on every Jekyll build, so no manual updates are needed when new pages or versions are added.

I built this on my fork so you can see how it works: https://jiheunha.github.io/gcam-doc/

Thank you!

Jiheun Ha added 11 commits May 20, 2026 11:54
The official documentation site currently has no search functionality,
making it difficult to find specific content across 43+ pages.

This adds a lightweight, zero-dependency search feature:
- search.json: Jekyll-generated index of all page titles and content
- javascripts/search.js: client-side search with snippet previews
- Search input in the sidebar header with a dropdown results overlay

Works entirely client-side on GitHub Pages — no server or plugins needed.
- Use Jekyll's relative_url filter to compute the search.json path so it
  works regardless of whether baseurl is set in _config.yml
- Move the search box inline with the navigation row, on the right side
- Pre-filter pages with where_exp so the loop only iterates valid entries,
  eliminating the trailing comma that broke JSON parsing
- Add Enter key handler and a Search button next to the input
- Always show overlay during search (loading + error feedback)
- Tighten event handling (closest('.gcam-search-box') for outside-click)
- Defensive: also set overlay.style.display explicitly
- Higher z-index so overlay isn't clipped by surrounding chrome
Temporary — remove before merging.
- Force display/visibility/opacity in inline style
- Add !important on overlay CSS and log rect to find clipping
The site's existing CSS targets every <ul> inside <header> with absolute
positioning and a fixed 38px height (for the Download/View-on-GitHub
button group), which collapsed the search results list to ~3px tall.

This adds specific overrides for the search overlay and result list so it
renders as a normal dropdown. Also polishes the result item design.

Removes temporary console.log debugging.
Result links now carry ?q=<query>; on page load the script walks the
content tree, wraps every occurrence in a <mark>, scrolls the first one
into view, and prefills the search box so the query is editable.

The first match is highlighted in orange and given a subtle outline so
it stands out from the other yellow highlights on the page.
Pages from archived versions (v3.2, v4.2, ...) share titles with the
current docs, so the result list was full of look-alike duplicates. Each
result now carries a small version badge ("current" for the latest docs,
or e.g. "v3.2" for archived pages) so they're easy to tell apart.
Pages from the current docs don't need a badge; they're the default.
Only archived /vX.Y/ pages now carry a version chip like "v3.2".
Pages from the latest docs (no /vX.Y/ in the URL) now sort to the top of
the result list; archived versions follow. Within each group, results
are still ordered by match count.
@jiheunha
jiheunha force-pushed the feature/add-search branch from b2cb673 to bf5c223 Compare May 20, 2026 02:54
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.

1 participant