diff options
Diffstat (limited to 'scripts/make_docs.py')
-rw-r--r-- | scripts/make_docs.py | 97 |
1 files changed, 69 insertions, 28 deletions
diff --git a/scripts/make_docs.py b/scripts/make_docs.py index efbbf88..f992d13 100644 --- a/scripts/make_docs.py +++ b/scripts/make_docs.py @@ -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,82 @@ 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)) - -input_pattern = """config=TeX-AMS-MML_HTMLorMML"></script>""" -output_pattern = """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() - - fptr = open(name, "w") - fptr.write(out) - fptr.close() +os.system('%s -b html -d %s %s %s' %(sphinx_exe, cache_dir, src_dir, html_dir)) + +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>'''), + + # 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>') +] + +# 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_other = \ +'''<div role="navigation" aria-label="breadcrumbs navigation"> + <ul class="wy-breadcrumbs"> + <li><a href="index.html">Docs</a> »</li> + + <li>''' + +# The index page has a slightly different breadcrumb. +breadcrumb_start_index = breadcrumb_start_other.replace('index.html', '#') + +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: + breadcrumb_start = breadcrumb_start_index \ + if name.endswith('index.html') \ + else breadcrumb_start_other + 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) |