Commit 288510ca authored by Paul Asmuth's avatar Paul Asmuth
Browse files

build markdown documentation

parent b038f07b
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ if [[ ! $# -eq 1 ]]; then
  exit 1
fi

output_dir="$1"
export output_dir="$1"

if [[ ! -d "${output_dir}" ]]; then
  echo "error: directory does not exist: ${output_dir}" >&2
@@ -14,5 +14,7 @@ if [[ ! -d "${output_dir}" ]]; then
fi

cp extra/web/documentation.css "${output_dir}"
./extra/web/build_api_reference.py
./extra/web/build_pages.py
find "${output_dir}" -name "_*" -delete
./extra/web/build_api_reference.py > $1/index.html
+2 −1
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ def main():
    {{{html}}}
  """

  print(build_layout(TPL.render(tpl, {'html': html})))
  write_file("/_reference.gen.html", html)


main()
+27 −4
Original line number Diff line number Diff line
#!/usr/bin/env python3
import pystache as TPL
import yaml
import os
from pathlib import Path

tpl = """
<!DOCTYPE html>
@@ -15,8 +18,8 @@ tpl = """
        <a class="menu" href="http://github.com/plotfx/plotfx" target="_blank">Github</a>
        <a class="menu" href="/documentation/download">Download</a>
        <a class="menu active" href="/reference">API Reference</a>
        <a class="menu active" href="/">Documentation</a>
        <a class="menu" href="/examples">Examples</a>
        <a class="menu active" href="/">Documentation</a>
        <h1><a href="/">PlotFX</a></h1>
      </div>
    </div>
@@ -24,10 +27,20 @@ tpl = """
    <div class="doc_wrap">
      <div class="doc_container">
        <div id="navigation">
          {{#toc}}
            <a class="nav_title">{{title}}</a>
            <ul>
              {{#pages}}
                <li>
                  <a href="{{url}}">{{title}}</a>
                </li>
              {{/pages}}
            </ul>
          {{/toc}}
        </div>

        <div id="documentation">
          <a target="_blank" href="https://github.com/paulasmuth/plotfx/blob/master/doc/FIXME..md" style="float: right; margin-top:18px; font-size: 80%;">
          <a target="_blank" href="https://github.com/plotfx/plotfx/blob/master/manual" style="float: right; margin-top:18px; font-size: 80%;">
            Edit this page on GitHub
          </a>

@@ -46,6 +59,16 @@ tpl = """
</html>
"""

def build_layout(content):
  return TPL.render(tpl, {'content': content})
def build_layout(url, content):
  toc = yaml.load(Path("manual/toc.yaml").read_text())["documentation"]
  return TPL.render(tpl, {"content": content, "url": url, "toc": toc})

def write_page(url, content):
  write_file(url + "/index.html", build_layout(url, content))

def write_file(path, content):
  output_path = os.environ["output_dir"] + path
  output_dir = Path(os.path.dirname(output_path))
  output_dir.mkdir(parents=True, exist_ok=True)
  with open(output_path, "w+") as f:
    f.write(content)
+41 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
from build_layout import *
import yaml
import markdown
from pathlib import Path
from mdx_gfm import GithubFlavoredMarkdownExtension
import re

def build_page(page):
  print("> Building page: %s" % page["url"])
  url = page["url"]
  path = "manual/" + page["file"] + ".md"

  if os.path.isfile(path):
    source = Path(path).read_text()
  else:
    source = "file not found"

  html = markdown.markdown(
      source,
      extensions=[GithubFlavoredMarkdownExtension()])

  html = re.sub(
      r'{%([^%]+)%}',
      lambda m: Path(os.path.join(os.environ["output_dir"], m[1])).read_text(),
      html)

  write_page(url, html)

def build_toc(toc):
  for page in toc:
    if "url" in page:
      build_page(page)
    if "pages" in page:
      build_toc(page["pages"])

def main():
  toc = yaml.load(Path("manual/toc.yaml").read_text())
  build_toc(toc["documentation"])

main()

manual/reference.md

0 → 100644
+4 −0
Original line number Diff line number Diff line
API Reference
=============

{%_reference.gen.html%}
Loading