-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
🐈 [new-site-search] Add custom site search using Lunr.js. #203
Conversation
With no real search content yet.
* master: (25 commits) Upgrade deps. compile cleanup add subtitle supplement icon path above icon preview section review cleanup display icon path, edit path style remove tooltip code, simplify icon styles Normalize iconsPath Remove filename from icon path. compile Cleanup fonts/scale docs & previews if we choose filepath on top, keep this commit filepath - version 2 - above filename Cleanup font docs force tooltips to break stylelint adding tooltip pattern styles, edit icon layout Add example to njk examples doc Add use-cases to relevant config ...
* master: Style branding update changelog Add Herman favicon. Add attribution/links to nav footer (needs styling).
@mirisuzanne Take a look at the results here... ready for styling if the functionality looks okay. We have more control over the functionality and markup here, so let me know if you want changes. |
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.
Looks great to me!
gulpfile.js
Outdated
@@ -421,3 +423,10 @@ gulp.task('imagemin', () => { | |||
}); | |||
|
|||
gulp.task('minify', ['jsmin', 'svgmin', 'imagemin']); | |||
|
|||
gulp.task('precompile-templates', () => |
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.
This had some issues on occasion – I had to restart my server quite often while working.
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.
Hm, what sort of errors?
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.
Only time I've been able to reproduce errors is when I make multiple quick changes in a row, before compilation has time to complete.
Right now I'm showing 15 words before and after every search result match, but showing all result matches. When you search for a common word (e.g. |
Okay, I think this is to a point where I'm okay reviewing/merging it. There's still one small bug in the JS search tool that I'm waiting on a fix for (see olivernn/lunr.js#320), but I expect that to come in shortly. This branch also inspired me to add two new issues (#204, which can probably wait for after 1.0, and #205, which should probably happen ASAP).
|
Sidenote: I added another branch, |
if (typeof window.deparam !== 'undefined') { | ||
params = window.deparam(window.location.search.substr(1)); | ||
} | ||
return params; |
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.
Do you want to get URL params if deparam
is undefined
?
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.
¯\_(ツ)_/¯
It's kind of a theoretical question... this fn should never be called currently in cases where $.deparam isn't defined. (There are various pieces of JS that are only used by the search-results page, so only loaded on that page.)
} | ||
// Add search result template to set of results | ||
matches = matches.add(el); | ||
} |
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.
It's not urgent, but if showResults
could be decomposed into well-named things, that'd probably help. It's a bit hard to follow.
showResults(results, val); | ||
}; | ||
|
||
Herman.getSearchData = function getSearchData() { |
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.
Why isn't this an anonymous function assigned to Herman.getSearchData
?
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.
Good call; no reason.
// Only fetch search data if on search results page with query term | ||
if (params && params.q && hasLunr && hasNunjucks) { | ||
const request = new XMLHttpRequest(); | ||
request.open('GET', '/search-data.json', true); |
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.
Can we not use fetch
here? Is this a backwards-compatibility thing?
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.
We're currently using the slim
build of jQuery, which does not include $.ajax
&c. It didn't seem worth adding for simple $.getJSON
call, so I did it the old-school way.
@@ -1,5 +1,6 @@ | |||
'use strict'; | |||
|
|||
const $ = require('cheerio'); |
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.
TIL about cheerio!
* master: Bump version to 1.0.0-rc.1 Remove old sourcemaps
Another attempt at fixing #28.