Skip to content
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

Open
wants to merge 38 commits into
base: prod
Choose a base branch
from

Conversation

kkemple
Copy link
Collaborator

@kkemple kkemple commented Jun 12, 2020

This PR begins the work for #135 by adding search support via lunr.js.

Changes:

  • Adds a new template for search.json. This is used to build the JSON that needs to be loaded on the client for search.
  • Adds a new collection of all definitions for search use.
  • Adds two new 11ty filters to properly format search JSON
  • Adds a search component in includes
  • Adds a scss file for search component
  • Adds the search component to index layout

https://deploy-preview-213--selfdefined.netlify.app/

Screen grabs

Screen Shot 2020-06-12 at 4 36 25 PM

Screen Shot 2020-06-12 at 4 36 11 PM

@kkemple kkemple changed the title implement-start-of-search [WIP] implement-start-of-search Jun 12, 2020
@tatianamac
Copy link
Collaborator

@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/)

@kkemple
Copy link
Collaborator Author

kkemple commented Jun 12, 2020

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 11ty/includes/components/search.njk!

@tatianamac tatianamac requested a review from ovlb June 13, 2020 01:56
@tatianamac tatianamac added the Status · Needs Review Needs editing/translation/code review label Jun 13, 2020
Copy link
Collaborator

@ovlb ovlb left a 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.

@kkemple
Copy link
Collaborator Author

kkemple commented Jun 20, 2020

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:

  • make search accessible
  • style search to match designs

@tatianamac
Copy link
Collaborator

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).

@tatianamac tatianamac added Status · In Progress and removed Status · Needs Review Needs editing/translation/code review labels Jun 22, 2020
@kkemple
Copy link
Collaborator Author

kkemple commented Jul 4, 2020

I've updated the serverless function to use the deployment previews /search.json path to get search results instead of using a static file (having a CORS issue, investigating). I've also started to update styles for the search to match the new designs. I still have to:

Not really ready for review yet but always welcome feedback!

@ovlb
Copy link
Collaborator

ovlb commented Jul 5, 2020

@kkemple I’ll have a look tomorrow and provide some feedback!

@kkemple
Copy link
Collaborator Author

kkemple commented Aug 1, 2020

I've worked more on the search UI and instead of showing the first 100 characters of each search result, it now shows each instance of the search term within a result (including a bit of extra surrounding content for context), as well as highlights the term itself! 💖

screenshot

Screen Shot 2020-08-01 at 4 39 01 PM

@mxmason
Copy link
Contributor

mxmason commented Aug 5, 2020

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:

  • I would love if each returned term also had a functional link (e.g. clicking "Gaslighting" takes me to that page.
  • I would love a count of how many results have been found, so I can understand how much data I am about to parse
  • How feasible would it be to make this search result take the user to a new, dedicated results page, in the style of a search engine? If this can be done, it would be a boon for accessibility, because screen reader users would be notified that the browser has navigated, and then they can discover the contents of the page on their own. @tatianamac, how would you feel about this?

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!

@kkemple
Copy link
Collaborator Author

kkemple commented Aug 15, 2020

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

  • converted to a form and was able to remove any js and rely on default form functionality 💖
  • I've replaced the h4 headings with h3s
  • I was unable to find an example of the sidebar for navigation in any definition pages! I could use some help on this part as well.
  • I've added the search component to the search results page

Scripting

  • I'm going to leave the script inline until your PR (🌓 Dark Mode #210) is merged. This will prevent any merge conflicts that need to be resolved by both of us adding a js folder under assets. If this gets merged before yours, I'll create an issue to track that, or if preferred, I can add that change to your PR.
  • I've moved the serverless function into the project so that it can be deployed with Netlify, but it will need a bit more work to be 100% functional (see comments below in Remaining section)
  • hiding search is no longer needed as the search form no longer depends on JS 💖
  • I've removed all IDs and replaced with classes

Styles

  • I've reduced specificity and un-nested styles
  • I'm going to leave this item to you! I'm not sure what values should be used or how pxToRem works and feel like you could quickly make these adjustments!
  • I would also love if you could handle this one as well, as I'm not sure what you're looking for here and you could probably handle it faster!
  • I've removed the styles for label, and used the class you suggested

Remaining

This 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 netlify dev command from the Netlify CLI in order to get the serverless function to work correctly.

@colabottles
Copy link

Regarding the search form, there is a label issue. The form label is present but not correctly associated with the form. This can be fixed by adding title="Search" to the input field.

@kkemple
Copy link
Collaborator Author

kkemple commented Aug 22, 2020

@ovlb I've taken a first pass at adding a table of contents to the search results page. A few things to note:

  • The styling is default, and with a search term that has a lot of results or longer words, it looks really wonky (see screenshot below)
  • I've added smooth scrolling for when the user clicks on the table of contents and the page updates to the result. This is behind a check for prefers-reduce-motion. (see gif)
screenshot of wonky menu

Screen Shot 2020-08-22 at 2 37 26 PM

gif of scrolling behavior

ezgif-6-c93ce828913f

<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" />
Copy link
Contributor

@mxmason mxmason Aug 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<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 :)

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!

Copy link
Collaborator

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.

Copy link
Collaborator Author

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?

Copy link
Collaborator

@ovlb ovlb Aug 25, 2020

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.

@ovlb
Copy link
Collaborator

ovlb commented Aug 24, 2020

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.

hiding search is no longer needed as the search form no longer depends on JS 💖

But the search page does, or? As such we should still hide search completely for non-JS contexts.

@kkemple
Copy link
Collaborator Author

kkemple commented Aug 25, 2020

@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.

@ovlb
Copy link
Collaborator

ovlb commented Aug 25, 2020

are you saying we should hide search for users that have JS disabled?

Yip. It’s not the best experience if they are able to submit the form but can’t see the results, imho.

We'll need to add messaging to the search results page as well as those could be shared via URL.

Good point.

@kkemple
Copy link
Collaborator Author

kkemple commented Aug 25, 2020

Yeah, totally agree! I'll take this on next time I dive in to work on it!

@tatianamac tatianamac linked an issue Aug 26, 2020 that may be closed by this pull request
@ovlb
Copy link
Collaborator

ovlb commented Aug 28, 2020

@kkemple FYI: I resolved some conflicts stemming from merging #210 into prod, and updated all colours in use to custom properties.

@tatianamac
Copy link
Collaborator

@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?

@tatianamac tatianamac added Status · Needs Submitter Info Requires more information from submitter before proceeding and removed Status · In Progress labels Apr 27, 2021
@kkemple kkemple added this to the Improve Site Navigation milestone Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status · Needs Submitter Info Requires more information from submitter before proceeding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🔍 Build search feature
5 participants