Rewrite original rst files with redirect text

Signed-off-by: James Munnelly <james@munnelly.eu>
This commit is contained in:
James Munnelly
2019-11-15 00:10:17 +00:00
parent ff75e6bcbf
commit a9006790b7
+12 -1
View File
@@ -16,6 +16,13 @@ TEMPLATE = """<html>
</html>
"""
SRC_TEMPLATE = """==========
File moved
==========
This document has moved to %s.
This placeholder file will be removed in a later release.
"""
def generate_external_redirects(app, exception):
logger = logging.getLogger(__name__)
@@ -48,7 +55,7 @@ def generate_external_redirects(app, exception):
with open(path) as redirects:
for line in redirects.readlines():
from_path, to_url = line.rstrip().split(' ')
orig_from_path = from_path
logger.info("Redirecting '%s' to '%s'" % (from_path, to_url))
if dirhtml:
@@ -67,6 +74,10 @@ def generate_external_redirects(app, exception):
with open(redirected_filename, 'w') as f:
f.write(TEMPLATE % to_url)
input_rst_filename = os.path.join(app.srcdir, orig_from_path)
with open(input_rst_filename, 'w') as f:
f.write(SRC_TEMPLATE % to_url)
def setup(app):
app.add_config_value('external_redirects_file', 'external_redirects', 'env')