Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 67 lines (47 sloc) 1.59 KB
#!/usr/bin/env python3
import os
import re
import sys
Update local Markdown files from Yokadi and files in the doc/
DOC_HEADER = """---
title: %s
layout: default
TITLE_RE = re.compile("^#", re.MULTILINE)
# Matches a Markdown link of the form: [Title](fileName)
LINK_RE = re.compile("\[(.*)\]\((.*)\)")
def copyDoc(title, src, dstDir):
with open(src) as fp:
content = open(src).read()
# Shift titles one level down because our template starts the document
# with a level1 title
content = TITLE_RE.sub("##", content)
with open(os.path.join(dstDir, os.path.basename(src)), "w") as fp:
fp.write(DOC_HEADER % title)
def main():
if len(sys.argv) != 3:
print("Usage: <path/to/yokadi/checkout> <path/to/>")
return 1
srcDir = sys.argv[1]
wwwDir = sys.argv[2]
docFileTmpl = os.path.join(wwwDir, "")
dstDoc = open(docFileTmpl.replace(".tmpl", ""), "w")
for line in open(docFileTmpl).readlines():
result =
if result:
title, fileName = result.groups(0)
copyDoc(title, os.path.join(srcDir, fileName), wwwDir)
# contains links to .md files, but must contain
# links to .html files
htmlFileName = os.path.basename(fileName).replace(".md", ".html")
line = line.replace(fileName, htmlFileName)
return 0
if __name__=="__main__":
# vi: ts=4 sw=4 et