Simplify search index exclusions

This commit is contained in:
Ben Edgington
2025-06-01 19:38:46 +01:00
parent 5eb701f08f
commit de6dcaab4c
7 changed files with 16 additions and 11 deletions

View File

@@ -84,10 +84,7 @@ function getChunks(tree, chunkTypes, exclude) {
}
function includePage(frontmatter, exclude) {
return (
exclude.pages?.indexOf(frontmatter.path) === -1 &&
!isExcludedFrontmatter(frontmatter, exclude)
);
return !isExcludedFrontmatter(frontmatter, exclude);
}
function buildSearchIndex(options) {

View File

@@ -8,26 +8,28 @@ if (minimal) {
const pages = defineCollection({
loader: minimal
? glob({ pattern: "**/preface.md", base: "./src/md/pages" })
: glob({ pattern: "**/*.md", base: "./src/md/pages" }),
? glob({ pattern: '**/preface.md', base: './src/md/pages' })
: glob({ pattern: '**/*.md', base: './src/md/pages' }),
schema: z.object({
hide: z.boolean(),
path: z.string(),
titles: z.array(z.string()),
index: z.array(z.number()),
sequence: z.number(),
search: z.boolean().optional(),
}),
});
const special = defineCollection({
loader: minimal
? glob({ pattern: "search.md", base: "./src/md" })
: glob({ pattern: "*.md", base: "./src/md" }),
? glob({ pattern: 'search.md', base: './src/md' })
: glob({ pattern: '*.md', base: './src/md' }),
schema: z.object({
path: z.string(),
titles: z.array(z.string()).optional(),
index: z.array(z.number()).optional(),
sequence: z.number().optional(),
search: z.boolean().optional(),
}),
});

View File

@@ -58,9 +58,11 @@ const SearchOptions = {
],
exclude: {
// Note, only pages under src/md/pages have a "hide" property.
frontmatter: [{ key: 'hide', value: true }],
// No point indexing these.
pages: ['/', '/404/', '/contents/', '/search/', '/annotated-spec/'],
frontmatter: [
{ key: 'hide', value: true },
{ key: 'search', value: false },
{ key: 'path', value: '/annotated-spec/' },
],
// Elements matching this query are ignored completely, including their text:
ignore:
'svg, details, mtable, mrow, [aria-hidden="true"], a[id^="fnref-"], a.data-footnote-backref',

View File

@@ -1,5 +1,6 @@
---
path: /404/
search: false
---
# Not Found

View File

@@ -3,6 +3,7 @@ path: /contents/
titles: ["Contents"]
index: [-1]
sequence: -1
search: false
---
# Contents

View File

@@ -3,6 +3,7 @@ path: /search/
titles: ["Search"]
index: [-1]
sequence: -2
search: false
---
# Search

View File

@@ -1,5 +1,6 @@
---
path: /
search: false
---
<div class="title-page">