Skip to content
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
17 changes: 13 additions & 4 deletions maintainer/deploy_docs_via_travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,26 @@ git remote add upstream "https://${GH_TOKEN}@${GH_REPOSITORY}"
git fetch --depth 50 upstream ${GH_DOC_BRANCH} gh-pages
git reset upstream/gh-pages

# for dev, latest, home redirects
mkdir dev latest
# === REDIRECTS AND COPIES ====
# home (index.html) redirects to stable/
# latest (latest/index.html) redirects to most recent release
# dev/ is a copy of the dev docs with the highest number (so 2.0.0-dev instead of 1.0.1-dev)
# stable/ is a copy of the release docs with the highest number
mkdir latest
export URL="https://docs.mdanalysis.org"
python ${MAINTAIN_DIR}/update_json_stubs_sitemap.py
touch .
touch .nojekyll

git add -A ${VERSION}/
git add .nojekyll versions.json
git add index.html dev latest
git add *.xml
git add index.html latest

for dirname in dev stable documentation_pages ; do
if [ -d $dirname ]; then git add $dirname; fi
done

git add *.xml *.html

# check for anything to commit
# https://stackoverflow.com/questions/3878624/how-do-i-programmatically-determine-if-there-are-uncommited-changes
Expand Down
71 changes: 52 additions & 19 deletions maintainer/update_json_stubs_sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import errno
import glob
import textwrap
import shutil

try:
from urllib.request import Request, urlopen
Expand Down Expand Up @@ -76,9 +77,10 @@ def write_redirect(file, version='', outfile=None):
already_exists = VERSION in existing
latest = 'dev' not in VERSION

if not already_exists and latest:
for ver in versions:
ver['latest'] = False
if not already_exists:
if latest:
for ver in versions:
ver['latest'] = False

versions.append({
'version': VERSION,
Expand All @@ -87,17 +89,6 @@ def write_redirect(file, version='', outfile=None):
'latest': latest
})

versions.sort(key=lambda x: x["version"])

with open("versions.json", 'w') as f:
json.dump(versions, f, indent=2)

# ========= WRITE HTML STUBS =========
# Add HTML files to redirect:
# index.html -> latest release
# latest/index.html -> latest release
# dev/index.html -> dev docs

for ver in versions[::-1]:
if ver['latest']:
latest_version = ver['version']
Expand All @@ -118,11 +109,23 @@ def write_redirect(file, version='', outfile=None):
except IndexError:
dev_version = None

versions.sort(key=lambda x: x["version"])

# ========= WRITE HTML STUBS AND COPY DOCS =========
# Add HTML files to redirect:
# index.html -> stable/ docs
# latest/index.html -> latest release (not dev docs)
# stable/ : a copy of the release docs with the highest number (2.0.0 instead of 1.0.0)
# dev/ : a copy of the develop docs with the highest number (2.0.0-dev instead of 1.0.1-dev)

if latest:
html_files = glob.glob(f'{VERSION}/**/*.html', recursive=True)
shutil.copytree(VERSION, "stable")
print(f"Copied {VERSION} to stable/")
html_files = glob.glob(f'stable/**/*.html', recursive=True)
for file in html_files:
outfile = file.strip(f'{VERSION}/')
# below should be true because we only globbed stable/* paths
assert file.startswith("stable/")
outfile = file[7:] # strip "stable/"
dirname = os.path.dirname(outfile)
if dirname and not os.path.exists(dirname):
try:
Expand All @@ -133,14 +136,44 @@ def write_redirect(file, version='', outfile=None):

write_redirect(file, '', outfile)



if latest_version:
write_redirect('index.html', latest_version)
write_redirect('objects.inv', latest_version, 'latest/objects.inv')
write_redirect('index.html', "stable")
write_redirect('index.html', latest_version, 'latest/index.html')
for ver in versions:
if ver["version"] == "stable":
ver["url"] = os.path.join(URL, "stable")
break
else:
versions.append({
"version": "stable",
"display": "stable",
"url": os.path.join(URL, "stable"),
"latest": False
})


if dev_version:
write_redirect('index.html', dev_version, 'dev/index.html')
if dev_version == VERSION:
shutil.copytree(VERSION, "dev")
print(f"Copied {VERSION} to dev/")

for ver in versions:
if ver["version"] == "dev":
ver["url"] = os.path.join(URL, "dev")
break
else:
versions.append({
"version": "dev",
"display": "dev",
"url": os.path.join(URL, "dev"),
"latest": False
})


with open("versions.json", 'w') as f:
json.dump(versions, f, indent=2)

# ========= WRITE SUPER SITEMAP.XML =========
# make one big sitemap.xml
Expand Down