From c9b28af1abd3753a5dce33e51e26166b8e0f2255 Mon Sep 17 00:00:00 2001 From: Peter Molnar Date: Sun, 4 Nov 2018 14:40:44 +0100 Subject: [PATCH] merging copy pasted code + fixing typo problem --- nasg.py | 35 ++++++++++++++--------------------- templates/base.j2.html | 4 ++-- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/nasg.py b/nasg.py index 444f94b..6649264 100644 --- a/nasg.py +++ b/nasg.py @@ -1185,6 +1185,7 @@ class Category(dict): def __init__(self, name=''): self.name = name self.page = 1 + self.trange = 'YYYY' def __setitem__(self, key, value): if key in self: @@ -1197,14 +1198,6 @@ class Category(dict): ) dict.__setitem__(self, key, value) - # TODO - # - find all months posts were made on - # - use this to iterate - # - make a function to query per month - # - make archives based on this - # - instead of plain numbers, use YYYY-MM - # - feed still needs last X - def get_posts(self, start=0, end=-1): return [ self[k].tmplvars @@ -1253,21 +1246,22 @@ class Category(dict): else: return settings.paths.get('build') + def navlink(self, ts): + return { + 'url': "%s%s/" % (self.url, ts.format(self.trange)), + 'label': ts.format(self.trange) + } + def tmplvars(self, posts=[], c=False, p=False, n=False): if p: - p = { - 'url': "%s%s/" % (self.url, p.format('YYYY')), - 'label': p.format('YYYY') - } + p = self.navlink(p) if n: - n = { - 'url': "%s%s/" % (self.url, n.format('YYYY')), - 'label': n.format('YYYY') - } + n = self.navlink(n) if not c: - c = self[0].published.format('YYYY') + post = self[list(self.keys()).pop()] + c = post.published.format(self.trange) return { 'site': settings.site, @@ -1462,10 +1456,9 @@ class Category(dict): await self.render_flat() return - time_format = 'YYYY' by_time = {} for key in self.sortedkeys: - trange = arrow.get(key).format(time_format) + trange = arrow.get(key).format(self.trange) if trange not in by_time: by_time.update({ trange: [] @@ -1474,12 +1467,12 @@ class Category(dict): keys = list(by_time.keys()) for p, c, n in zip([None]+keys[:-1], keys, keys[1:]+[None]): - if arrow.utcnow().format(time_format) == c.format(time_format): + if arrow.utcnow().format(self.trange) == c.format(self.trange): renderdir = self.renderdir else: renderdir = os.path.join( self.renderdir, - c.format(time_format) + c.format(self.trange) ) # if not os.path.isdir(renderdir): diff --git a/templates/base.j2.html b/templates/base.j2.html index bcd3c4f..4ac49b6 100644 --- a/templates/base.j2.html +++ b/templates/base.j2.html @@ -20,10 +20,10 @@