Skip to content

Commit 20337f9

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 07d3e76 commit 20337f9

File tree

14 files changed

+141
-0
lines changed

14 files changed

+141
-0
lines changed

news/changelog-1.6.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ All changes included in 1.6:
7979

8080
- ([#10268](https://github.com/quarto-dev/quarto-cli/issues/10268)): `quarto create` supports opening project in Positron, in addition to VS Code and RStudio IDE.
8181
- ([#10285](https://github.com/quarto-dev/quarto-cli/issues/10285)): Include text from before the first chapter sections in search indices. In addition, include text of every element with `.quarto-include-in-search-index` class in search indices.
82+
- ([#11189](https://github.com/quarto-dev/quarto-cli/issues/11189)): Exclude text of every element with the `.quarto-exclude-from-search-index` class from search indices.
8283
- ([#10566](https://github.com/quarto-dev/quarto-cli/issues/10566)): Ensure that `quarto run` outputs `stdout` and `stderr` to the correct streams.
8384

8485
### Websites

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+
};

0 commit comments

Comments
 (0)