summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJohannes Löthberg <johannes@kyriasis.com>2014-10-18 14:14:30 +0200
committerJohannes Löthberg <johannes@kyriasis.com>2014-10-18 14:14:30 +0200
commitb944832d593683e54c216d23bb493b302b521e29 (patch)
tree6c4376d642e8245a6a41e44d4a8e090a481185bb /scripts
parent80e38791f41cf326e43946e306157daa7d7e08e1 (diff)
downloadtheos-website-b944832d593683e54c216d23bb493b302b521e29.tar.xz
convert root page to reST like ~kyrias/
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/bupa74
1 files changed, 74 insertions, 0 deletions
diff --git a/scripts/bupa b/scripts/bupa
new file mode 100755
index 0000000..1fd06ff
--- /dev/null
+++ b/scripts/bupa
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+"""Usage: bupa <filename>
+
+Options:
+ -h --help Show this screen.
+"""
+from jinja2 import Environment, FileSystemLoader
+import glob, yaml, docopt
+
+from docutils import core
+from docutils.writers.html4css1 import Writer
+
+def reST_to_html(s):
+ return core.publish_parts(s, writer_name='html4css1')['html_body']
+
+def filename_to_id(file_name):
+ return int(file_name.split('/')[-1].
+ split('-')[0].
+ split('.')[0])
+
+class Page(object):
+ def __init__(self, page_dict):
+ self.id = None
+ self.title = page_dict['title']
+ self.header = page_dict['header']
+ self.date = page_dict['date']
+ self.author = page_dict['author']
+ if 'author_link' in page_dict:
+ self.author_link = page_dict['author_link']
+ self.body = page_dict['body'][0]
+
+def parse(filename):
+ with open(filename, 'r') as file:
+ data = file.read()
+
+ frontmatter, *body = data.split('\n\n', 1)
+ frontmatter = frontmatter.partition('\n')[2]
+ frontmatter = yaml.load(frontmatter)
+
+ page_dict = frontmatter.copy()
+ page_dict['body'] = body
+ if not 'header' in page_dict:
+ page_dict['header'] = page_dict['title']
+
+ page = Page(page_dict)
+ return page
+
+ with open('build/journal.html', 'w') as file:
+ file.write(template.render(entries=entries, title='~/journal', header='The lost journal'))
+
+def build_page(env, templ_name, pagename):
+ template = env.get_template(templ_name)
+
+ page = parse('src/'+pagename+'.rst')
+ page.body = reST_to_html(page.body)
+ page.article_id = pagename
+
+ with open('build/'+pagename+'.html', 'w') as file:
+ file.write(template.render(page=page, title=page.title, header=page.header))
+
+def main():
+ arguments = docopt.docopt(__doc__)
+ env = Environment(loader=FileSystemLoader('src/templates'))
+
+ if '<filename>' in arguments:
+ file = arguments['<filename>'].split('/')[-1]
+ else:
+ exit(2)
+
+ if file == 'index.html':
+ build_page(env, 'page.html', 'index')
+
+if __name__ == '__main__':
+ main()