Skip to content

Commit b7d491c

Browse files
committed
Fixes #11189
- Users will now be able to create `div`s and `span`s that exclude certain page elements from the search index.
1 parent e928dd8 commit b7d491c

File tree

13 files changed

+140
-0
lines changed

13 files changed

+140
-0
lines changed

src/project/types/website/website-search.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ export async function updateSearchIndex(
291291
}
292292
});
293293

294+
// Remove all page elements that should be excluded from the search index
295+
const exclusions = doc.querySelectorAll(".quarto-exclude-from-search-index");
296+
for (const exclusion of exclusions) {
297+
exclusion._remove();
298+
}
299+
294300
// We always take the first child of the main region (whether that is a p or section)
295301
// and create an index entry for the page itself (with no hash). If there is other
296302
// 'unsectioned' content on the page, we include that as well.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.quarto/
2+
*.html
3+
*.pdf
4+
*_files/
5+
/_site_with_filter/
6+
/_site_without_filter/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
title: Remove-class
2+
author: Nick Vigilante
3+
version: 1.0.0
4+
quarto-required: ">=99.9.0"
5+
contributes:
6+
filters:
7+
- remove-class.lua
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
-- Reformat all heading text
3+
function RemoveClass(el)
4+
class = "quarto-exclude-from-search-index"
5+
if el.classes:includes(class) then
6+
el.classes:remove(class)
7+
end
8+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
project:
2+
output-dir: _site_with_filter
3+
post-render:
4+
- check-index-with-filter.ts
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
project:
2+
output-dir: _site_without_filter
3+
post-render:
4+
- check-index-without-filter.ts
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
project:
2+
type: website
3+
4+
profile:
5+
default: without-filter
6+
7+
website:
8+
title: "issue-11189"
9+
navbar:
10+
left:
11+
- href: index.qmd
12+
text: Home
13+
- about.qmd
14+
15+
format:
16+
html:
17+
theme: cosmo
18+
css: styles.css
19+
toc: true
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: "About"
3+
---
4+
5+
About this site
6+
7+
::: {.quarto-exclude-from-search-index}
8+
9+
Please don't find me.
10+
11+
:::
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const json = JSON.parse(Deno.readTextFileSync("_site_with_filter/search.json"));
2+
3+
const obj = Object.fromEntries(json.map((x: any) => [x.objectID, x]));
4+
5+
const file = "index.html";
6+
7+
if (obj[file].text.match("Please find me.") === null) {
8+
throw new Error("could not find text that should be shown in " + file);
9+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const json = JSON.parse(Deno.readTextFileSync("_site_without_filter/search.json"));
2+
3+
const obj = Object.fromEntries(json.map((x: any) => [x.objectID, x]));
4+
5+
const file = "about.html";
6+
7+
if (obj[file].text.match("Please don't find me.") !== null) {
8+
throw new Error("found text that should be hidden in " + file);
9+
};

0 commit comments

Comments
 (0)