-
-
Notifications
You must be signed in to change notification settings - Fork 170
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
[WIP] implement-start-of-search #213
base: prod
Are you sure you want to change the base?
Conversation
@kkemple Thanks for doing this! This is so awesome. Are you at a point where you'd like feedback yet? If so, what sorta feedback? (Also I imagine you know this but I find it helpful to include the Deploy preview link: https://deploy-preview-213--selfdefined.netlify.app/) |
Thanks for adding the link! I think biggest piece of feedback I could use is am I doing this the 11ty way? I did some research about how to generate JSON for searching client-side and most examples used this pattern of generating a file from a template you can query from on the client. Could also use a review of the JS code in |
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.
Hey,
Sorry for keeping you waiting for ages.
First off: I think that’s a really cool step that you go here and I would love to see this proceed.
I never heard of lunr before and this a cool tool. But I wonder if it, in the current implementation, is the right tool for our site. I think it really shines if you have loads of data readily available on a page and want to search through this. In our case, we are kind of bending over backwards to achieve this goal, the bending being the ~90 kB JSON that we need to load in the client to have all data available. As a more complex definition adds roughly 3 kB to this, this will get larger by the day.
Now, I also think that parsing our data into this JSON is a pragmatic and good first step into building search functionality, and I also believe that lunr is up for the job.
My proposal, I believe this has been discussed in one of the previous API discussions, is to leverage the created JSON + lunr. But to do so in a server-side function (or serverless function or whatever the current buzzword is). This way, we can have the fast progress this combination enables, without putting the burden on the user and their networks.
By leveraging lunr on our server, we only need a small search wrapper as a client-side script. This makes search network-dependent again, but if the network is flaky, loading a huge JSON blob will probably fail too.
I've moved the search to a serverless function, currently it has a static json file but that won't scale well, once the search page is actually deployed we can query that from the function. Thanks for all the feedback everyone! Still left to do:
|
This is so awesome. Thank you, @kkemple ! I am going to remove the Needs Review label off until you're ready for additional feedback (in my mind, waiting for the new approach to include design is okay, but let me know if you feel differently). |
I've updated the serverless function to use the deployment previews
Not really ready for review yet but always welcome feedback! |
@kkemple I’ll have a look tomorrow and provide some feedback! |
Hey @kkemple – I love this! Thank you so much for building it. I like the presentation of each result; especially that I can see the term and the text snippet in which my search can be found. I know that you're still working on the UI, so I write the following with that in mind:
Now that I am getting some free time again, I would be glad to support your engineering work here or be a soundboard for accessibility – let me know if I can help! |
Thanks for all this awesome feedback @ovlb! I've started implementing these changes, I'll go through in order and address each item! HTML & Page Structure
Scripting
Styles
RemainingThis brings us extremely close to having something we can merge. The last things I can think is making the url in the serverless function an ENV variable so that we can change the url from the deploy preview URL to the production URL. I don't have access to Netlify console so I'm currently unable to do that. Also, it means for search to work properly locally we would need to use the |
Regarding the search form, there is a |
@ovlb I've taken a first pass at adding a table of contents to the search results page. A few things to note:
|
<form method="get" action="/search" class="js-search-form search__form"> | ||
<label for="q" class="sub-headline">Look up a definition</label> | ||
<div class="search__actions"> | ||
<input type="search" class="search__input" name="q" /> |
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.
<input type="search" class="search__input" name="q" /> | |
<input type="search" id="q" class="search__input" name="q" /> |
@kkemple: input:label associations are created with the for
attribute pointing to a unique ID*. Thank you to @colabottles for pointing this out; I missed it!
It's worth noting, the title
attribute is not a good technique for defining the accessible name of a control because browsers and assistive technologies may not actually report the title
to the user. It's better to use aria-label
when we cannot use a real <label>
element, and we do have a real label here!
*paging @ovlb in case he has some thoughts on a safer unique ID than q
:)
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.
@dengeist aria-label
is the better method, I agree. This is one case that ARIA should be used. Thanks for pointing that out!
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.
Re ID: might be safer to namespace it into search-query
or alike. Currently it’s the only input we have, but it will probably not stay this way.
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.
does the input name need to change if we change the ID?
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.
Not necessarily. The name
is what’s used in FormData, document.forms.formName
, or — if old school — when handling a POST
request coming from a form action on the server. Whereas the ID is used in HTML to link label and input. I wrote an article where this is explained in more detail: Association of labels and inputs.
I’ve pushed the style updates. Re toc: It might make sense to move the table of content between the number of results and the actual result list to give it more space to breathe. And it’s also in the logical page flow there.
But the search page does, or? As such we should still hide search completely for non-JS contexts. |
@ovlb are you saying we should hide search for users that have JS disabled? We can definitely do that. We'll need to add messaging to the search results page as well as those could be shared via URL. |
Yip. It’s not the best experience if they are able to submit the form but can’t see the results, imho.
Good point. |
Yeah, totally agree! I'll take this on next time I dive in to work on it! |
@kkemple : I'm doing my sweep through of issues right now, so absolutely no pressure from this message. How are you feeling about this issue? Are there any blockers that prevent us from merging this in as of right now? |
This PR begins the work for #135 by adding search support via lunr.js.
Changes:
https://deploy-preview-213--selfdefined.netlify.app/
Screen grabs