From 965c9e67ef6f79b9cf72a01da03222a66d632569 Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Wed, 15 Oct 2014 10:45:58 +0100 Subject: templates use header for h1, Entry renamed to Page also merge build_about and build_index --- scripts/bupa | 56 ++++++++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 32 deletions(-) (limited to 'scripts') diff --git a/scripts/bupa b/scripts/bupa index eca289a..b982ec8 100755 --- a/scripts/bupa +++ b/scripts/bupa @@ -18,15 +18,16 @@ def filename_to_id(file_name): split('-')[0]. split('.')[0]) -class Entry(object): - def __init__(self, entry_dict): +class Page(object): + def __init__(self, page_dict): self.id = None - self.title = entry_dict['title'] - self.date = entry_dict['date'] - self.author = entry_dict['author'] - if 'author_link' in entry_dict: - self.author_link = entry_dict['author_link'] - self.body = entry_dict['body'][0] + 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: @@ -36,15 +37,16 @@ def parse(filename): frontmatter = frontmatter.partition('\n')[2] frontmatter = yaml.load(frontmatter) - entry_dict = frontmatter.copy() - entry_dict['body'] = body + page_dict = frontmatter.copy() + page_dict['body'] = body + if not 'header' in page_dict: + page_dict['header'] = page_dict['title'] - entry = Entry(entry_dict) - return entry + page = Page(page_dict) + return page def build_journal(env): template = env.get_template('journal.html') - files = os.listdir('src/journal') files.sort(key=filename_to_id, reverse=True) @@ -56,27 +58,17 @@ def build_journal(env): entries += [entry] with open('build/journal.html', 'w') as file: - file.write(template.render(entries=entries, title='~/journal')) - -def build_index(env): - template = env.get_template('page.html') - - page = parse('src/index.rst') - page.body = reST_to_html(page.body) - page.article_id = 'index' - - with open('build/index.html', 'w') as file: - file.write(template.render(page=page, title=page.title)) + file.write(template.render(entries=entries, title='~/journal', header='The lost journal')) -def build_about(env): - template = env.get_template('page.html') +def build_page(env, templ_name, pagename): + template = env.get_template(templ_name) - page = parse('src/about.rst') + page = parse('src/'+pagename+'.rst') page.body = reST_to_html(page.body) - page.article_id = 'about' + page.article_id = pagename - with open('build/about.html', 'w') as file: - file.write(template.render(page=page, title='~/about')) + 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__) @@ -85,9 +77,9 @@ def main(): if arguments[''] == 'journal.html': build_journal(env) elif arguments[''] == 'index.html': - build_index(env) + build_page(env, 'page.html', 'index') elif arguments[''] == 'about.html': - build_about(env) + build_page(env, 'page.html', 'about') if __name__ == '__main__': main() -- cgit v1.2.3-70-g09d2