Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect old top-level files to versioned docs #41

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions matplotlib.org.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@
site_dir: "/usr/share/caddy"
tls_config: "tls /etc/caddy/tls/cert.pem /etc/caddy/tls/privkey.pem"
repos:
- mpl-brochure-site
- matplotlib.github.com
- basemap
- cheatsheets
- cycler
- devdocs
- governance
- ipympl
- matplotblog
- mpl-bench
- mpl-gui
- mpl-sphinx-theme
- mpl-third-party
- pytest-mpl
- data-prototype
# Key is repo name, value is the site /path/ (which defaults to the repo
# name if not set).
mpl-brochure-site:
matplotlib.github.com:
basemap:
cheatsheets:
cycler:
devdocs:
governance:
ipympl:
matplotblog:
mpl-bench:
mpl-gui:
mpl-sphinx-theme:
mpl-third-party: thirdpartypackages
pytest-mpl:
data-prototype:
vars_files:
- files/webhook_vars.yml
tasks:
Expand Down Expand Up @@ -162,7 +164,7 @@
mode: 0755
owner: caddy
group: caddy
loop: "{{ repos }}"
loop: "{{ repos.keys() }}"

- name: Clone Git repositories
become: true
Expand All @@ -174,7 +176,7 @@
{{
(item == 'matplotlib.github.com') | ternary('main', 'gh-pages')
}}
loop: "{{ repos }}"
loop: "{{ repos.keys() }}"

# Caddy server setup
# ##################
Expand Down
84 changes: 79 additions & 5 deletions templates/Caddyfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
(subproject) {
# Caddy doesn't know this is a directory, so redirect to trailing / as
# would usually happen for them.
redir /{args.0} /{args.0}/ permanent
redir /{args[1]} /{args[1]}/ permanent

handle_path /{args.0}/* {
root * {{ caddy.site_dir }}/{args.0}
handle_path /{args[1]}/* {
root * {{ caddy.site_dir }}/{args[0]}
try_files {path}.html {path}
file_server {
hide .git
Expand Down Expand Up @@ -70,8 +70,8 @@ http://{{ caddy.addresses.main }}, http://{{ ansible_fqdn }} {

root * {{ caddy.site_dir }}

{% for site in repos %}
import subproject {{ site }}
{% for site, path in repos.items() %}
import subproject {{ site }} {{ path | default(site, true) }}
{% endfor %}

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

# Redirect the repo-named third-party packages path to the more-generic path.
redir /3pp /thirdpartypackages/ # And also add a shortcut.
@mpl-third-party path /mpl-third-party /mpl-third-party/*
handle @mpl-third-party {
route {
uri strip_prefix /mpl-third-party
redir * /thirdpartypackages{uri}
}
}

# Place the brochure site at the top level.
@brochure file {
root {{ caddy.site_dir }}/mpl-brochure-site
Expand All @@ -104,6 +114,70 @@ http://{{ caddy.addresses.main }}, http://{{ ansible_fqdn }} {
rewrite / /mpl-brochure-site/index.html
rewrite @brochure /mpl-brochure-site{http.matchers.file.relative}

# Redirect any of the old top-level files to the versioned docs.
redir /citing.html /stable/project/citing.html permanent
redir /contents.html /stable/users/ permanent
redir /downloads.html /stable/users/installing/ permanent
redir /gallery.html /stable/gallery/ permanent
redir /py-modindex.html /stable/py-modindex.html permanent
{# 3.5.0 was the last version to be synced to the top-level directory.
We also try for stable, just to go to the best version possible. #}
{%- with old_versions = [
"stable",
"3.5.0",
"3.4.3", "3.4.2", "3.4.1", "3.4.0",
"3.3.4", "3.3.3", "3.3.2", "3.3.1", "3.3.0",
"3.2.2", "3.2.1", "3.2.0",
"3.1.3", "3.1.1", "3.1.0",
"3.0.3", "3.0.2", "3.0.0",
"2.2.5", "2.2.4", "2.2.3", "2.2.2", "2.2.0",
"2.1.2", "2.1.1", "2.1.0",
"2.0.2", "2.0.1", "2.0.0",
"1.5.3", "1.5.1", "1.5.0",
"1.4.3", "1.4.2", "1.4.1", "1.4.0",
"1.3.1", "1.3.0", "1.2.1",
] %}
{%- with old_toplevel_dirs = [
"_downloads",
"_images",
"_modules",
"_panels_static",
"_sources",
"_static",
"api",
"devel",
"examples",
"faq",
"gallery",
"glossary",
"mpl_examples",
"mpl_toolkits",
"plot_directive",
"plot_types",
"pyplots",
"resources",
"tutorials",
"users",
] %}
@old-toplevel-dirs {
path{% for dir in old_toplevel_dirs %} /{{dir}} /{{dir}}/{% endfor +%}
file {
root {{ caddy.site_dir }}/matplotlib.github.com
try_files{% for version in old_versions %} /{{version}}/{path}/index.html{% endfor +%}
}
}
redir @old-toplevel-dirs {http.matchers.file.relative} permanent
@old-toplevel-dir-contents {
path{% for dir in old_toplevel_dirs %} /{{dir}}/*{% endfor +%}
file {
root {{ caddy.site_dir }}/matplotlib.github.com
try_files{% for version in old_versions %} /{{version}}/{path}.html /{{version}}/{path}{% endfor +%}
}
}
redir @old-toplevel-dir-contents {http.matchers.file.relative} permanent
{%- endwith -%}
{%- endwith +%}

# Finally try any of the versioned docs.
handle {
root * {{ caddy.site_dir }}/matplotlib.github.com
Expand Down
Loading