Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Detect latest release, generate HTML redirection page
Browse files Browse the repository at this point in the history
  • Loading branch information
freetonik committed Jun 10, 2022
1 parent 566a351 commit 6e168b0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
author="Jan Holthuis",
author_email="[email protected]",
url="https://github.com/freetonik/sphinx-multiversion-contrib",
version="0.2.5",
version="0.2.6",
install_requires=["sphinx >= 2.1"],
license="BSD",
packages=["sphinx_multiversion"],
Expand Down
25 changes: 25 additions & 0 deletions sphinx_multiversion/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ def get_python_flags():
yield from ("-X", "{}={}".format(option, value))


def generate_html_redirection_page(path=''):
return fr'''<!-- This page is created automatically by documentation builder -->
<!DOCTYPE html>
<html>
<head>
<title>Redirecting to main branch docs</title>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=./{path}">
<link rel="canonical" href="./{path}">
</head>
</html>'''


def main(argv=None):
if not argv:
argv = sys.argv[1:]
Expand Down Expand Up @@ -219,6 +232,7 @@ def main(argv=None):
gitrefs = sorted(gitrefs, key=lambda x: (x.is_remote, *x))

logger = logging.getLogger(__name__)
released_versions = []

with tempfile.TemporaryDirectory() as tmp:
# Generate Metadata
Expand Down Expand Up @@ -291,6 +305,9 @@ def main(argv=None):
"docnames": list(project.discover()),
}

if metadata[gitref.name]['is_released']:
released_versions.append(gitref.name)

if args.dump_metadata:
print(json.dumps(metadata, indent=2))
return 0
Expand All @@ -299,6 +316,12 @@ def main(argv=None):
logger.error("No matching refs found!")
return 2

# Generate HTML page which redirects to latest released docs
html_file_path = os.path.abspath(os.path.join(sourcedir, "_static/index.html"))
with open(html_file_path, mode="w") as fp:
redirection_path = released_versions[-1] + "/index.html"
fp.write(generate_html_redirection_page(redirection_path))

# Write Metadata
metadata_path = os.path.abspath(os.path.join(tmp, "versions.json"))
with open(metadata_path, mode="w") as fp:
Expand All @@ -321,6 +344,8 @@ def main(argv=None):
[
*defines,
"-D",
"smv_latest_version={}".format(released_versions[-1]),
"-D",
"smv_current_version={}".format(version_name),
"-c",
confdir_absolute,
Expand Down

0 comments on commit 6e168b0

Please sign in to comment.