From 674748086931ab6e8715d9f8f70eb79017f631e8 Mon Sep 17 00:00:00 2001 From: AJ Bowen Date: Sat, 28 May 2016 20:52:21 -0700 Subject: [PATCH] Add a script to extract section titles --- www/extract-section-titles.py | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 www/extract-section-titles.py diff --git a/www/extract-section-titles.py b/www/extract-section-titles.py new file mode 100755 index 00000000..ad0e608b --- /dev/null +++ b/www/extract-section-titles.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +""" +Extract and print level 1 and 2 titles from workshop slides. +""" + +with open("htdocs/index.html", "r") as f: + data = f.read() + +# @jpetazzo abuses "class: title" to make a point sometimes +skip = [ + "Why?", + "---", + "But ...", + "WHY?!?", +] + +# Ditch linebreaks from main section titles +replace = [ + "
", +] + +# remove blank lines +sections = [x for x in data.split('\n') if x] # and x not in skip] +sections = "\n".join(sections) +sections = sections.split('class: title') +del(sections[0]) # delete the CSS frontmatter + +for section in sections: + lines = [x for x in section.split("\n") if x] + + if lines[0] not in skip: + title = lines[0] + title = title.replace("
", "") + title = title.replace("# ", "") + del(lines[0]) + print("{}".format(title)) + + titles = [x[2:] for x in lines if x.startswith("# ")] + for title in titles: + print("\t{}".format(title))