docs: directive `alias` for redirects
Subsystems (7)
PATCH v3 1/1 docs: directive `alias` for redirects
and several redirects for moved main arch pages
Problems:
- The documentation lacks hierarchy
- Relocating pages disrupts external links to the documentation and causes confusion for users
Benefits:
- Users can easily access relocated pages from external resources
- Using redirects frees up options for reorganizing the documentation
The solution:
- Introduced directive alias which declares previous path of a moved document as the argument.
- Redirects are implemented with Sphinx extension rediraffe_redirects.
---
Changes:
- complete new implementation
--- Documentation/arch/arc/index.rst | 2 ++ Documentation/arch/ia64/index.rst | 2 ++ Documentation/arch/index.rst | 2 ++ Documentation/arch/m68k/index.rst | 2 ++ Documentation/arch/nios2/index.rst | 2 ++ Documentation/arch/openrisc/index.rst | 2 ++ Documentation/arch/parisc/index.rst | 2 ++ Documentation/arch/sh/index.rst | 2 ++ Documentation/arch/sparc/index.rst | 2 ++ Documentation/arch/x86/index.rst | 2 ++ Documentation/arch/x86/x86_64/index.rst | 2 ++ Documentation/arch/xtensa/index.rst | 2 ++ Documentation/conf.py | 9 +++++++ Documentation/sphinx/alias.py | 35 +++++++++++++++++++++++++ Documentation/sphinx/requirements.txt | 1 + 15 files changed, 69 insertions(+) create mode 100644 Documentation/sphinx/alias.py
Documentation/arch/arc/index.rst +2 -0
@@ -15,3 +15,5 @@ ARC architecture === * :ref:`genindex` + +.. alias:: arc/index
Documentation/arch/ia64/index.rst +2 -0
@@ -17,3 +17,5 @@ IA-64 Architecture serial features + +.. alias:: ia64/index
Documentation/arch/index.rst +2 -0
@@ -26,3 +26,5 @@ implementation. sparc/index x86/index xtensa/index + +.. alias:: arch
Documentation/arch/m68k/index.rst +2 -0
@@ -18,3 +18,5 @@ m68k Architecture === * :ref:`genindex` + +.. alias:: m68k/index
Documentation/arch/nios2/index.rst +2 -0
@@ -10,3 +10,5 @@ Nios II Specific Documentation nios2 features + +.. alias:: nios2/index
Documentation/arch/openrisc/index.rst +2 -0
@@ -18,3 +18,5 @@ OpenRISC Architecture === * :ref:`genindex` + +.. alias:: openrisc/index
Documentation/arch/parisc/index.rst +2 -0
@@ -18,3 +18,5 @@ PA-RISC Architecture === * :ref:`genindex` + +.. alias:: parisc/index
Documentation/arch/sh/index.rst +2 -0
@@ -54,3 +54,5 @@ Maple .. kernel-doc:: drivers/sh/maple/maple.c :export: + +.. alias:: sh/index
Documentation/arch/sparc/index.rst +2 -0
@@ -11,3 +11,5 @@ Sparc Architecture oradax/oracle-dax features + +.. alias:: sparc/index
Documentation/arch/x86/index.rst +2 -0
@@ -42,3 +42,5 @@ x86-specific Documentation features elf_auxvec xstate + +.. alias:: x86/index
Documentation/arch/x86/x86_64/index.rst +2 -0
@@ -15,3 +15,5 @@ x86_64 Support cpu-hotplug-spec machinecheck fsgs + +.. alias:: x86/x86_64/index
Documentation/arch/xtensa/index.rst +2 -0
@@ -12,3 +12,5 @@ Xtensa Architecture mmu features + +.. alias:: xtensa/index
Documentation/conf.py +9 -0
@@ -16,6 +16,7 @@ import sys import os import sphinx import shutil +from importlib.util import find_spec # helper # ------
@@ -57,6 +58,14 @@ extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'maintainers_include', 'sphinx.ext.autosectionlabel', 'kernel_abi', 'kernel_feat'] +extensions += ['alias'] # uses rediraffe + +if find_spec('sphinxext.rediraffe'): + extensions += ['sphinxext.rediraffe'] + rediraffe_redirects = { } +else: + print("Skipping redirects because sphinxext.rediraffe is not installed") + if major >= 3: if (major > 3) or (minor > 0 or patch >= 2): # Sphinx c function parser is more pedantic with regards to type
Documentation/sphinx/alias.py new file +35 -0
@@ -0,0 +1,35 @@ +# SPDX-License-Identifier: GPL-2.0 + +u""" + Directive `alias` + ~~~~~~~~~~~~~~~ + Provides browser redirects for moved pages. + + The directive declares previous path of a moved document as the argument. + Redirects are implemented with Sphinx extension rediraffe_redirects. + + :copyright: Copyright 2023 Costa Shulyupin <[email protected]> + :license: GPL Version 2, June 1991 see linux/COPYING for details. + +""" + +from docutils.parsers.rst import Directive +import os + + +class AliasDirective(Directive): + required_arguments = 1 + + def run(self): + env = self.state.document.settings.env + if 'rediraffe_redirects' not in env.config: + return [] + env.config.rediraffe_redirects[self.arguments[0]] \ + = os.path.relpath(self.state.document.current_source, + env.srcdir) + return [] + + +def setup(app): + app.add_directive('alias', AliasDirective) + return { 'parallel_read_safe': False, 'parallel_write_safe': False }
Documentation/sphinx/requirements.txt +1 -0
@@ -1,3 +1,4 @@ # jinja2>=3.1 is not compatible with Sphinx<4.0 jinja2<3.1 Sphinx=2.4.4 +rediraffe_redirects
Signature · 1 line
2.40.0
Jonathan Corbet
maintainerQuoted 16 lines · Costa Shulyupin
and several redirects for moved main arch pages
Problems:
- The documentation lacks hierarchy
- Relocating pages disrupts external links to the documentation and causes confusion for usersBenefits:
- Users can easily access relocated pages from external resources
- Using redirects frees up options for reorganizing the documentationThe solution:
- Introduced directivealiaswhich declares previous path of a moved document as the argument.
- Redirects are implemented with Sphinx extensionrediraffe_redirects.
Quoted 6 lines
Signed-off-by Costa Shulyupin <[email protected]>---
Changes:
- complete new implementation
I honestly don't know why you keep throwing versions of this at us. In the absence of observed problems, I don't see the value in adding infrastructure that we have to maintain going forward.
Please stop with this for now.
Thanks,
jon