mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 08:34:37 +08:00
Strip breadcrumbs from the documentation
Change-Id: I2a1469844e5a20eecdd735f38d68e571fce3f3fa
This commit is contained in:
+60
-25
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/python
|
||||
# encoding: utf-8
|
||||
#
|
||||
# Ceres Solver - A fast non-linear least squares minimizer
|
||||
# Copyright 2013 Google Inc. All rights reserved.
|
||||
# Copyright 2014 Google Inc. All rights reserved.
|
||||
# http://code.google.com/p/ceres-solver/
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -40,42 +41,76 @@ import sys
|
||||
N = len(sys.argv)
|
||||
|
||||
if N < 3:
|
||||
print "make_docs.py src_root destination_root"
|
||||
print 'make_docs.py src_root destination_root'
|
||||
sys.exit(1)
|
||||
|
||||
src_dir = sys.argv[1] + "/docs/source"
|
||||
src_dir = sys.argv[1] + '/docs/source'
|
||||
build_root = sys.argv[2]
|
||||
cache_dir = build_root + "/doctrees"
|
||||
html_dir = build_root + "/html"
|
||||
cache_dir = build_root + '/doctrees'
|
||||
html_dir = build_root + '/html'
|
||||
|
||||
# Called from Command Line
|
||||
if N == 3:
|
||||
sphinx_exe = "sphinx-build"
|
||||
sphinx_exe = 'sphinx-build'
|
||||
|
||||
# Called from CMake (using the SPHINX_EXECUTABLE found)
|
||||
elif N == 4:
|
||||
sphinx_exe = sys.argv[3]
|
||||
|
||||
# Run Sphinx to build the documentation.
|
||||
os.system("%s -b html -d %s %s %s" %(sphinx_exe, cache_dir, src_dir, html_dir))
|
||||
os.system('%s -b html -d %s %s %s' %(sphinx_exe, cache_dir, src_dir, html_dir))
|
||||
|
||||
input_pattern = """config=TeX-AMS-MML_HTMLorMML"></script>"""
|
||||
output_pattern = """config=TeX-AMS_HTML">
|
||||
MathJax.Hub.Config({
|
||||
"HTML-CSS": {
|
||||
availableFonts: ["TeX"]
|
||||
}
|
||||
});
|
||||
</script>"""
|
||||
replacements = [
|
||||
# By default MathJax uses does not use TeX fonts. This simple search
|
||||
# and replace fixes that.
|
||||
('''config=TeX-AMS-MML_HTMLorMML"></script>''',
|
||||
'''config=TeX-AMS_HTML">
|
||||
MathJax.Hub.Config({
|
||||
"HTML-CSS": {
|
||||
availableFonts: ["TeX"]
|
||||
}
|
||||
});
|
||||
</script>'''),
|
||||
|
||||
# By default MathJax uses does not use TeX fonts. This simple search
|
||||
# and replace fixes that.
|
||||
for name in glob.glob("%s/*.html" % html_dir):
|
||||
print "Postprocessing: ", name
|
||||
fptr = open(name)
|
||||
out = fptr.read().replace(input_pattern, output_pattern)
|
||||
fptr.close()
|
||||
# The title for the homepage is not ideal, so change it.
|
||||
('<title>Ceres Solver — Ceres Solver</title>',
|
||||
'<title>Ceres Solver — A Nonlinear Least Squares Minimizer</title>')
|
||||
]
|
||||
|
||||
fptr = open(name, "w")
|
||||
fptr.write(out)
|
||||
fptr.close()
|
||||
# This is a nasty hack to strip the breadcrumb navigation. A better strategy is
|
||||
# to fork the upstream template, but that is no fun either. Whitespace matters!
|
||||
# This doesn't use regular expressions since the escaping makes it untenable.
|
||||
breadcrumb_start = \
|
||||
'''<div role="navigation" aria-label="breadcrumbs navigation">
|
||||
<ul class="wy-breadcrumbs">
|
||||
<li><a href="index.html">Docs</a> »</li>
|
||||
|
||||
<li>'''
|
||||
|
||||
breadcrumb_end = \
|
||||
'''</li>
|
||||
<li class="wy-breadcrumbs-aside">
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
<hr/>
|
||||
</div>'''
|
||||
|
||||
for name in glob.glob('%s/*.html' % html_dir):
|
||||
print 'Postprocessing: ', name
|
||||
with open(name) as fptr:
|
||||
out = fptr.read()
|
||||
|
||||
for input_pattern, output_pattern in replacements:
|
||||
out = out.replace(input_pattern, output_pattern)
|
||||
|
||||
try:
|
||||
pre_breadcrumb_start, post_breadcrumb_start = out.split(breadcrumb_start)
|
||||
title, post_breadcrumb_end = post_breadcrumb_start.split(breadcrumb_end)
|
||||
print 'Stripping breadcrumb for -', title
|
||||
out = pre_breadcrumb_start + post_breadcrumb_end
|
||||
except ValueError:
|
||||
print 'Skipping breadcrumb strip for', name
|
||||
|
||||
with open(name, 'w') as fptr:
|
||||
fptr.write(out)
|
||||
|
||||
Reference in New Issue
Block a user