Revert to single HTML generator and parametrize excludeClasses

This commit is contained in:
Jérôme Petazzoni
2017-10-12 09:53:14 +02:00
parent c4d76ba367
commit 3369005e06
6 changed files with 36 additions and 13 deletions

View File

@@ -1,3 +1,5 @@
workshop.md: workshop.yml *.md
./markmaker.py < workshop.yml > workshop.md
# open http://localhost:8888/workshop.html
workshop.html:
%.html: %.yml *.md workshop.html
./markmaker.py < $< > $@ || rm $@
# open $@

View File

@@ -1,3 +1,7 @@
exclude:
- self-paced
- snap
chapters:
- |
class: title

View File

@@ -1,3 +1,7 @@
exclude:
- self-paced
- snap
chapters:
- |
class: title

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env python
# transforms a YAML manifest into a MARKDOWN workshop file
# transforms a YAML manifest into a HTML workshop file
import glob
import logging
@@ -19,15 +19,26 @@ class InvalidChapter(ValueError):
ValueError.__init__(self, "Invalid chapter: {!r}".format(chapter))
def yaml2markdown(inf, outf):
manifest = yaml.load(inf)
def generatefromyaml(manifest):
manifest = yaml.load(manifest)
markdown, titles = processchapter(manifest["chapters"])
logging.debug(titles)
toc = gentoc(titles)
markdown = markdown.replace("@@TOC@@", toc)
for (s1,s2) in manifest.get("variables", {}).items():
markdown = markdown.replace(s1, s2)
outf.write(markdown)
exclude = manifest.get("exclude", [])
logging.debug("exclude={!r}".format(exclude))
if not exclude:
logging.warning("'exclude' is empty.")
exclude = ",".join('"{}"'.format(c) for c in exclude)
html = open("workshop.html").read()
html = html.replace("@@MARKDOWN@@", markdown)
html = html.replace("@@EXCLUDE@@", exclude)
return html
def gentoc(titles, depth=0, chapter=0):
@@ -65,7 +76,6 @@ def processchapter(chapter):
if "\n" in chapter:
return (chapter, findtitles(chapter))
if os.path.isfile(chapter):
mdfiles.remove(chapter)
return processchapter(open(chapter).read())
if isinstance(chapter, list):
chapters = [processchapter(c) for c in chapter]
@@ -75,6 +85,4 @@ def processchapter(chapter):
raise InvalidChapter(chapter)
mdfiles = set(glob.glob("*.md"))
yaml2markdown(sys.stdin, sys.stdout)
logging.debug("The following files were unused: {}".format(mdfiles))
sys.stdout.write(generatefromyaml(sys.stdin))

View File

@@ -1,3 +1,6 @@
exclude:
- in-person
chapters:
- |
class: title

View File

@@ -7,6 +7,7 @@
<link rel="stylesheet" href="workshop.css">
</head>
<body>
<!--
<div style="position: absolute; left: 20%; right: 20%; top: 30%;">
<h1 style="font-size: 3em;">Loading ...</h1>
The slides should show up here. If they don't, it might be
@@ -20,14 +21,15 @@
Once the slides are loaded, this notice disappears when you
go full screen (e.g. by hitting "f").
</div>
-->
<textarea id="source">@@MARKDOWN@@</textarea>
<script src="remark.min.js" type="text/javascript">
</script>
<script type="text/javascript">
var slideshow = remark.create({
sourceUrl: 'workshop.md',
ratio: '16:9',
highlightSpans: true,
excludedClasses: ["self-paced", "snap"]
excludedClasses: [@@EXCLUDE@@]
});
</script>
</body>