Skip to content

Commit

Permalink
Simplify filtered tree logic, bump version
Browse files Browse the repository at this point in the history
Always hide other toctrees when on a page included on a toctree.
Do not rely on doctools lut.py anymore, since was confusing having to
update it to affect other repository.
The "topic" entry on the lut.py is now the path to the index.rst page
of the toctree, generally an orphan page, to reduce nesting by one level.

Signed-off-by: Jorge Marques <[email protected]>
  • Loading branch information
gastmaier committed Aug 10, 2024
1 parent eae0c82 commit c6a1f67
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
2 changes: 1 addition & 1 deletion adi_doctools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .role import setup as role_setup
from .lut import get_lut

__version__ = "0.3.35"
__version__ = "0.3.36"

logger = logging.getLogger(__name__)

Expand Down
45 changes: 17 additions & 28 deletions adi_doctools/theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,33 +127,25 @@ def get_topic(pagename):
i = pagename.find('/')
return pagename[0:i] if i != -1 else ''

def filter_tree(root, conf_vars, pagename):
repo, repos = conf_vars
# Keep unchanged for standalone pages (e.g. /index.html, /search.html)
repository = {}
topics = {}
for key in repos:
if repos[key]['visibility'] == 'public':
if 'topic' in repos[key]:
topics.update(repos[key]['topic'])
else:
repository[key] = repos[key]['name']
repotoc = {**topics, **repository}
if repo not in repotoc:
def filter_tree(root, pagename):
body = root.find('./body')
# Keep unchanged for standalone pages (e.g. /index.html, /search.html) and pages not in a toctree
found = False
for e in body.getchildren():
if e.tag == 'ul' and e.get("class") == "current":
found = True
if not found:
return

# Pop toctrees that are not from the current repo
title = repotoc[repo]
body = root.find('./body')
txt = ''
# Pop toctrees that do not include current page
e_ = None
for e in body.getchildren():
if e.tag == 'p':
span = e.find('./span')
if span is not None:
txt = span.text
body.remove(e)
elif txt != title:
body.remove(e)
if e.tag == 'ul':
if e.get("class") != "current":
body.remove(e)
if e_ is not None and e_.tag == 'p':
body.remove(e_)
e_ = e

def iterate(elem):
for ul in elem.findall('./ul'):
Expand Down Expand Up @@ -193,10 +185,7 @@ def iterate(elem):
iterate(li)
lvl.pop()

repo = app.env.config.repository
if repo in app.lut['repos'] and "topic" in app.lut['repos'][repo]:
conf_vars_ = (get_topic(pagename), *conf_vars[1:])
filter_tree(root, conf_vars_, pagename)
filter_tree(root, pagename)

for ul in root.findall('./body/ul'):
for li in ul.findall('./li[@class]'):
Expand Down
15 changes: 8 additions & 7 deletions docs/fundamentals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ The content is organized in three levels:

* repotoc: Listing of repositories in the same organization that contain
documentations.
In general, a repository contains only one topic, e.g. the pyadi-iio doc is only
about the libiio python bindings.
If a repo stores more than one topic, the ``topic`` attribute is used to split
each topic on its own repotoc entry, as if they were stored in multiple
In general, a repository contains only one topic (toctree), e.g. the pyadi-iio
doc is only about the libiio python bindings.
If a repo stores more than one toctree/topic, the ``topic`` attribute is used to
split each toctree on its own repotoc entry, as if they were stored in multiple
repositories.
The ``topic`` entry must match the folder name containing the content, e.g.
if ``topic: {'eval':..., 'university':...}``, then a folder named ``eval`` and
other named ``university`` must exist in the doc source root.
The ``topic`` entry must contain one landing page associated with the toctree title,
e.g. ``topic: {'eval': 'Evaluation Boards', 'university': 'University Program'}``,
then the *index.rst* must a toctree titled ``Evaluation Boards`` and the page
``eval/index.rst`` must exist.
In the html output, is displayed on the top header.
* toc: Table of contents of a repository documentation; the displayed depth
is customizable, but in general a doc page (``.rst``, ``.md``) generates one toc
Expand Down

0 comments on commit c6a1f67

Please sign in to comment.