summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Löthberg <johannes@kyriasis.com>2014-10-15 10:45:58 +0100
committerJohannes Löthberg <johannes@kyriasis.com>2014-10-15 18:40:45 +0100
commit965c9e67ef6f79b9cf72a01da03222a66d632569 (patch)
tree01de1b64ba61f01aa6f8c90c94392bc347ef8c7c
parent7979369ccf314d72b83347e53ba6915f511c855e (diff)
downloadwebsite-965c9e67ef6f79b9cf72a01da03222a66d632569.tar.xz
templates use header for h1, Entry renamed to Page
also merge build_about and build_index
-rwxr-xr-xscripts/bupa56
-rw-r--r--src/about.rst3
-rw-r--r--src/templates/journal.html5
-rw-r--r--src/templates/layout.html5
-rw-r--r--src/templates/page.html5
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['<filename>'] == 'journal.html':
build_journal(env)
elif arguments['<filename>'] == 'index.html':
- build_index(env)
+ build_page(env, 'page.html', 'index')
elif arguments['<filename>'] == '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 %}
- <header>
-{% include 'nav.html' %}
- <h1>The lost journal</h1>
- </header>
-
{% for entry in entries %}
<article itemscope itemtype="http://schema.org/Article"
class="entry" id="entry:{{ entry.id }}">
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 <johannes@kyriasis.com>">
</head>
<body itemscope itemtype="http://schema.org/WebPage">
+<header>
+{% include 'nav.html' %}
+ <h1>{{ header }}</h1>
+</header>
+
{% block content %}{% endblock %}
<footer>
<div id="foot-left">
diff --git a/src/templates/page.html b/src/templates/page.html
index 9e0dddc..3c5d29a 100644
--- a/src/templates/page.html
+++ b/src/templates/page.html
@@ -1,11 +1,6 @@
{% extends 'layout.html' %}
{% block content %}
- <header>
-{% include 'nav.html' %}
- <h1>{{ page.title }}</h1>
- </header>
-
<article id="{{ page.article_id }}" class="botborder" itemprop="mainContentOfPage">
{{ page.body }}