[v3] docs: directive `alias` for redirects
Commit Message
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.
Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
---
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
Comments
Costa Shulyupin <costa.shul@redhat.com> writes:
> 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.
>
> Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
>
> ---
>
> 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
@@ -15,3 +15,5 @@ ARC architecture
=======
* :ref:`genindex`
+
+.. alias:: arc/index
@@ -17,3 +17,5 @@ IA-64 Architecture
serial
features
+
+.. alias:: ia64/index
@@ -26,3 +26,5 @@ implementation.
sparc/index
x86/index
xtensa/index
+
+.. alias:: arch
@@ -18,3 +18,5 @@ m68k Architecture
=======
* :ref:`genindex`
+
+.. alias:: m68k/index
@@ -10,3 +10,5 @@ Nios II Specific Documentation
nios2
features
+
+.. alias:: nios2/index
@@ -18,3 +18,5 @@ OpenRISC Architecture
=======
* :ref:`genindex`
+
+.. alias:: openrisc/index
@@ -18,3 +18,5 @@ PA-RISC Architecture
=======
* :ref:`genindex`
+
+.. alias:: parisc/index
@@ -54,3 +54,5 @@ Maple
.. kernel-doc:: drivers/sh/maple/maple.c
:export:
+
+.. alias:: sh/index
@@ -11,3 +11,5 @@ Sparc Architecture
oradax/oracle-dax
features
+
+.. alias:: sparc/index
@@ -42,3 +42,5 @@ x86-specific Documentation
features
elf_auxvec
xstate
+
+.. alias:: x86/index
@@ -15,3 +15,5 @@ x86_64 Support
cpu-hotplug-spec
machinecheck
fsgs
+
+.. alias:: x86/x86_64/index
@@ -12,3 +12,5 @@ Xtensa Architecture
mmu
features
+
+.. alias:: xtensa/index
@@ -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
new file mode 100644
@@ -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 <costa.shul@redhat.com>
+ :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 }
@@ -1,3 +1,4 @@
# jinja2>=3.1 is not compatible with Sphinx<4.0
jinja2<3.1
Sphinx==2.4.4
+rediraffe_redirects