Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC Pagefind support #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions www/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"check": "astro check && tsc",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
"astro": "astro",
"postbuild": "pagefind -v --source dist --bundle-dir en/pagefind"
},
"dependencies": {
"@algolia/client-search": "^4.13.1",
Expand All @@ -27,5 +28,8 @@
"react": "^18.2.0",
"react-dom": "^18.1.0",
"sharp": "^0.31.2"
},
"devDependencies": {
"pagefind": "^0.12.0"
}
}
31 changes: 29 additions & 2 deletions www/src/components/Header/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,37 @@ const lang = getLanguageFromURL(currentPage);
</a>
</div>
{KNOWN_LANGUAGE_CODES.length > 1 && <LanguageSelect lang={lang} client:idle />}
<!-- <div class="search-item"> -->
<div class="search-item">
<!-- <Search client:idle /> -->
<!-- </div> -->
<input id="search" type="text" placeholder="Search...">
</div>
</nav>
<script is:inline>
document.querySelector('#search')?.addEventListener('input', async (e) => {
// only load the pagefind script once
if (e.target.dataset.loaded !== 'true') {
e.target.dataset.loaded = 'true'
// load the pagefind script
window.pagefind = await import("/en/pagefind/pagefind.js");
}

// search the index using the input value
const search = await window.pagefind.search(e.target.value)

// clear the old results
document.querySelector('#results').innerHTML = ''

// add the new results
for (const result of search.results) {
const data = await result.data()
document.querySelector('#results').innerHTML += `
<a href="${data.url}">
<h3>${data.meta.title}</h3>
<p>${data.excerpt}</p>
</a>`
}
})
</script>
</header>

<style>
Expand Down
2 changes: 1 addition & 1 deletion www/src/components/Header/SkipToContent.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
type Props = {};
---

<a href="#article" class="sr-only focus:not-sr-only skiplink"><span>Skip to Content</span></a>
<a href="#article" data-pagefind-ignore class="sr-only focus:not-sr-only skiplink"><span>Skip to Content</span></a>

<style>
.skiplink,
Expand Down
1 change: 1 addition & 0 deletions www/src/layouts/IntroductionLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ const githubEditUrl = `${CONFIG.GITHUB_EDIT_URL}/${currentFile}`;
<p align="center" class="main-logo">
<Logo className="logo-img" />
</p>
<div id="results" />
<PageContent frontmatter={frontmatter} headings={headings} githubEditUrl={githubEditUrl}>
<slot />
</PageContent>
Expand Down
1 change: 1 addition & 0 deletions www/src/layouts/MainLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const githubEditUrl = `${CONFIG.GITHUB_EDIT_URL}/${currentFile}`;
<LeftSidebar currentPage={currentPage} />
</aside>
<div id="grid-main">
<div id="results" />
<PageContent frontmatter={frontmatter} headings={headings} githubEditUrl={githubEditUrl}>
<slot />
</PageContent>
Expand Down
7 changes: 7 additions & 0 deletions www/src/pages/en/pagefind/pagefind.js.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { APIContext } from "astro"

export async function get({}: APIContext) {
return {
body: 'export const search = () => {return {results: []}}'
}
}
2 changes: 1 addition & 1 deletion www/src/pages/en/recipes/keys-only-gsi.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ It is common to define a Global Secondary Index using a `KEYS_ONLY` projection.

## Example Setup

<blockQuote>
<blockQuote data-pagefind-ignore="all">
<h4>Example Setup</h4>
<details>
<summary>Table Definition</summary>
Expand Down
2 changes: 1 addition & 1 deletion www/src/partials/entity-query-example-setup.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<blockQuote>
<blockQuote data-pagefind-ignore="all">
<h4>Example Setup</h4>
<details>
<summary>Table Definition</summary>
Expand Down
2 changes: 1 addition & 1 deletion www/src/partials/table-definition.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<blockQuote>
<blockQuote data-pagefind-ignore="all">
<h4>Example Setup</h4>
<details>
<summary>Table Definition</summary>
Expand Down