Skip to content

Commit e8e37f7

Browse files
authored
Merge pull request #41 from QuLogic/redirects
Redirect old top-level files to versioned docs
2 parents a0168ac + 08a0ec7 commit e8e37f7

File tree

2 files changed

+98
-22
lines changed

2 files changed

+98
-22
lines changed

matplotlib.org.yml

+19-17
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@
88
site_dir: "/usr/share/caddy"
99
tls_config: "tls /etc/caddy/tls/cert.pem /etc/caddy/tls/privkey.pem"
1010
repos:
11-
- mpl-brochure-site
12-
- matplotlib.github.com
13-
- basemap
14-
- cheatsheets
15-
- cycler
16-
- devdocs
17-
- governance
18-
- ipympl
19-
- matplotblog
20-
- mpl-bench
21-
- mpl-gui
22-
- mpl-sphinx-theme
23-
- mpl-third-party
24-
- pytest-mpl
25-
- data-prototype
11+
# Key is repo name, value is the site /path/ (which defaults to the repo
12+
# name if not set).
13+
mpl-brochure-site:
14+
matplotlib.github.com:
15+
basemap:
16+
cheatsheets:
17+
cycler:
18+
devdocs:
19+
governance:
20+
ipympl:
21+
matplotblog:
22+
mpl-bench:
23+
mpl-gui:
24+
mpl-sphinx-theme:
25+
mpl-third-party: thirdpartypackages
26+
pytest-mpl:
27+
data-prototype:
2628
vars_files:
2729
- files/webhook_vars.yml
2830
tasks:
@@ -162,7 +164,7 @@
162164
mode: 0755
163165
owner: caddy
164166
group: caddy
165-
loop: "{{ repos }}"
167+
loop: "{{ repos.keys() }}"
166168

167169
- name: Clone Git repositories
168170
become: true
@@ -174,7 +176,7 @@
174176
{{
175177
(item == 'matplotlib.github.com') | ternary('main', 'gh-pages')
176178
}}
177-
loop: "{{ repos }}"
179+
loop: "{{ repos.keys() }}"
178180

179181
# Caddy server setup
180182
# ##################

templates/Caddyfile.j2

+79-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
(subproject) {
44
# Caddy doesn't know this is a directory, so redirect to trailing / as
55
# would usually happen for them.
6-
redir /{args.0} /{args.0}/ permanent
6+
redir /{args[1]} /{args[1]}/ permanent
77

8-
handle_path /{args.0}/* {
9-
root * {{ caddy.site_dir }}/{args.0}
8+
handle_path /{args[1]}/* {
9+
root * {{ caddy.site_dir }}/{args[0]}
1010
try_files {path}.html {path}
1111
file_server {
1212
hide .git
@@ -70,8 +70,8 @@ http://{{ caddy.addresses.main }}, http://{{ ansible_fqdn }} {
7070

7171
root * {{ caddy.site_dir }}
7272

73-
{% for site in repos %}
74-
import subproject {{ site }}
73+
{% for site, path in repos.items() %}
74+
import subproject {{ site }} {{ path | default(site, true) }}
7575
{% endfor %}
7676

7777
# Hide mpl-altair until the site is fixed.
@@ -96,6 +96,16 @@ http://{{ caddy.addresses.main }}, http://{{ ansible_fqdn }} {
9696
}
9797
}
9898

99+
# Redirect the repo-named third-party packages path to the more-generic path.
100+
redir /3pp /thirdpartypackages/ # And also add a shortcut.
101+
@mpl-third-party path /mpl-third-party /mpl-third-party/*
102+
handle @mpl-third-party {
103+
route {
104+
uri strip_prefix /mpl-third-party
105+
redir * /thirdpartypackages{uri}
106+
}
107+
}
108+
99109
# Place the brochure site at the top level.
100110
@brochure file {
101111
root {{ caddy.site_dir }}/mpl-brochure-site
@@ -104,6 +114,70 @@ http://{{ caddy.addresses.main }}, http://{{ ansible_fqdn }} {
104114
rewrite / /mpl-brochure-site/index.html
105115
rewrite @brochure /mpl-brochure-site{http.matchers.file.relative}
106116

117+
# Redirect any of the old top-level files to the versioned docs.
118+
redir /citing.html /stable/project/citing.html permanent
119+
redir /contents.html /stable/users/ permanent
120+
redir /downloads.html /stable/users/installing/ permanent
121+
redir /gallery.html /stable/gallery/ permanent
122+
redir /py-modindex.html /stable/py-modindex.html permanent
123+
{# 3.5.0 was the last version to be synced to the top-level directory.
124+
We also try for stable, just to go to the best version possible. #}
125+
{%- with old_versions = [
126+
"stable",
127+
"3.5.0",
128+
"3.4.3", "3.4.2", "3.4.1", "3.4.0",
129+
"3.3.4", "3.3.3", "3.3.2", "3.3.1", "3.3.0",
130+
"3.2.2", "3.2.1", "3.2.0",
131+
"3.1.3", "3.1.1", "3.1.0",
132+
"3.0.3", "3.0.2", "3.0.0",
133+
"2.2.5", "2.2.4", "2.2.3", "2.2.2", "2.2.0",
134+
"2.1.2", "2.1.1", "2.1.0",
135+
"2.0.2", "2.0.1", "2.0.0",
136+
"1.5.3", "1.5.1", "1.5.0",
137+
"1.4.3", "1.4.2", "1.4.1", "1.4.0",
138+
"1.3.1", "1.3.0", "1.2.1",
139+
] %}
140+
{%- with old_toplevel_dirs = [
141+
"_downloads",
142+
"_images",
143+
"_modules",
144+
"_panels_static",
145+
"_sources",
146+
"_static",
147+
"api",
148+
"devel",
149+
"examples",
150+
"faq",
151+
"gallery",
152+
"glossary",
153+
"mpl_examples",
154+
"mpl_toolkits",
155+
"plot_directive",
156+
"plot_types",
157+
"pyplots",
158+
"resources",
159+
"tutorials",
160+
"users",
161+
] %}
162+
@old-toplevel-dirs {
163+
path{% for dir in old_toplevel_dirs %} /{{dir}} /{{dir}}/{% endfor +%}
164+
file {
165+
root {{ caddy.site_dir }}/matplotlib.github.com
166+
try_files{% for version in old_versions %} /{{version}}/{path}/index.html{% endfor +%}
167+
}
168+
}
169+
redir @old-toplevel-dirs {http.matchers.file.relative} permanent
170+
@old-toplevel-dir-contents {
171+
path{% for dir in old_toplevel_dirs %} /{{dir}}/*{% endfor +%}
172+
file {
173+
root {{ caddy.site_dir }}/matplotlib.github.com
174+
try_files{% for version in old_versions %} /{{version}}/{path}.html /{{version}}/{path}{% endfor +%}
175+
}
176+
}
177+
redir @old-toplevel-dir-contents {http.matchers.file.relative} permanent
178+
{%- endwith -%}
179+
{%- endwith +%}
180+
107181
# Finally try any of the versioned docs.
108182
handle {
109183
root * {{ caddy.site_dir }}/matplotlib.github.com

0 commit comments

Comments
 (0)