Skip to content

Commit 6306e46

Browse files
committed
add search
1 parent 657d1c3 commit 6306e46

5 files changed

Lines changed: 178 additions & 1 deletion

File tree

package-lock.json

Lines changed: 103 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "module",
66
"scripts": {
77
"dev": "astro dev",
8-
"build": "astro check && astro build",
8+
"build": "astro check && astro build && pagefind --site dist",
99
"preview": "astro preview",
1010
"astro": "astro",
1111
"lint": "eslint .",
@@ -37,6 +37,7 @@
3737
"eslint": "^9.39.3",
3838
"eslint-plugin-astro": "^1.3.1",
3939
"globals": "^15.14.0",
40+
"pagefind": "^1.4.0",
4041
"prettier": "^3.4.2",
4142
"prettier-plugin-astro": "^0.14.1",
4243
"typescript": "^5.7.3",

src/layouts/BaseLayout.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const navItems = [
1111
{ href: '/demonstrations/', label: 'Demonstrations' },
1212
{ href: '/downloads/', label: 'Downloads' },
1313
{ href: '/docs/', label: 'Docs' },
14+
{ href: '/search/', label: 'Search' },
1415
{ href: '/community/', label: 'Community' },
1516
{ href: '/faq/', label: 'FAQ' },
1617
];

src/pages/search.astro

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
import BaseLayout from '../layouts/BaseLayout.astro';
3+
---
4+
5+
<BaseLayout title="Search - Dasher" description="Search the Dasher website documentation and pages.">
6+
<div class="container">
7+
<section class="section search-section">
8+
<h1>Search</h1>
9+
<p class="lead">
10+
Search across docs, guides, and site pages.
11+
</p>
12+
<div id="search-ui" class="search-ui" aria-live="polite"></div>
13+
<noscript>
14+
<p>Search requires JavaScript enabled in your browser.</p>
15+
</noscript>
16+
</section>
17+
</div>
18+
</BaseLayout>
19+
20+
<link rel="stylesheet" href="/pagefind/pagefind-ui.css" />
21+
<script is:inline type="module">
22+
const mount = document.getElementById('search-ui');
23+
24+
if (!mount) {
25+
throw new Error('Search mount not found');
26+
}
27+
28+
const showFallback = () => {
29+
mount.innerHTML = `
30+
<div class="search-fallback">
31+
<p>Search index not available in this environment yet.</p>
32+
<p>Run <code>npm run build</code> to generate Pagefind assets, then open this page from the built site.</p>
33+
</div>
34+
`;
35+
};
36+
37+
try {
38+
const { PagefindUI } = await import('/pagefind/pagefind-ui.js');
39+
new PagefindUI({
40+
element: '#search-ui',
41+
showSubResults: true,
42+
resetStyles: false,
43+
autofocus: true,
44+
placeholder: 'Search docs, demos, and pages...',
45+
translations: {
46+
clear_search: 'Clear',
47+
load_more: 'Load more results',
48+
search_label: 'Search site',
49+
},
50+
});
51+
} catch {
52+
showFallback();
53+
}
54+
</script>

src/styles/pages.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,24 @@ li {
11991199
transform: translateY(-2px);
12001200
}
12011201

1202+
/* Search page */
1203+
.search-section .lead {
1204+
margin-left: 0;
1205+
margin-right: 0;
1206+
text-align: left;
1207+
}
1208+
1209+
.search-ui {
1210+
margin-top: var(--space-md);
1211+
}
1212+
1213+
.search-fallback {
1214+
padding: var(--space-md);
1215+
background-color: var(--color-focus-yellow);
1216+
border-radius: var(--radius-md);
1217+
border: 2px solid var(--color-horizon-mint);
1218+
}
1219+
12021220
.external-link h3 {
12031221
font-size: 1rem;
12041222
margin: 0 0 var(--space-xs) 0;

0 commit comments

Comments
 (0)