Skip to content

Commit 4a45d5a

Browse files
FireGiantDocsrobmen
authored andcommitted
Boost schema reference pages in Pagefind results
1 parent c39c7ca commit 4a45d5a

4 files changed

Lines changed: 45 additions & 0 deletions

File tree

astro.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export default defineConfig({
4545
components: {
4646
// Override the default `Head` component to add our page tracking.
4747
Head: './src/components/starlight/Head.astro',
48+
// Boost schema reference pages in Pagefind results.
49+
MarkdownContent: './src/components/starlight/MarkdownContent.astro',
50+
PageTitle: './src/components/starlight/PageTitle.astro',
4851
// Override the default `SiteTitle` component to link to both firegiant.com and docs.firegiant.com.
4952
SiteTitle: './src/components/starlight/SiteTitle.astro',
5053
},
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
import '@astrojs/starlight/style/markdown.css';
3+
import { PRIORITY_PAGEFIND_CONTENT_WEIGHT, isPrioritySearchSlug } from '../../utils/pagefind';
4+
5+
const slug = Astro.locals.starlightRoute.entry.slug;
6+
const dataAttributes = isPrioritySearchSlug(slug)
7+
? { 'data-pagefind-weight': PRIORITY_PAGEFIND_CONTENT_WEIGHT }
8+
: {};
9+
---
10+
11+
<div class="sl-markdown-content" {...dataAttributes}><slot /></div>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
import { PRIORITY_PAGEFIND_TITLE_WEIGHT, isPrioritySearchSlug } from '../../utils/pagefind';
3+
4+
const PAGE_TITLE_ID = '_top';
5+
const slug = Astro.locals.starlightRoute.entry.slug;
6+
const dataAttributes = isPrioritySearchSlug(slug)
7+
? { 'data-pagefind-weight': PRIORITY_PAGEFIND_TITLE_WEIGHT }
8+
: {};
9+
---
10+
11+
<h1 id={PAGE_TITLE_ID} {...dataAttributes}>{Astro.locals.starlightRoute.entry.data.title}</h1>
12+
13+
<style>
14+
@layer starlight.core {
15+
h1 {
16+
margin-top: 1rem;
17+
font-size: var(--sl-text-h1);
18+
line-height: var(--sl-line-height-headings);
19+
font-weight: 600;
20+
color: var(--sl-color-white);
21+
}
22+
}
23+
</style>

src/utils/pagefind.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const PRIORITY_SEARCH_PREFIXES = ['wix/schema/', 'firegiant/schema/'] as const;
2+
3+
export const PRIORITY_PAGEFIND_CONTENT_WEIGHT = '8';
4+
export const PRIORITY_PAGEFIND_TITLE_WEIGHT = '10';
5+
6+
export function isPrioritySearchSlug(slug: string): boolean {
7+
return PRIORITY_SEARCH_PREFIXES.some((prefix) => slug.startsWith(prefix));
8+
}

0 commit comments

Comments
 (0)