Split search_index.js into Liquid data and pure JS#638
Closed
xr843 wants to merge 2 commits intobuddhist-uni:mainfrom
Closed
Split search_index.js into Liquid data and pure JS#638xr843 wants to merge 2 commits intobuddhist-uni:mainfrom
xr843 wants to merge 2 commits intobuddhist-uni:mainfrom
Conversation
Extract unaccent, OBU_STEMMER, buildSearchIndex, and initSearchWorker into search_worker_init.js so unit tests can import the JS directly without needing to parse Liquid/Jekyll templates. search_index.js now only contains the Liquid template data (store variable) and a call to initSearchWorker(store).
✅ Deploy Preview for obu ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Collaborator
|
The little bit of glue code left in |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Splits
search_index.jsinto two files:search_worker_init.js— pure JavaScript logic (unaccent,OBU_STEMMER,buildSearchIndex,initSearchWorker)search_index.js— keeps the Liquid/Jekyll template data (storevariable) and callsinitSearchWorker(store)at the endWhy
As discussed in #636, the current
search_index.jsmixes Liquid template syntax with JavaScript functions, which means unit tests can't import the JS logic directly — they'd need to parse Liquid first. By extracting the pure JS into a separate file, tests can importsearch_worker_init.js(andsearch_functions.js) without needing a Jekyll build.Changes
assets/js/search_worker_init.js: Containsunaccent,OBU_STEMMER,buildSearchIndex(store), andinitSearchWorker(store)— all the pure JS that was previously insearch_index.js.assets/js/search_index.js: Now only has the Liquid front matter,importScriptscalls (including the new file), thestoredata template, andinitSearchWorker(store).scripts/minify.bash: Also minifiessearch_worker_init.jsduring the build.Backward compatibility
/assets/js/search_index.js) is unchanged fromsearch.js's perspectiveimportScriptsloading order preserves the same dependency chain