diff options
-rwxr-xr-x | scripts/build.py | 46 | ||||
-rw-r--r-- | templates/index.html | 18 |
2 files changed, 13 insertions, 51 deletions
diff --git a/scripts/build.py b/scripts/build.py index 2b6055d..560f503 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -8,36 +8,19 @@ from jinja2 import Environment, FileSystemLoader from utils.reST import reST_to_html -def build_entry(jenv, entry, older=None, newer=None): - entry_template = jenv.get_template('entry.html') - - source_file = 'entries/{}.rst'.format(entry['file']) - with open(source_file, 'r') as f: - source = f.read() - - rendered_source = reST_to_html(source) - - rendered = entry_template.render(entry=entry, - older=older, - newer=newer, - content=rendered_source) - with open('out/{}.html'.format(entry['file']), 'w+') as f: - f.write(rendered) - - -def build_index(jenv, entry, older=None): - index_template = jenv.get_template('index.html') - +def build_entry(jenv, fname, entry, older=None, newer=None): + template = jenv.get_template('entry.html') source_file = 'entries/{}.rst'.format(entry['file']) with open(source_file, 'r') as f: source = f.read() rendered_source = reST_to_html(source) - rendered = index_template.render(entry=entry, - older=older, - content=rendered_source) - with open('out/index.html', 'w+') as f: + rendered = template.render(entry=entry, + older=older, + newer=newer, + content=rendered_source) + with open('out/{}.html'.format(fname), 'w+') as f: f.write(rendered) @@ -78,16 +61,13 @@ if __name__ == '__main__': published, unpublished = split_entries(entries) for entry in unpublished: - build_entry(jenv, entry) + build_entry(jenv, entry['file'], entry) for index, entry in enumerate(published): - older = published[index:index-1] - newer = published[index:index+1] - build_entry(jenv, entry, older, newer) - - if len(published) > 1: - build_index(jenv, published[-1], published[-2]) - else: - build_index(jenv, published[-1], None) + older = published[index-1:index] + newer = published[index+1:index+2] + build_entry(jenv, entry['file'], entry, older, newer) + + build_entry(jenv, 'index', published[-1], older=published[-2:-1]) build_archive(jenv, published) diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index 628e078..0000000 --- a/templates/index.html +++ /dev/null @@ -1,18 +0,0 @@ -{% extends 'layout.html' %} - -{% block content %} -<article itemscope itemtype="http://schema.org/Article"> - <div> - <h1>{{ entry['title'] }}</h1> - <time itemprop="datePublished" datetime="{{ entry['date'] }}">{{ entry['date'] }}</time> - </div> - <div> - {{ content }} - </div> -</article> -{% if older %} -<div id="post-nav"> - <a class="older" href="{{ older['file'] }}.html">Older ({{ older['title'] }})</a> -</div> -{% endif %} -{% endblock %} |