From f07e5bf5222a3bfc5ce2a86edad829bb02e84601 Mon Sep 17 00:00:00 2001 From: Peter Molnar Date: Wed, 29 May 2019 21:34:47 +0200 Subject: [PATCH] moved hardcoded rss, atom, json, etc. filenames into settings and template variables --- nasg.py | 24 +++++++++++++----------- settings.py | 4 +++- templates/Category.j2.html | 7 ++++--- templates/Home.j2.html | 8 ++++---- templates/Singular.j2.html | 16 +++++++++++----- templates/base.j2.html | 4 +++- 6 files changed, 38 insertions(+), 25 deletions(-) diff --git a/nasg.py b/nasg.py index f98d570..79dc2cf 100644 --- a/nasg.py +++ b/nasg.py @@ -998,11 +998,13 @@ class Singular(MarkdownDoc): 'site': settings.site, 'menu': settings.menu, 'meta': settings.meta, + 'fnames': settings.filenames } writepath( self.renderfile, J2.get_template(self.template).render(v) ) + del(v) g = { 'post': self.jsonld, @@ -1013,27 +1015,27 @@ class Singular(MarkdownDoc): self.gopherfile, J2.get_template(self.gophertemplate).render(g) ) + del(g) j = settings.site.copy() j.update({ "mainEntity": self.jsonld }) writepath( - os.path.join(self.renderdir, 'index.json'), + os.path.join(self.renderdir, settings.filenames.json), json.dumps(j, indent=4, ensure_ascii=False) ) del(j) # oembed writepath( - os.path.join(self.renderdir, 'oembed.json'), + os.path.join(self.renderdir, settings.filenames.oembed_json), json.dumps(self.oembed_json, indent=4, ensure_ascii=False) ) writepath( - os.path.join(self.renderdir, 'oembed.xml'), + os.path.join(self.renderdir, settings.filenames.oembed_xml), self.oembed_xml ) - class Home(Singular): def __init__(self, fpath): super().__init__(fpath) @@ -1078,9 +1080,6 @@ class Home(Singular): ) lines.append(line) lines.append('') - #lines.append('') - #lines = lines + list(settings.bye.split('\n')) - #lines.append('') writepath( self.renderfile.replace( settings.filenames.html, @@ -1099,7 +1098,8 @@ class Home(Singular): 'site': settings.site, 'menu': settings.menu, 'meta': settings.meta, - 'posts': self.posts + 'posts': self.posts, + 'fnames': settings.filenames }) writepath(self.renderfile, r) await self.render_gopher() @@ -1864,6 +1864,7 @@ class Category(dict): 'years': self.years, }, 'posts': posts, + 'fnames': settings.filenames } def indexfpath(self, subpath=None, fname=settings.filenames.html): @@ -1880,14 +1881,15 @@ class Category(dict): ) async def render_feed(self, xmlformat): + if 'json' == xmlformat: + await self.render_json() + return + logger.info( 'rendering category "%s" %s feed', self.name, xmlformat ) - if 'json' == xmlformat: - await self.render_json() - return start = 0 end = int(settings.pagination) diff --git a/settings.py b/settings.py index d83cf72..8fe3b63 100644 --- a/settings.py +++ b/settings.py @@ -176,7 +176,9 @@ filenames = struct({ 'md': 'index.md', 'txt': 'index.txt', 'html': 'index.html', - 'gopher': 'gophermap' + 'gopher': 'gophermap', + 'oembed_xml': 'oembed.xml', + 'oembed_json': 'oembed.json' }) photo = struct({ diff --git a/templates/Category.j2.html b/templates/Category.j2.html index 6d84470..4f35b0c 100644 --- a/templates/Category.j2.html +++ b/templates/Category.j2.html @@ -3,9 +3,10 @@ {% block title %}{{ category.title }}{% endblock %} {% block meta %} - - - + + + + {% endblock %} diff --git a/templates/Home.j2.html b/templates/Home.j2.html index fce1efb..d3777a4 100644 --- a/templates/Home.j2.html +++ b/templates/Home.j2.html @@ -7,10 +7,10 @@ - - - - + + + + {% endblock %} {% block content %} diff --git a/templates/Singular.j2.html b/templates/Singular.j2.html index d5c11fc..3e69fff 100644 --- a/templates/Singular.j2.html +++ b/templates/Singular.j2.html @@ -7,11 +7,10 @@ {% block meta %} - - - - - + + + + @@ -19,6 +18,13 @@ + {% if post.image is iterable %} diff --git a/templates/base.j2.html b/templates/base.j2.html index 28651f3..7e8da10 100644 --- a/templates/base.j2.html +++ b/templates/base.j2.html @@ -8,12 +8,14 @@ + {% for key, value in meta.items() %} {% endfor %} {% block meta %}{% endblock %} + @@ -26,7 +28,7 @@ - +