-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Rework the search scripts and layouts to make it closer to docsy #49724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework the search scripts and layouts to make it closer to docsy #49724
Conversation
✅ Pull request preview available for checkingBuilt without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
Suggest opening an upstream issue about the possibility. |
google/docsy#2194 has been created. I will also note the same in the comments to ensure we don't forget to incorporate it if Docsy takes in the change. |
c689333 to
746220f
Compare
746220f to
74e17b6
Compare
|
Could we adopt google/docsy#1512 anyway, and use that behind the |
a56b84d to
73afeb3
Compare
3262264 to
fe4044c
Compare
@sftim I have implemented something close to that PR, the only difference being that instead of a website/layouts/_default/search.html Line 40 in 3c9c69a
I have also mentioned this alternative in the mentioned PR in docsy. |
|
(SGTM) |
|
This PR is ready for review. See the description for the details of the changes. I have refrained from touching any stylistic changes as they might complicate the PR. I will be doing those in a separate PR. |
694a6f3 to
5585f5b
Compare
sftim
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, https://deploy-preview-49724--kubernetes-io-main-staging.netlify.app/search/ and https://deploy-preview-49724--kubernetes-io-main-staging.netlify.app/search/?q=example don't look right to me (I see a blank white viewport)
Once those are working, great!
6ea4700 to
64a33e0
Compare
|
/lgtm @SayakMukhopadhyay I suggest you squash this to 1 commit, keeping the same merge base (if you keep the same final tree, the LGTM stays put). |
|
LGTM label has been added. Git tree hash: 96bf1a504f5094ded898e0f805b2291e04cf83b9
|
70d0407 to
1ab8cb3
Compare
Nice, I didn't know this. |
1ab8cb3 to
066f90b
Compare
|
Great job; LGTM, too! I checked how it works/renders in two browsers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The K8s website isn't using any of the Docsy search functionality, right (i.e., you're not using GSE, nor Algolia, nor offline search)? If so, a simpler solution to what is proposed here is to just override layouts/partials/search-input.html (and assets/js/search.js) IMHO.
There is enough essential complexity in this website, we should strive to keep the design as simple as possible IMHO.
See inline comment for suggested code streamlining.
Edit
Oh, GCSE isn't being used here! I was confusing K8s with work on other sites were GCSE has been dropped (and was sure that that was the case for the K8s website).
Anyhow, my comment about simply overriding the two Docsy files seems to stand. I'm not sure what you gain by keeping the other Docsy code.
If you do override, and aren't sharing / reusing any of the code, what I've done in other projects is add a comment to the start of the file, something like this: https://github.com/open-telemetry/opentelemetry.io/blob/5b4881e6fc831d634ac635e3a70d916cafc17a31/assets/scss/_variables_project.scss#L1:
/* Docsy-delta full file override: we're not tracking changes to the Docsy file of the same name. */
066f90b to
e222a65
Compare
I have found that while migrating, having chunks of the Docsy code gives a good idea of how the custom code fits. For eg. when working with This is especially true when Docsy introduces an enhancement or feature or removes a bug that we are implementing in the custom code. If we remove all Docsy code, even if they won't be executed either way, finding out if a piece of code is necessary after an upgrade becomes difficult. Hence, I am trying to keep the overridden layouts as close to the Docsy layouts as possible, at least until we reach Docsy latest. Once that happens, I plan to add proper contribution documentation and comments on each override so that future upgrades can be simpler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR reworks the search functionality to align it more closely with Docsy by consolidating and updating search scripts and layouts. Key changes include:
- Consolidation of search functionality into a new file (assets/js/custom-search.js) to simplify modifications.
- Removal of deprecated search scripts and updates in the Hugo configuration (hugo.toml) to enable the new custom search.
- Updates to the search UI layout to adopt Docsy’s styling and behavior.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| assets/js/custom-search.js | New consolidated search script with updated logic and UI behavior |
| hugo.toml | Updated configuration parameter to enable custom search |
| static/js/search.js | Removed deprecated search script |
| assets/js/search.js | Removed deprecated search script |
e222a65 to
87f1c51
Compare
feat: implement custom partial in search--input.html
chore: add some comments on how things can be refactored later
feat: bring the search.html closer to docsy by only including the search-input partial and using the other things from baseof.html
fix: first line comments need to be in the {{/* */}} block, see gohugoio/hugo#7243
Apply suggestions from code review
fix: apply review suggestions
fix: search bar should be removed in page find results and should be present in the sidebar
Co-authored-by: Tim Bannister <[email protected]>
87f1c51 to
8af9731
Compare
dipesh-rawat
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
|
LGTM label has been added. Git tree hash: 844c36105c3bd865e0d1eefe3d5e6fca1115df42
|
|
Wonderful work! |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: reylejano The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
BTW, watch out for cases where that element with a fixed |
This is a small change towards getting the search functionality closer to Docsy. Its related to #47975 but takes a different approach to the same end. The changes made are as follows:
static/js/search.jsandassets/js/search.jsmoved toassets/js/custom-search.js. This helps with modification and prevents the need to overridesearch,jsfromdocsy/assets/js. The file is also namedcustom-search.jsin the same vein as Docsy hasoffline-search.js. This helps in indicating that their functionality are similar. Also updated all variable declarations to useletorconstand all equality conditions to use===.custom-search.jsis incorporatedlayouts/partials/scripts.htmlDocsy add all search scripts like theoffline-search.jsin this file. This addition is also done inside a.Site.Params.customSearchguard in the same vein that Docsy uses.Site.Params.offlineSearchguard.As an aside, I was thinking of seeing if a "custom search" feature could be added in Docsy which would mean that we would just need to add a script and be done with any custom search functionality.
/static/js/search.jsis removed fromlayouts/_default/search.htmlsearch-input.htmltosearch-input-custom.html. This utilises an unmerged upstream PR's basic idea. Also updatessearch-input.htmlitself by copying the rest of the code from Docsy to keep things as 1:1 aligned as possible.search.htmlhas been updated to bring it as close to Docsy as possible. It replaces the majority of the body code including the search bar. The search bar now uses the same CSS styling as the search bar in the homepage and has been taken from the related shortcode. As an aside, we should see if we can templatize the search bar in the home page instead of putting it in every language's homepage. The whole page is also made a definition of themainblock so that it can utilise thebaseof.htmllayout.idinstead of a CSSclassthat could be used elsewhere.The only visual changes I see are (left PR, right live)

I also plan to rework
search-input.htmland associated scss files but probably in a different PR.Helps with #41171