Skip to content

Commit 86363fe

Browse files
committed
Add redirect and fix display issue for warningbox
1 parent f5a0ebd commit 86363fe

File tree

10 files changed

+29
-33
lines changed

10 files changed

+29
-33
lines changed

README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,7 @@ Yes, you usually will want to accomplish this by just changing the first header
7171
```rst
7272
:orphan:
7373
74-
This page has been moved to :doc:`new-page-name`.
75-
76-
.. raw:: html
77-
78-
<noscript>
79-
<meta http-equiv="refresh" content="0; url=/new-page-name.html"/>
80-
</noscript>
81-
<script>
82-
location.pathname = "/new-page-name.html";
83-
</script>
74+
.. redirect:: new-page-name
8475
```
8576

8677
### How to I add a warning to a page?

src/_ext/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .fixme import FixMeDirective
22
from .gallery import GalleryDirective
33
from .warningbox import WarningBoxDirective
4+
from .redirect import RedirectDirective
45

56
from sphinx.application import Sphinx
67
from sphinx.util.typing import ExtensionMetadata
@@ -10,6 +11,7 @@ def setup(app: Sphinx) -> ExtensionMetadata:
1011
app.add_directive("fixme", FixMeDirective)
1112
app.add_directive("warningbox", WarningBoxDirective)
1213
app.add_directive("gallery", GalleryDirective)
14+
app.add_directive("redirect", RedirectDirective)
1315

1416
return {
1517
"version": "0.1",
122 Bytes
Binary file not shown.
1.36 KB
Binary file not shown.
-32 Bytes
Binary file not shown.

src/_ext/redirect.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from docutils import nodes
2+
3+
from sphinx.util.docutils import SphinxDirective
4+
5+
from .utils import RawHTML
6+
7+
8+
class RedirectDirective(SphinxDirective):
9+
required_arguments = 1
10+
11+
def run(self) -> list[nodes.Node]:
12+
new_page = self.arguments[0]
13+
new_uri = self.env.app.builder.get_target_uri(new_page)
14+
return [
15+
*self.parse_text_to_nodes(
16+
f"This page has been moved to :doc:`{new_page}`."
17+
),
18+
RawHTML(
19+
f'<noscript><meta http-equiv="refresh" content="0; url={new_uri}"/></noscript>'
20+
),
21+
RawHTML(f'<script>location.href = "{new_uri}";</script>'),
22+
]

src/_ext/warningbox.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ class WarningBoxDirective(SphinxDirective):
1616
def run(self) -> list[nodes.Node]:
1717
return [
1818
RawHTML('<div class="warning">'),
19-
nodes.inline(text=f"⚠️ {self.options['title']} ⚠️"),
20-
RawHTML("<br/>"),
19+
*self.parse_text_to_nodes(f"⚠️ {self.options['title']} ⚠️"),
2120
*self.parse_content_to_nodes(),
2221
RawHTML("</div>"),
2322
]

src/guide/software/screens.rst

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
11
:orphan:
22

3-
This page has been moved to :doc:`../config/screens`.
4-
5-
.. raw:: html
6-
7-
<noscript>
8-
<meta http-equiv="refresh" content="0; url=/guide/config/screens.html"/>
9-
</noscript>
10-
<script>
11-
location.pathname = "/guide/config/screens.html";
12-
</script>
3+
.. redirect:: ../config/screens

src/guide/software/templates.rst

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
11
:orphan:
22

3-
This page has been moved to :doc:`../config/templates`.
4-
5-
.. raw:: html
6-
7-
<noscript>
8-
<meta http-equiv="refresh" content="0; url=/guide/config/templates.html"/>
9-
</noscript>
10-
<script>
11-
location.pathname = "/guide/config/templates.html";
12-
</script>
3+
.. redirect:: ../config/templates

src/guide/software/toltec.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Toltec
33
======
44

55
.. warningbox::
6-
:title: Always refer to the <a href="https://toltec-dev.org">toltec website</a> for up to date information
6+
:title: Always refer to the `toltec website <https://toltec-dev.org>`_ for up to date information
77

88
The website contains up to date information on what version of the OS is supported, as well as the latest installation steps.
99

0 commit comments

Comments
 (0)