Skip to content
Draft
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
1 change: 1 addition & 0 deletions website/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default defineConfig({
customCss: ["./src/css/custom.css"],
components: {
Header: "./src/components/header/header.astro",
Head: "./src/components/starlight-overrides/Head.astro",
PageFrame: "./src/components/starlight-overrides/PageFrame.astro",
Sidebar: "./src/components/starlight-overrides/Sidebar.astro",
},
Expand Down
37 changes: 36 additions & 1 deletion website/src/components/header/search.astro
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import "@docsearch/css";
stroke-linecap="round"
stroke-linejoin="round"></path>
</svg>
<span class="DocSearch-Button-Placeholder">Search...</span>
<span class="DocSearch-Button-Placeholder">Search… ($ for all)</span>
</span>
<span class="DocSearch-Button-Keys"></span>
</button>
Expand All @@ -33,15 +33,50 @@ import "@docsearch/css";
<script>
import algoliaConfig from "@site/algolia";

const EXCLUDED_URL_PATTERNS = ["/reference/js-api/", "/release-notes/"];

class StarlightDocSearch extends HTMLElement {
constructor() {
super();
window.addEventListener("DOMContentLoaded", async () => {
const { default: docsearch } = await import("@docsearch/js");

let showAllResults = false;

const options: Parameters<typeof docsearch>[0] = {
...algoliaConfig,
container: "sl-doc-search",
keyboardShortcuts: { "/": false },
transformSearchClient(searchClient) {
return {
...searchClient,
search(requests: any[]) {
return searchClient.search(
requests.map((req: any) => {
const query: string = req.params?.query ?? "";
if (query.startsWith("$")) {
showAllResults = true;
return {
...req,
params: {
...req.params,
query: query.slice(1),
},
};
}
showAllResults = false;
return req;
}),
);
},
};
},
transformItems(items) {
if (showAllResults) return items;
return items.filter(
(item) => !EXCLUDED_URL_PATTERNS.some((pattern) => item.url.includes(pattern)),
);
},
};
docsearch(options);
});
Expand Down
14 changes: 14 additions & 0 deletions website/src/components/starlight-overrides/Head.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
import Default from "@astrojs/starlight/components/Head.astro";

const route = Astro.locals.starlightRoute;
const isJsApi = route.entry.data.jsApi === true;
const isReleaseNotes = route.id.includes("release-notes");

let tag = "docs";
if (isJsApi) tag = "js-api";
else if (isReleaseNotes) tag = "release-notes";
---

<Default {...Astro.props} />
<meta name="docsearch:tag" content={tag} />
14 changes: 8 additions & 6 deletions website/src/components/starlight-overrides/Sidebar.astro
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ if (isReleaseNotes) {
}
---

<SidebarPersister>
<SidebarSublist sublist={filtered} />
</SidebarPersister>

<div class="md:sl-hidden">
<MobileMenuFooter />
<div data-docsearch-ignore>
<SidebarPersister>
<SidebarSublist sublist={filtered} />
</SidebarPersister>

<div class="md:sl-hidden">
<MobileMenuFooter />
</div>
</div>
Loading