-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create doc sitemap.xml for development site and fix for master deploy…
…ment - sitemap.xml is appropriate for the development docs: thus we do not ship and install a sitemap.xml that is misleading (when installing automatically via Travis CI) - change the loc in the sitemap.xml with the new maintainer/adapt_sitemap.py script: parse XML tree and replace the developer site URL prefix with the release doc prefix - manually create the release docs from master with the maintainer/deploy_master_docs.sh script (which is now calling the adapt_sitemap.py script)
- release-2.8.0
- release-2.7.0
- release-2.6.1
- release-2.6.0
- release-2.5.0
- release-2.4.3
- release-2.4.2
- release-2.4.1
- release-2.4.0
- release-2.3.0
- release-2.2.0
- release-2.1.0
- release-2.0.0
- release-2.0.0-beta
- release-1.1.1
- release-1.1.0
- release-1.0.1
- release-1.0.0
- release-0.20.1
- release-0.20.0
- release-0.19.2
- release-0.19.1
- release-0.19.0
- package-2.8.0
- package-2.7.0
- package-2.6.1
- package-2.6.0
- package-2.5.0
- package-2.4.3
- package-2.4.2
- package-2.4.1
- package-2.4.0
- package-2.4.0b1
- package-2.3.0
- package-2.2.0
- package-2.1.0
Showing
3 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env python | ||
# | ||
# | ||
# Adjust path in sitemap.xml | ||
|
||
from __future__ import print_function | ||
|
||
from xml.etree import ElementTree | ||
import argparse | ||
|
||
# defaults for MDAnalysis, see https://github.com/MDAnalysis/mdanalysis/pull/1890 | ||
# and https://github.com/MDAnalysis/MDAnalysis.github.io/issues/78 | ||
|
||
RELEASE_URL = "https://www.mdanalysis.org/docs/" | ||
DEVELOP_URL = "https://www.mdanalysis.org/mdanalysis/" | ||
|
||
# change if sitemaps.org updates their schema | ||
NAMESPACE = {"sitemaps": "http://www.sitemaps.org/schemas/sitemap/0.9"} | ||
|
||
def replace_loc(tree, search, replace, namespace=NAMESPACE): | ||
root = tree.getroot() | ||
urls = root.findall("sitemaps:url", namespace) | ||
if len(urls) == 0: | ||
raise ValueError("No sitemaps:url element found: check if the namespace in the XML file " | ||
"is still xmlns='{0[sitemaps]}'".format(namespace)) | ||
for url in urls: | ||
loc = url.find("sitemaps:loc", namespace) | ||
try: | ||
loc.text = loc.text.replace(search, replace) | ||
except AttributError: | ||
raise ValueError("No sitemaps:loc element found: check if the namespace in the XML file " | ||
"is still xmlns='{0[sitemaps]}'".format(namespace)) | ||
return tree | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description='Change top level loc in sitemap.', | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
|
||
parser.add_argument('sitemap', metavar="FILE", | ||
help="path to sitemap.xml file, will be changed in place") | ||
parser.add_argument('--output', '-o', metavar="FILE", | ||
default="sitemap_release.xml", | ||
help="write altered XML to output FILE") | ||
parser.add_argument("--search", "-s", metavar="URL", | ||
default=DEVELOP_URL, | ||
help="search this URL in the loc elements") | ||
parser.add_argument("--replace", "-r", metavar="URL", | ||
default=RELEASE_URL, | ||
help="replace the searched URL with this URL in the loc elements") | ||
args = parser.parse_args() | ||
|
||
|
||
with open(args.sitemap) as xmlfile: | ||
tree = ElementTree.parse(xmlfile) | ||
|
||
tree = replace_loc(tree, args.search, args.replace) | ||
|
||
with open(args.output, "wb") as xmlfile: | ||
tree.write(xmlfile, encoding="utf-8", xml_declaration=True, | ||
default_namespace=NAMESPACE['sitemaps']) | ||
|
||
print("adapt_sitemap.py: Created output file {} with change in loc:".format(args.output)) | ||
print("adapt_sitemap.py: {0} --> {1}".format(args.search, args.replace)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters