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

Pagefind for search #3079

Open
corneliusroemer opened this issue Oct 27, 2024 · 2 comments · May be fixed by #3081
Open

Pagefind for search #3079

corneliusroemer opened this issue Oct 27, 2024 · 2 comments · May be fixed by #3081
Labels
feature Feature proposal website Tasks related to the web application

Comments

@corneliusroemer
Copy link
Contributor

corneliusroemer commented Oct 27, 2024

Docs and governance pages are hard to find (there are more than 30 or so in Pathoplexus).

We could use Pagefind to implement a site-wide search, as discussed in pathoplexus/pathoplexus#244

I looked into this briefly:

  • We can't use the astro-pagefind plugin because we use server side rendering.
  • Instead, we can scrape pages with, for instance, wget to create a folder tree with render html pages. E.g.:
    npm run start-server &
    wget --mirror \
         --convert-links \
         --adjust-extension \
         --no-parent \
         --reject "*.js,*.css,*.png,*.jpg,*.jpeg,*.gif,*.ico,*.svg,*.woff,*.woff2,*.ttf" \
         --exclude-directories="/seq" \
         --directory-prefix=./static \
         localhost:3000
    
  • We then run npx pagefind --site static/localhost:3000
  • And move the resulting output into the public folder: mv static/localhost:3000/pagefind public/pagefind
  • We can then add search in the header component of every page by:
    • including this in the html header:
      <link href='/pagefind/pagefind-ui.css' rel='stylesheet' />
      <script src='/pagefind/pagefind-ui.js' is:inline></script>
    • Adding a search div somewhere in the header nav html:
      <div id='search' class='px-4'></div>
    • Initializing the search somewhere:
      <script is:inline>
          window.addEventListener('DOMContentLoaded', (event) => {
              new PagefindUI({
                  element: '#search',
                  showSubResults: true,
              });
          });
      </script>
  • Here's an (ugly) proof-of-concept:
    2024-10-27 02 11 18
  • This workaround might be necessary: CLI adds .html suffix to target paths in the generated index, causing 404 errors in the Pagefind UI CloudCannon/pagefind#732 (comment)
  • It's probably nicer to show search results in a modal, this is how Starlight (Astro docs) does it: https://github.com/withastro/starlight/blob/main/packages/starlight/components/Search.astro
Brave Browser 2024-10-27 02 40 47
@corneliusroemer corneliusroemer added website Tasks related to the web application feature Feature proposal labels Oct 27, 2024
@corneliusroemer corneliusroemer linked a pull request Oct 27, 2024 that will close this issue
@corneliusroemer corneliusroemer linked a pull request Oct 27, 2024 that will close this issue
@corneliusroemer
Copy link
Contributor Author

We could also use Algolia, might be slightly more feature packed, has free plan and if we need more we should qualify for open source: https://www.algolia.com/for-open-source/

@theosanderson
Copy link
Member

I don't think we should incorporate something into Loculus that requires filling out a form to apply(?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature proposal website Tasks related to the web application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants