Skip to content

Commit

Permalink
feat: Skip document with :nosearch: metadata (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverRainZ authored Aug 17, 2024
1 parent 27b8d0a commit 02a110c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ Change Log
Version 1.x
===========

.. todo
.. version:: 1.3
- Skip document with ``:nosearch:`` metadata (:issue:`22`)
.. version:: 1.2
:date: 2024-03-23

Expand Down
2 changes: 1 addition & 1 deletion src/sphinxnotes/snippet/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def on_doctree_resolved(app:Sphinx, doctree:nodes.document, docname:str) -> None
return

doc = []
snippets = pick(doctree)
snippets = pick(app, doctree, docname)
for s, n in snippets:
if not is_snippet_matched(pats, s, docname):
continue
Expand Down
11 changes: 9 additions & 2 deletions src/sphinxnotes/snippet/picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@
"""

from __future__ import annotations
from typing import List, Tuple
from typing import TYPE_CHECKING

from docutils import nodes

from sphinx.util import logging

from . import Snippet, Section, Document

if TYPE_CHECKING:
from sphinx.application import Sphinx

logger = logging.getLogger(__name__)


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

metadata = app.env.metadata.get(docname, {})
if 'no-search' in metadata or 'nosearch' in metadata:
logger.debug('Skipped document with nosearch metadata')
return []

snippets = []

# Pick document
Expand Down

0 comments on commit 02a110c

Please sign in to comment.