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

offline search for mirror drives #1175

Merged
merged 10 commits into from
Jun 23, 2023
Merged

offline search for mirror drives #1175

merged 10 commits into from
Jun 23, 2023

Conversation

gumaerc
Copy link
Collaborator

@gumaerc gumaerc commented Jun 21, 2023

What are the relevant tickets?

Closes #1174

Description (What does it do?)

This PR adds the Fuse.js library to the project and utilizes it to provide offline search functionality in the www-offline theme, used as the home page of mirror drives. The search icon is now displayed in the header on pages that aren't the search page, linking to a new search.html page at the root. In mitodl/ocw-studio#1705, we set up ocw-studio to publish a file under content/websites for each website that has been published live at least once inside the root website, ocw-www. This content is currently being used to generate a paginated list of sites at the root when using the www-offline theme in index.html. In search.html, we put that same list into an array in Javascript and feed it into Fuse.js as a data source, indexing on primary_course_number and title. The search page mostly replicates a basic version of the online search without any facets or resource search, providing links to sites relative to the root of the mirror drive in the same way the paginated index does. Everything is done in raw Javascript right in a script tag on the page to avoid any issues with CORS when viewing the page without a web server offline.

Screenshots (if appropriate):

image
image

How can this be tested?

  • Clone ocw-hugo-themes on this branch as well as https://github.mit.edu/ocw-content-rc/ocw-www and ocw-hugo-projects on the cg/www-offline-enable-section branch
  • In ocw-hugo-themes, run yarn install to make sure you install the latest dependencies
  • In ocw-hugo-themes, run yarn build /path/to/ocw-content-rc/ocw-www/ /path/to/ocw-hugo-projects/ocw-www/config-offline.yaml
  • Browse to your ocw-content-rc/ocw-www/dist folder and double click on index.html
  • Click the search icon in the header
  • Type any query you want here and search for courses
  • Click on any of the courses and verify that the path in your browser looks something like file://path/to/ocw-content-rc/ocw-www/dist/courses/course-name
  • These courses will not be present because this isn't a full mirror drive build, but if you want to test browsing to an offline site this way you can download the course ZIP from the live site, create a courses folder under dist and extract it there to a folder matching the courses name` property

Release process

mitodl/ocw-hugo-projects#255 should be merged and released before this PR

@github-actions github-actions bot temporarily deployed to pull request June 21, 2023 23:07 Inactive
@github-actions github-actions bot temporarily deployed to pull request June 21, 2023 23:08 Inactive
@github-actions
Copy link

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Copy link
Contributor

@ChristopherChudzicki ChristopherChudzicki left a comment

Choose a reason for hiding this comment

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

This makes sense, works as described, and is super cool 👍

Some things I noticed... I think that at least the first two are worth addressing:

  1. I think we should change minMatchCharLength: 5 to something significantly lower. Currently, OCW has no math courses (joking...):
Screenshot 2023-06-23 at 2 39 36 PM
  1. When there are no matches, the page is very blank. I think we should say "No results found". Or perhaps always show the count.

  2. (Fixed) Sometimes the titles contain invalid characters on the search page. For example, 3.034-fall-2005 has an ampersand in its title:

And, as mentioned in slack: We may want to move some/all of the JS to a file that gets processed by webpack. JS in template files do not. The arrow functions will make IE mad. See also #1075

aria-label="Search"
placeholder="Search OpenCourseWare"
/>
<button id="search-button" type="submit" class="py-2 px-3">Search</button>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<button id="search-button" type="submit" class="py-2 px-3">Search</button>
<button id="search-button" type="button" class="py-2 px-3">Search</button>

Then you won't need to prevent default down below.

@github-actions github-actions bot temporarily deployed to pull request June 23, 2023 19:48 Inactive
@github-actions github-actions bot temporarily deployed to pull request June 23, 2023 19:49 Inactive
@gumaerc
Copy link
Collaborator Author

gumaerc commented Jun 23, 2023

@ChristopherChudzicki all set for another look

@github-actions github-actions bot temporarily deployed to pull request June 23, 2023 20:09 Inactive
@github-actions github-actions bot temporarily deployed to pull request June 23, 2023 20:09 Inactive
@gumaerc gumaerc merged commit 3cde05d into main Jun 23, 2023
5 checks passed
This was referenced Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

offline search for mirror drives
2 participants