Skip to content

Commit c3c2ebb

Browse files
committed
docs: add redirects to avoid dead links
1 parent 8143368 commit c3c2ebb

File tree

86 files changed

+1056
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1056
-3
lines changed

docsrc/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ in this directory.
9393
For sequential builds, define the `SynchronousDriver` class, which builds the
9494
revisions sequentially.
9595

96+
To generate redirects for the old, non-version docs, we need the driver to
97+
create folders for the rendered templates. This extension takes place in
98+
`TemplatingDriver`.
99+
96100
For all other details, please refer to `poly.py` and the code of `sphinx-polyversion`.
97101

98102
This text was written by @vpratz, if you have any questions feel free to reach out.

docsrc/poly.py

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from sphinx_polyversion.git import Git, file_predicate, refs_by_type
1313
from sphinx_polyversion.pyvenv import VirtualPythonEnvironment
1414
from sphinx_polyversion.sphinx import SphinxBuilder, Placeholder
15-
from sphinx_polyversion.utils import to_thread
15+
from sphinx_polyversion.utils import to_thread, shift_path
1616

1717
from typing import (
1818
Any,
@@ -32,6 +32,7 @@
3232

3333
#: CodeRegex matching the branches to build docs for
3434
BRANCH_REGEX = r"^(master|dev)$"
35+
# BRANCH_REGEX = r"^(master)$"
3536

3637
#: Regex matching the tags to build docs for
3738
TAG_REGEX = r"^v[\.0-9]*$"
@@ -273,7 +274,47 @@ async def __aexit__(self, exc_type, exc, tb):
273274
}
274275

275276

276-
class SynchronousDriver(DefaultDriver):
277+
class TemplatingDriver(DefaultDriver):
278+
async def build_root(self) -> None:
279+
"""
280+
Build the root directory.
281+
282+
The root of the output directory contains subdirectories for the docs
283+
of each revision. This method adds more to this root directory.
284+
"""
285+
# metadata as json
286+
(self.output_dir / "versions.json").write_text(self.encoder.encode(self.builds))
287+
288+
# copy static files
289+
if self.static_dir and self.static_dir.exists():
290+
logger.info("Copying static files to root directory...")
291+
for file in self.static_dir.rglob("*"):
292+
shutil.copyfile(file, shift_path(self.static_dir, self.output_dir, file))
293+
294+
# generate dynamic files from jinja templates
295+
if self.root_data_factory:
296+
context = self.root_data_factory(self)
297+
else:
298+
context = {"revisions": self.builds, "repo": self.root}
299+
300+
if self.template_dir and self.template_dir.is_dir():
301+
logger.info("Rendering jinja2 templates...")
302+
import jinja2
303+
304+
env = jinja2.Environment(
305+
loader=jinja2.FileSystemLoader(str(self.template_dir)),
306+
autoescape=jinja2.select_autoescape(),
307+
)
308+
for template_path_str in env.list_templates():
309+
template = env.get_template(template_path_str)
310+
rendered = template.render(context)
311+
output_path = self.output_dir / template_path_str
312+
# enable creation of paths for templates, allowing deeper structures
313+
output_path.parent.mkdir(parents=True, exist_ok=True)
314+
output_path.write_text(rendered)
315+
316+
317+
class SynchronousDriver(TemplatingDriver):
277318
async def arun(self) -> None:
278319
"""Build all revisions (async)."""
279320
await self.init()
@@ -282,7 +323,7 @@ async def arun(self) -> None:
282323
await self.build_root()
283324

284325

285-
driver_cls = DefaultDriver if PARALLEL_BUILDS else SynchronousDriver
326+
driver_cls = TemplatingDriver if PARALLEL_BUILDS else SynchronousDriver
286327

287328

288329
# Setup driver and run it
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Redirecting to v1.1.6</title>
5+
<meta charset="utf-8" />
6+
<meta
7+
http-equiv="refresh"
8+
content="0; url=/v1.1.6/_examples/Amortized_Point_Estimation.html"
9+
/>
10+
<link rel="canonical" href="/v1.1.6/_examples/Amortized_Point_Estimation.html" />
11+
</head>
12+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Redirecting to v1.1.6</title>
5+
<meta charset="utf-8" />
6+
<meta
7+
http-equiv="refresh"
8+
content="0; url=/v1.1.6/_examples/Covid19_Initial_Posterior_Estimation.html"
9+
/>
10+
<link rel="canonical" href="/v1.1.6/_examples/Covid19_Initial_Posterior_Estimation.html" />
11+
</head>
12+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Redirecting to v1.1.6</title>
5+
<meta charset="utf-8" />
6+
<meta
7+
http-equiv="refresh"
8+
content="0; url=/v1.1.6/_examples/Hierarchical_Model_Comparison_MPT.html"
9+
/>
10+
<link rel="canonical" href="/v1.1.6/_examples/Hierarchical_Model_Comparison_MPT.html" />
11+
</head>
12+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Redirecting to v1.1.6</title>
5+
<meta charset="utf-8" />
6+
<meta
7+
http-equiv="refresh"
8+
content="0; url=/v1.1.6/_examples/Intro_Amortized_Posterior_Estimation.html"
9+
/>
10+
<link rel="canonical" href="/v1.1.6/_examples/Intro_Amortized_Posterior_Estimation.html" />
11+
</head>
12+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Redirecting to v1.1.6</title>
5+
<meta charset="utf-8" />
6+
<meta
7+
http-equiv="refresh"
8+
content="0; url=/v1.1.6/_examples/LCA_Model_Posterior_Estimation.html"
9+
/>
10+
<link rel="canonical" href="/v1.1.6/_examples/LCA_Model_Posterior_Estimation.html" />
11+
</head>
12+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Redirecting to v1.1.6</title>
5+
<meta charset="utf-8" />
6+
<meta
7+
http-equiv="refresh"
8+
content="0; url=/v1.1.6/_examples/Linear_ODE_system.html"
9+
/>
10+
<link rel="canonical" href="/v1.1.6/_examples/Linear_ODE_system.html" />
11+
</head>
12+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Redirecting to v1.1.6</title>
5+
<meta charset="utf-8" />
6+
<meta
7+
http-equiv="refresh"
8+
content="0; url=/v1.1.6/_examples/Model_Comparison_MPT.html"
9+
/>
10+
<link rel="canonical" href="/v1.1.6/_examples/Model_Comparison_MPT.html" />
11+
</head>
12+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Redirecting to v1.1.6</title>
5+
<meta charset="utf-8" />
6+
<meta
7+
http-equiv="refresh"
8+
content="0; url=/v1.1.6/_examples/Model_Misspecification.html"
9+
/>
10+
<link rel="canonical" href="/v1.1.6/_examples/Model_Misspecification.html" />
11+
</head>
12+
</html>

0 commit comments

Comments
 (0)