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 ++++++++++++++++++++-------------------------- src/about.rst | 3 ++- src/templates/journal.html | 5 ----- src/templates/layout.html | 5 +++++ src/templates/page.html | 5 ----- 5 files changed, 31 insertions(+), 43 deletions(-) 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() diff --git a/src/about.rst b/src/about.rst index c2d280e..07687e2 100644 --- a/src/about.rst +++ b/src/about.rst @@ -1,5 +1,6 @@ .. frontmatter - title: About me + title: ~/about + header: About me date: 2014-10-14 author: Johannes Löthberg diff --git a/src/templates/journal.html b/src/templates/journal.html index 0269d2e..9f301b1 100644 --- a/src/templates/journal.html +++ b/src/templates/journal.html @@ -1,11 +1,6 @@ {% extends 'layout.html' %} {% block content %} -
-{% include 'nav.html' %} -

The lost journal

-
- {% for entry in entries %}
diff --git a/src/templates/layout.html b/src/templates/layout.html index 45ab99d..c91aa94 100644 --- a/src/templates/layout.html +++ b/src/templates/layout.html @@ -10,6 +10,11 @@ title="Johannes Löthberg "> +
+{% include 'nav.html' %} +

{{ header }}

+
+ {% block content %}{% endblock %}