mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-07 03:40:27 +00:00
doc: continue doc restructuring
Changing the folder structure will cause too many broken links for external references (from other sites). So, let's put the content back where it was before the reorg, and instead use the new persona-based navigation to point to documents in the original locations. Also, introduce redirects for some documents that no longer exits. Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
This commit is contained in:
committed by
David Kinder
parent
901a65cb53
commit
e2d3653976
74
doc/extensions/html_redirects.py
Normal file
74
doc/extensions/html_redirects.py
Normal file
@@ -0,0 +1,74 @@
|
||||
# Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
|
||||
# Mechanism to generate static HTML redirect pages in the output
|
||||
#
|
||||
# Uses redirect_template.html and the list of pages given in
|
||||
# conf.html_redirect_pages
|
||||
#
|
||||
# Adapted from ideas in https://tech.signavio.com/2017/managing-sphinx-redirects
|
||||
import os.path
|
||||
|
||||
from sphinx.builders.html import StandaloneHTMLBuilder
|
||||
|
||||
REDIRECT_TEMPLATE = """
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0; url=$NEWURL" />
|
||||
<script>
|
||||
window.location.href = "$NEWURL"
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p>Page has moved <a href="$NEWURL">here</a>.</p>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
|
||||
def setup(app):
|
||||
app.add_config_value('html_redirect_pages', [], 'html')
|
||||
app.connect('build-finished', create_redirect_pages)
|
||||
|
||||
# Since we're just setting up a build-finished hook, which runs
|
||||
# after both reading and writing, this extension is safe for both.
|
||||
return {
|
||||
'parallel_read_safe': True,
|
||||
'parallel_write_safe': True,
|
||||
}
|
||||
|
||||
|
||||
def create_redirect_pages(app, docname):
|
||||
if not isinstance(app.builder, StandaloneHTMLBuilder):
|
||||
return # only relevant for standalone HTML output
|
||||
|
||||
for (old_url, new_url) in app.config.html_redirect_pages:
|
||||
if old_url.startswith('/'):
|
||||
old_url = old_url[1:]
|
||||
print("Creating redirect: %s.html to %s.html" % (old_url, new_url))
|
||||
|
||||
new_url = app.builder.get_relative_uri(old_url, new_url)
|
||||
out_file = app.builder.get_outfilename(old_url)
|
||||
|
||||
out_dir = os.path.dirname(out_file)
|
||||
if not os.path.exists(out_dir):
|
||||
os.makedirs(out_dir)
|
||||
|
||||
content = REDIRECT_TEMPLATE.replace("$NEWURL", new_url)
|
||||
|
||||
if not os.path.exists(out_file):
|
||||
with open(out_file, "w") as rp:
|
||||
rp.write(content)
|
Reference in New Issue
Block a user