From 940cd5cea9181d93b8090441286dde6e4b9a1369 Mon Sep 17 00:00:00 2001 From: Niccolo Borgioli Date: Mon, 2 Dec 2024 10:45:22 +0100 Subject: [PATCH] add search --- TODO.md | 4 +- package.json | 1 + pnpm-lock.yaml | 9 +++++ readingTime.js | 1 + src/components/BaseHead.astro | 8 +++- src/components/Nav.astro | 7 ++-- src/components/PageSearch.svelte | 66 ++++++++++++++++++++++++++++++++ src/pages/search.astro | 39 +++++++++++++++++++ 8 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 src/components/PageSearch.svelte create mode 100644 src/pages/search.astro diff --git a/TODO.md b/TODO.md index d2419a3..3d12d89 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,3 @@ -- Search - Tag count -- Link in contact to status monitor +- title for pages +- check header meta info diff --git a/package.json b/package.json index 49333c6..84ba1f8 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "@fontsource-variable/playfair-display": "^5.1.0", "@iconify-json/ion": "^1.2.1", "astro": "^4.16.13", + "fuse.js": "^7.0.0", "mdast-util-to-string": "^4.0.0", "reading-time": "^1.5.0", "rehype-autolink-headings": "^7.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f848e12..6d83a02 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -38,6 +38,9 @@ importers: astro: specifier: ^4.16.13 version: 4.16.13(rollup@4.27.3)(sass@1.81.0)(stylus@0.64.0)(typescript@5.6.3) + fuse.js: + specifier: ^7.0.0 + version: 7.0.0 mdast-util-to-string: specifier: ^4.0.0 version: 4.0.0 @@ -1225,6 +1228,10 @@ packages: engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} os: [darwin] + fuse.js@7.0.0: + resolution: {integrity: sha512-14F4hBIxqKvD4Zz/XjDc3y94mNZN6pRv3U13Udo0lNLCWRBUsrMv2xwcF/y/Z5sV6+FQW+/ow68cHpm4sunt8Q==} + engines: {node: '>=10'} + gensync@1.0.0-beta.2: resolution: {integrity: sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==} engines: {node: '>=6.9.0'} @@ -3675,6 +3682,8 @@ snapshots: fsevents@2.3.3: optional: true + fuse.js@7.0.0: {} + gensync@1.0.0-beta.2: {} get-caller-file@2.0.5: {} diff --git a/readingTime.js b/readingTime.js index ca6ca03..a11b082 100644 --- a/readingTime.js +++ b/readingTime.js @@ -5,6 +5,7 @@ export function remarkReadingTime() { return function (tree, { data }) { const textOnPage = toString(tree) const readingTime = getReadingTime(textOnPage) + data.astro.frontmatter.text = textOnPage data.astro.frontmatter.readingTime = readingTime } } diff --git a/src/components/BaseHead.astro b/src/components/BaseHead.astro index 61842a3..e8333f1 100644 --- a/src/components/BaseHead.astro +++ b/src/components/BaseHead.astro @@ -45,5 +45,9 @@ const description = 'Welcome to my website!' - + diff --git a/src/components/Nav.astro b/src/components/Nav.astro index 92c8911..b1bce1b 100644 --- a/src/components/Nav.astro +++ b/src/components/Nav.astro @@ -1,4 +1,5 @@ --- +import SearchIcon from '~icons/ion/search-outline' const { pathname } = Astro.url const routes = [ @@ -14,11 +15,11 @@ const routes = [

NB