From 55a504e33a43b42cd8dda43e6c8816927c00b320 Mon Sep 17 00:00:00 2001 From: oatbiscuits Date: Thu, 30 Nov 2023 21:33:22 +0000 Subject: [PATCH] Add search functionality (#370) This should solve #23. This is a fully static search implementation powered by [Pagefind](https://pagefind.app/). In terms of UI, I found and implemented a section in the sidebar for searching the documentation. It was hidden presumably waiting for implementation. It mentioned using the slash (/) key for searching, so I implemented the hotkey as well. I made the indexing command required by Pagefind run after Eleventy finishes building using the `.after` hook. Reviewed-on: https://codeberg.org/Codeberg/Documentation/pulls/370 Co-authored-by: oatbiscuits Co-committed-by: oatbiscuits --- .eleventy.js | 5 ++ README.md | 3 +- assets/css/codeberg-docs.css | 21 ++++- content/_includes/contribution_invitation.njk | 2 +- content/_includes/default_layout.njk | 30 +++++-- package-lock.json | 84 ++++++++++++++++++- package.json | 3 +- pagefind.yml | 2 + 8 files changed, 140 insertions(+), 10 deletions(-) create mode 100644 pagefind.yml diff --git a/.eleventy.js b/.eleventy.js index 7409a7d..a24dec1 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -6,6 +6,7 @@ const markdownItAnchor = require('markdown-it-anchor') const library = require('@fortawesome/fontawesome-svg-core').library; const icon = require('@fortawesome/fontawesome-svg-core').icon; const fas = require('@fortawesome/free-solid-svg-icons').fas; +const { execSync } = require('child_process'); module.exports = function(eleventyConfig) { eleventyConfig.addPlugin(navigationPlugin) @@ -58,6 +59,10 @@ module.exports = function(eleventyConfig) {
${content}
` }); + + eleventyConfig.on('eleventy.after', () => { + execSync(`npx pagefind`, { encoding: 'utf-8' }) + }) return { dir: { diff --git a/README.md b/README.md index 3e3a2da..b12e27a 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,9 @@ This website uses [Eleventy](https://www.11ty.dev/), a static site generator. It's supplied as a dev-dependency in `package.json` and its dependencies are locked with `package-lock.json` to try to ensure reproducible builds. +It also uses [PageFind](https://pagefind.app/), a static search library. ## License and Contributors This website (excluding bundled fonts) is licensed under CC BY-SA 4.0. See the [LICENSE](LICENSE.md) file for details. -Please refer to the [commit log](https://codeberg.org/Codeberg/Documentation/commits/branch/main) for an exhaustive list of contributors to Codeberg Documentation. \ No newline at end of file +Please refer to the [commit log](https://codeberg.org/Codeberg/Documentation/commits/branch/main) for an exhaustive list of contributors to Codeberg Documentation. diff --git a/assets/css/codeberg-docs.css b/assets/css/codeberg-docs.css index 9f03a0b..703e6a9 100644 --- a/assets/css/codeberg-docs.css +++ b/assets/css/codeberg-docs.css @@ -161,4 +161,23 @@ code:not(pre > code) { .admonition-content > *:last-child { margin-bottom: 0; -} \ No newline at end of file +} + +#search-results { + overflow: hidden; + word-wrap: anywhere; + white-space: break-spaces; + --pagefind-ui-background: var(--dm-sidebar-bg-color); + --pagefind-ui-primary: var(--dm-sidebar-link-text-color); + --pagefind-ui-border: var(--dm-sidebar-divider-bg-color); +} + +#search-results li { + margin-bottom: 0; + gap: 0; + padding: 10px 0px; +} + +.pagefind-modular-list-thumb { + display: none; +} diff --git a/content/_includes/contribution_invitation.njk b/content/_includes/contribution_invitation.njk index c833fb8..bae670c 100644 --- a/content/_includes/contribution_invitation.njk +++ b/content/_includes/contribution_invitation.njk @@ -1,4 +1,4 @@ -
+

Hey there! 👋 Thank you for reading this article!

Is there something missing, or do you have an idea on how to improve the documentation? diff --git a/content/_includes/default_layout.njk b/content/_includes/default_layout.njk index d2251f0..3f9bda3 100644 --- a/content/_includes/default_layout.njk +++ b/content/_includes/default_layout.njk @@ -32,6 +32,25 @@ + + + {% if page.url != '/' %}