From c6a1f67f799e0290cac9ae4d5a25bdc264450559 Mon Sep 17 00:00:00 2001 From: Jorge Marques Date: Sat, 10 Aug 2024 21:31:22 +0200 Subject: [PATCH] Simplify filtered tree logic, bump version 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 --- adi_doctools/__init__.py | 2 +- adi_doctools/theme/__init__.py | 45 +++++++++++++--------------------- docs/fundamentals.rst | 15 ++++++------ 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/adi_doctools/__init__.py b/adi_doctools/__init__.py index daa2929..f0faf3e 100644 --- a/adi_doctools/__init__.py +++ b/adi_doctools/__init__.py @@ -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__) diff --git a/adi_doctools/theme/__init__.py b/adi_doctools/theme/__init__.py index a6b4748..6228618 100644 --- a/adi_doctools/theme/__init__.py +++ b/adi_doctools/theme/__init__.py @@ -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'): @@ -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]'): diff --git a/docs/fundamentals.rst b/docs/fundamentals.rst index 64e4fea..b5361cf 100644 --- a/docs/fundamentals.rst +++ b/docs/fundamentals.rst @@ -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