From 86dbe9299ae33524e6da543a9af9b4d29c2f9fa3 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Sun, 23 Jun 2019 12:07:06 +1000 Subject: [PATCH] docs: Load page redirects from a file instead of inline in config --- docs/conf_common.py | 28 +++++++++------------------- docs/page_redirects.txt | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 docs/page_redirects.txt diff --git a/docs/conf_common.py b/docs/conf_common.py index 8bd4eb988..8fd13cbaf 100644 --- a/docs/conf_common.py +++ b/docs/conf_common.py @@ -18,6 +18,7 @@ from __future__ import print_function from __future__ import unicode_literals import sys import os +import re import subprocess # Note: If extensions (or modules to document with autodoc) are in another directory, @@ -235,25 +236,14 @@ pygments_style = 'sphinx' # Custom added feature to allow redirecting old URLs # -# list of tuples (old_url, new_url) for pages to redirect -# (URLs should be relative to document root, only) -html_redirect_pages = [('api-reference/ethernet/index', 'api-reference/network/index'), - ('api-reference/ethernet/esp_eth', 'api-reference/network/esp_eth'), - ('api-reference/mesh/index', 'api-reference/network/index'), - ('api-reference/mesh/esp_mesh', 'api-reference/network/esp_mesh'), - ('api-reference/wifi/index', 'api-reference/network/index'), - ('api-reference/wifi/esp_now', 'api-reference/network/esp_now'), - ('api-reference/wifi/esp_smartconfig', 'api-reference/network/esp_smartconfig'), - ('api-reference/wifi/esp_wifi', 'api-reference/network/esp_wifi'), - ('api-reference/system/tcpip_adapter', 'api-reference/network/tcpip_adapter'), - ('get-started/idf-monitor', 'api-guides/tools/idf-monitor'), - ('get-started-cmake/idf-monitor', 'api-guides/tools/idf-monitor'), - ('get-started/get-started-devkitc', 'hw-reference/get-started-devkitc'), - ('get-started/get-started-wrover-kit', 'hw-reference/get-started-wrover-kit'), - ('get-started/get-started-pico-kit', 'hw-reference/get-started-pico-kit'), - ('get-started-cmake/get-started-devkitc', 'hw-reference/get-started-devkitc'), - ('get-started-cmake/get-started-wrover-kit', 'hw-reference/get-started-wrover-kit'), - ('get-started-cmake/get-started-pico-kit', 'hw-reference/get-started-pico-kit')] +# Redirects should be listed in page_redirects.xt +# +with open("../page_redirects.txt") as f: + lines = [re.sub(" +", " ", l.strip()) for l in f.readlines() if l.strip() != "" and not l.startswith("#")] + for line in lines: # check for well-formed entries + if len(line.split(' ')) != 2: + raise RuntimeError("Invalid line in page_redirects.txt: %s" % line) +html_redirect_pages = [tuple(l.split(' ')) for l in lines] # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. diff --git a/docs/page_redirects.txt b/docs/page_redirects.txt new file mode 100644 index 000000000..c1ffdf139 --- /dev/null +++ b/docs/page_redirects.txt @@ -0,0 +1,25 @@ +# Redirects from "old URL" "new URL" +# +# Space delimited +# +# New URL should be relative to document root, only) +# +# Empty lines and lines starting with # are ignored + +api-reference/ethernet/index api-reference/network/index +api-reference/ethernet/esp_eth api-reference/network/esp_eth +api-reference/mesh/index api-reference/network/index +api-reference/mesh/esp_mesh api-reference/network/esp_mesh +api-reference/wifi/index api-reference/network/index +api-reference/wifi/esp_now api-reference/network/esp_now +api-reference/wifi/esp_smartconfig api-reference/network/esp_smartconfig +api-reference/wifi/esp_wifi api-reference/network/esp_wifi +api-reference/system/tcpip_adapter api-reference/network/tcpip_adapter +get-started/idf-monitor api-guides/tools/idf-monitor +get-started-cmake/idf-monitor api-guides/tools/idf-monitor +get-started/get-started-devkitc hw-reference/get-started-devkitc +get-started/get-started-wrover-kit hw-reference/get-started-wrover-kit +get-started/get-started-pico-kit hw-reference/get-started-pico-kit +get-started-cmake/get-started-devkitc hw-reference/get-started-devkitc +get-started-cmake/get-started-wrover-kit hw-reference/get-started-wrover-kit +get-started-cmake/get-started-pico-kit hw-reference/get-started-pico-kit