diff --git a/README.md b/README.md index 46b271b..eb4cb18 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,7 @@ All commands are run from the root of the project, from a terminal: ## 🗺 Roadmap - [x] Initial project setup - [x] Basic theme implementation -- [x] Better full-text search without `Fuse.js` -- [ ] A mode to make the site 0 javascript +- [ ] Better full-text search without `Fuse.js` - [ ] Multiple authors via YAML - [ ] i18n support - [ ] Integrate with Fediverse w/ activityPub diff --git a/package.json b/package.json index 8f7df2f..bd612b6 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "@astrojs/sitemap": "^3.3.1", "@fontsource-variable/jetbrains-mono": "^5.2.5", "astro": "^5.2.5", + "fuse.js": "^7.0.0", "sharp": "^0.34.1", "ultrahtml": "^1.6.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ed376d1..5741b93 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,9 @@ importers: astro: specifier: ^5.2.5 version: 5.7.10(@azure/identity@4.9.1)(@types/node@22.15.3)(rollup@4.40.1)(typescript@5.8.3)(yaml@2.7.1) + fuse.js: + specifier: ^7.0.0 + version: 7.1.0 sharp: specifier: ^0.34.1 version: 0.34.1 @@ -1689,6 +1692,10 @@ packages: function-bind@1.1.2: resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} + fuse.js@7.1.0: + resolution: {integrity: sha512-trLf4SzuuUxfusZADLINj+dE8clK1frKdmqiJNb1Es75fmI5oY6X2mxLVUciLLjxqw/xr72Dhy+lER6dGd02FQ==} + engines: {node: '>=10'} + get-caller-file@2.0.5: resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} engines: {node: 6.* || 8.* || >= 10.*} @@ -4920,6 +4927,8 @@ snapshots: function-bind@1.1.2: {} + fuse.js@7.1.0: {} + get-caller-file@2.0.5: {} get-east-asian-width@1.3.0: {} diff --git a/src/components/BackToTop.astro b/src/components/BackToTop.astro index 3fe2679..59c0c27 100644 --- a/src/components/BackToTop.astro +++ b/src/components/BackToTop.astro @@ -1,8 +1,7 @@ --- -import {siteConfig} from "../config"; -const noscript = siteConfig.noClientJavaScript + --- -{noscript ? : + } \ No newline at end of file + \ No newline at end of file diff --git a/src/components/Search.astro b/src/components/Search.astro index a2c94f8..b115350 100644 --- a/src/components/Search.astro +++ b/src/components/Search.astro @@ -1,17 +1,5 @@ --- -import {siteConfig} from "../config"; -const noscript = siteConfig.noClientJavaScript --- -{noscript ? -
-
- - - -
- -
- :
search @@ -25,203 +13,86 @@ const noscript = siteConfig.noClientJavaScript
+ } + function performSearch(query) { + if (!query) { + document.getElementById('search-results').innerHTML = ''; + return; + } + + if (!searchInitialized) return; + + const results = fuse.search(query); + const resultsElement = document.getElementById('search-results'); + + if (results.length === 0) { + resultsElement.innerHTML = '

No results found.

'; + return; + } + + const html = results + .map(result => ` +
+ + ${result.item.title} + ${new Date(result.item.pubDate).toISOString().split('T')[0]} + +
+ `) + .join(''); + + resultsElement.innerHTML = html; + } + // Add event listener for search input + const searchInput = document.getElementById('search-input'); + + // Initialize search only when the input is focused or clicked + searchInput.addEventListener('focus', initializeSearch); + searchInput.addEventListener('click', initializeSearch); + + searchInput.addEventListener('input', (e) => { + if (!searchInitialized) { + initializeSearch().then(() => { + performSearch(e.target.value); + }); + } else { + performSearch(e.target.value); + } + }); + + searchInput.addEventListener('focus', () => { + if (!searchInitialized) { + document.getElementById('search-results').innerHTML = '

Loading search index...

'; + } + }); +