summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJohannes Löthberg <johannes@kyriasis.com>2014-10-21 13:45:31 +0200
committerJohannes Löthberg <johannes@kyriasis.com>2014-10-21 13:50:01 +0200
commit60c4449e6f0e98f76e1d428efb7f3f14c492fed5 (patch)
treeb83f4d158670d856b027401afc3b8050bb0daee2 /scripts
parentb984bf243f1f86700ea4af69213fa726fdd5daa9 (diff)
downloadwebsite-60c4449e6f0e98f76e1d428efb7f3f14c492fed5.tar.xz
open files in binary mode, encode/decode as utf-8
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/bupa20
1 files changed, 10 insertions, 10 deletions
diff --git a/scripts/bupa b/scripts/bupa
index ff8d5d1..6770b48 100755
--- a/scripts/bupa
+++ b/scripts/bupa
@@ -30,8 +30,8 @@ class Page(object):
self.body = page_dict['body'][0]
def parse(filename):
- with open(filename, 'r') as file:
- data = file.read()
+ with open(filename, 'rb') as file:
+ data = file.read().decode('utf-8')
frontmatter, *body = data.split('\n\n', 1)
frontmatter = frontmatter.partition('\n')[2]
@@ -69,9 +69,9 @@ def build_journal(env):
entry.page = file.split('/', 1)[1].split('.', 1)[0] + '.html'
entry.body = reST_to_html(entry.body)
entries += [entry]
- with open('build/'+entry.page, 'w') as file:
+ with open('build/'+entry.page, 'wb') as file:
file.write(entry_tmpl.render(entry=entry, title='~/journal',
- header='The lost journal'))
+ header='The lost journal').encode('utf-8'))
feed.add(
title=entry.title,
content=entry.body,
@@ -81,11 +81,11 @@ def build_journal(env):
updated=entry.date
)
- with open('build/journal.html', 'w') as file:
+ with open('build/journal.html', 'wb') as file:
file.write(template.render(entries=entries, title='~/journal',
- header='The lost journal'))
- with open('build/journal.xml', 'w') as file:
- file.write(feed.to_string())
+ header='The lost journal').encode('utf-8'))
+ with open('build/journal.xml', 'wb') as file:
+ file.write(feed.to_string().encode('utf-8'))
def build_page(env, templ_name, pagename):
template = env.get_template(templ_name)
@@ -94,8 +94,8 @@ def build_page(env, templ_name, pagename):
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))
+ with open('build/'+pagename+'.html', 'wb') as file:
+ file.write(template.render(page=page, title=page.title, header=page.header).encode('utf-8'))
def main():
arguments = docopt.docopt(__doc__)