Skip to content

Commit 4777f06

Browse files
Remove 'Buy the Book' links, add Pagefind search
- Remove Gumroad links from landing page and footer - Add pagefind as build dependency, runs post-build - Wire up search dialog with live results, debounced input - Add data-pagefind-body to chapter content for focused indexing Co-authored-by: Ona <no-reply@ona.com>
1 parent 332a3e1 commit 4777f06

7 files changed

Lines changed: 195 additions & 16 deletions

File tree

astro.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export default defineConfig({
99
integrations: [mdx(), sitemap()],
1010
vite: {
1111
plugins: [tailwindcss()],
12+
server: {
13+
allowedHosts: true,
14+
},
1215
},
1316
markdown: {
1417
shikiConfig: {

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
"private": true,
66
"scripts": {
77
"dev": "astro dev",
8-
"build": "astro build",
8+
"build": "astro build && pagefind --site dist",
99
"preview": "astro preview",
1010
"astro": "astro"
1111
},
@@ -16,6 +16,7 @@
1616
},
1717
"devDependencies": {
1818
"@tailwindcss/vite": "^4.1.1",
19+
"pagefind": "^1.3.0",
1920
"tailwindcss": "^4.1.1"
2021
}
2122
}

src/components/Footer.astro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const base = import.meta.env.BASE_URL.replace(/\/$/, "");
1111
<p>February 2026</p>
1212
</div>
1313
<div class="flex gap-6">
14-
<a href="https://siddhantkhare.gumroad.com" target="_blank" rel="noopener noreferrer" class="hover:text-[var(--text-primary)] transition-colors">Buy the Book</a>
1514
<a href="https://github.com/Siddhant-K-code/agentic-engineering-guide" target="_blank" rel="noopener noreferrer" class="hover:text-[var(--text-primary)] transition-colors">GitHub</a>
1615
<a href="https://twitter.com/Siddhant_K_code" target="_blank" rel="noopener noreferrer" class="hover:text-[var(--text-primary)] transition-colors">Twitter</a>
1716
</div>

src/components/Header.astro

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,22 @@ const base = import.meta.env.BASE_URL.replace(/\/$/, "");
8282
<div id="search-dialog" class="fixed inset-0 z-[100] hidden">
8383
<div class="absolute inset-0 bg-black/50 backdrop-blur-sm" id="search-backdrop"></div>
8484
<div class="relative max-w-xl mx-auto mt-[15vh] bg-[var(--bg-secondary)] border border-[var(--border)] rounded-lg shadow-2xl overflow-hidden">
85-
<div id="search-container" class="p-4">
86-
<p class="text-sm text-[var(--text-tertiary)]">Search will be available after Pagefind is configured.</p>
85+
<div class="flex items-center border-b border-[var(--border)] px-4">
86+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="var(--text-tertiary)" stroke-width="2" stroke-linecap="round" class="shrink-0">
87+
<circle cx="11" cy="11" r="8" />
88+
<line x1="21" y1="21" x2="16.65" y2="16.65" />
89+
</svg>
90+
<input
91+
id="search-input"
92+
type="text"
93+
placeholder="Search chapters..."
94+
autocomplete="off"
95+
class="w-full bg-transparent px-3 py-3 text-sm text-[var(--text-primary)] placeholder:text-[var(--text-tertiary)] outline-none"
96+
/>
97+
<kbd class="font-[var(--font-mono)] text-[10px] px-1.5 py-0.5 rounded bg-[var(--bg-tertiary)] border border-[var(--border)] text-[var(--text-tertiary)] shrink-0">ESC</kbd>
98+
</div>
99+
<div id="search-results" class="max-h-[60vh] overflow-y-auto p-2">
100+
<p id="search-placeholder" class="text-sm text-[var(--text-tertiary)] px-2 py-4 text-center">Type to search across all chapters</p>
87101
</div>
88102
</div>
89103
</div>
@@ -105,13 +119,42 @@ const base = import.meta.env.BASE_URL.replace(/\/$/, "");
105119
overlay?.classList.toggle('hidden');
106120
});
107121

108-
// Search dialog
122+
// Search
109123
const searchTrigger = document.getElementById('search-trigger');
110124
const searchDialog = document.getElementById('search-dialog');
111125
const searchBackdrop = document.getElementById('search-backdrop');
126+
const searchInput = document.getElementById('search-input') as HTMLInputElement;
127+
const searchResults = document.getElementById('search-results');
128+
const searchPlaceholder = document.getElementById('search-placeholder');
129+
130+
let pagefind: any = null;
131+
132+
async function loadPagefind() {
133+
if (pagefind) return;
134+
try {
135+
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
136+
pagefind = await import(/* @vite-ignore */ `${base}/pagefind/pagefind.js`);
137+
await pagefind.init();
138+
} catch (e) {
139+
console.warn('Pagefind not available:', e);
140+
}
141+
}
112142

113-
function openSearch() { searchDialog?.classList.remove('hidden'); }
114-
function closeSearch() { searchDialog?.classList.add('hidden'); }
143+
function openSearch() {
144+
searchDialog?.classList.remove('hidden');
145+
searchInput?.focus();
146+
loadPagefind();
147+
}
148+
149+
function closeSearch() {
150+
searchDialog?.classList.add('hidden');
151+
if (searchInput) searchInput.value = '';
152+
if (searchResults) searchResults.innerHTML = '';
153+
if (searchPlaceholder) {
154+
searchPlaceholder.style.display = '';
155+
searchResults?.appendChild(searchPlaceholder);
156+
}
157+
}
115158

116159
searchTrigger?.addEventListener('click', openSearch);
117160
searchBackdrop?.addEventListener('click', closeSearch);
@@ -123,4 +166,42 @@ const base = import.meta.env.BASE_URL.replace(/\/$/, "");
123166
}
124167
if (e.key === 'Escape') closeSearch();
125168
});
169+
170+
let debounceTimer: ReturnType<typeof setTimeout>;
171+
searchInput?.addEventListener('input', () => {
172+
clearTimeout(debounceTimer);
173+
debounceTimer = setTimeout(async () => {
174+
const query = searchInput.value.trim();
175+
if (!searchResults) return;
176+
177+
if (!query) {
178+
searchResults.innerHTML = '';
179+
if (searchPlaceholder) {
180+
searchPlaceholder.style.display = '';
181+
searchResults.appendChild(searchPlaceholder);
182+
}
183+
return;
184+
}
185+
186+
if (!pagefind) {
187+
searchResults.innerHTML = '<p class="text-sm text-[var(--text-tertiary)] px-2 py-4 text-center">Search index not available. Try again after the site is built.</p>';
188+
return;
189+
}
190+
191+
const search = await pagefind.search(query);
192+
const results = await Promise.all(search.results.slice(0, 10).map((r: any) => r.data()));
193+
194+
if (results.length === 0) {
195+
searchResults.innerHTML = '<p class="text-sm text-[var(--text-tertiary)] px-2 py-4 text-center">No results found</p>';
196+
return;
197+
}
198+
199+
searchResults.innerHTML = results.map((r: any) => `
200+
<a href="${r.url}" class="block px-3 py-2.5 rounded-md hover:bg-[var(--bg-hover)] transition-colors">
201+
<span class="block text-sm font-medium text-[var(--text-primary)] leading-snug">${r.meta?.title || 'Untitled'}</span>
202+
<span class="block text-xs text-[var(--text-tertiary)] mt-1 leading-relaxed line-clamp-2">${r.excerpt}</span>
203+
</a>
204+
`).join('');
205+
}, 200);
206+
});
126207
</script>

src/layouts/ChapterLayout.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const pageTitle = chapter
5353
</header>
5454

5555
<!-- Content -->
56-
<div class="prose">
56+
<div class="prose" data-pagefind-body>
5757
<slot />
5858
</div>
5959

src/pages/index.astro

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ const base = import.meta.env.BASE_URL.replace(/\/$/, "");
4444
>
4545
Start Reading →
4646
</a>
47-
<a
48-
href="https://siddhantkhare.gumroad.com"
49-
target="_blank"
50-
rel="noopener noreferrer"
51-
class="inline-flex items-center gap-2 px-5 py-2.5 text-sm font-medium border border-[var(--border)] rounded-md hover:border-[var(--text-tertiary)] transition-colors"
52-
>
53-
Buy the Book
54-
</a>
5547
<a
5648
href="https://github.com/Siddhant-K-code/agentic-engineering-guide"
5749
target="_blank"

0 commit comments

Comments
 (0)