From 75d7bb2acc90eb1c6daec66dc7b73573c643ce57 Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Thu, 16 Apr 2015 10:40:36 +0200 Subject: Generate sitemap programatically --- Makefile | 4 ---- scripts/bupa | 8 ++++++++ src/sitemap.xml | 15 --------------- src/templates/sitemap.xml | 20 ++++++++++++++++++++ 4 files changed, 28 insertions(+), 19 deletions(-) delete mode 100644 src/sitemap.xml create mode 100644 src/templates/sitemap.xml diff --git a/Makefile b/Makefile index d444268..0e3a90b 100644 --- a/Makefile +++ b/Makefile @@ -34,10 +34,6 @@ build/resources/%: src/resources/% @install -m644 $< $@ @echo Copied $< → $@ -build/sitemap.xml: src/sitemap.xml - @install -Dm644 $< $@ - @echo Copied $< → $@ - build/pgp-key.txt: src/pgp-key.txt @install -Dm644 $< $@ @echo Copied $< → $@ diff --git a/scripts/bupa b/scripts/bupa index 1208263..e87ca4c 100755 --- a/scripts/bupa +++ b/scripts/bupa @@ -104,6 +104,8 @@ def build_journal(jinja_env): with open('build/journal.atom', 'wb') as file: file.write(atom_feed.to_string().encode('utf-8')) + make_sitemap(jinja_env, entries) + def build_page(jinja_env, template, pagename): page = parse('src/'+pagename+'.rst') page.body = reST_to_html(page.body) @@ -116,6 +118,12 @@ def write_page(page, header, filename, template, jinja_env): rendered_page = template.render(page=page, title=page.title, header=header) file.write(rendered_page.encode('utf-8')) +def make_sitemap(jinja_env, entries): + template = jinja_env.get_template('sitemap.xml') + with open('build/sitemap.xml', 'wb') as f: + rendered = template.render(entries=entries) + f.write(rendered.encode('utf-8')) + def main(): arguments = docopt.docopt(__doc__, version='bupa 0.0.1') jinja_env = Environment(loader=FileSystemLoader('src/templates')) # something something jinja2 templates diff --git a/src/sitemap.xml b/src/sitemap.xml deleted file mode 100644 index e35ec27..0000000 --- a/src/sitemap.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - https://theos.kyriasis.com/~kyrias/index.html - - - https://theos.kyriasis.com/~kyrias/about.html - - - https://theos.kyriasis.com/~kyrias/journal.html - - - https://theos.kyriasis.com/~kyrias/pgp-key.txt - - diff --git a/src/templates/sitemap.xml b/src/templates/sitemap.xml new file mode 100644 index 0000000..d3943e4 --- /dev/null +++ b/src/templates/sitemap.xml @@ -0,0 +1,20 @@ + + + + https://theos.kyriasis.com/~kyrias/index.html + + + https://theos.kyriasis.com/~kyrias/about.html + + + https://theos.kyriasis.com/~kyrias/journal.html + + + https://theos.kyriasis.com/~kyrias/pgp-key.txt + +{% for entry in entries %} + + https://theos.kyriasis.com/~kyrias/journal/{{ entry.page }} + +{% endfor %} + -- cgit v1.2.3-70-g09d2