Skip to content

Commit 02a110c

Browse files
authored
feat: Skip document with :nosearch: metadata (#23)
1 parent 27b8d0a commit 02a110c

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

docs/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ Change Log
2222
Version 1.x
2323
===========
2424

25+
.. todo
26+
27+
.. version:: 1.3
28+
29+
- Skip document with ``:nosearch:`` metadata (:issue:`22`)
30+
2531
.. version:: 1.2
2632
:date: 2024-03-23
2733

src/sphinxnotes/snippet/ext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def on_doctree_resolved(app:Sphinx, doctree:nodes.document, docname:str) -> None
123123
return
124124

125125
doc = []
126-
snippets = pick(doctree)
126+
snippets = pick(app, doctree, docname)
127127
for s, n in snippets:
128128
if not is_snippet_matched(pats, s, docname):
129129
continue

src/sphinxnotes/snippet/picker.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@
99
"""
1010

1111
from __future__ import annotations
12-
from typing import List, Tuple
12+
from typing import TYPE_CHECKING
1313

1414
from docutils import nodes
1515

1616
from sphinx.util import logging
1717

1818
from . import Snippet, Section, Document
1919

20+
if TYPE_CHECKING:
21+
from sphinx.application import Sphinx
2022

2123
logger = logging.getLogger(__name__)
2224

2325

24-
def pick(doctree:nodes.document) -> List[Tuple[Snippet,nodes.section]]:
26+
def pick(app:Sphinx, doctree:nodes.document, docname: str) -> list[tuple[Snippet,nodes.section]]:
2527
"""
2628
Pick snippets from document, return a list of snippet and the section
2729
it belongs to.
@@ -31,6 +33,11 @@ def pick(doctree:nodes.document) -> List[Tuple[Snippet,nodes.section]]:
3133
logger.debug('Skipped document without source')
3234
return []
3335

36+
metadata = app.env.metadata.get(docname, {})
37+
if 'no-search' in metadata or 'nosearch' in metadata:
38+
logger.debug('Skipped document with nosearch metadata')
39+
return []
40+
3441
snippets = []
3542

3643
# Pick document

0 commit comments

Comments
 (0)