merging copy pasted code + fixing typo problem
This commit is contained in:
parent
5dd9cfb1f9
commit
c9b28af1ab
2 changed files with 16 additions and 23 deletions
35
nasg.py
35
nasg.py
|
@ -1185,6 +1185,7 @@ class Category(dict):
|
||||||
def __init__(self, name=''):
|
def __init__(self, name=''):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.page = 1
|
self.page = 1
|
||||||
|
self.trange = 'YYYY'
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
if key in self:
|
if key in self:
|
||||||
|
@ -1197,14 +1198,6 @@ class Category(dict):
|
||||||
)
|
)
|
||||||
dict.__setitem__(self, key, value)
|
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):
|
def get_posts(self, start=0, end=-1):
|
||||||
return [
|
return [
|
||||||
self[k].tmplvars
|
self[k].tmplvars
|
||||||
|
@ -1253,21 +1246,22 @@ class Category(dict):
|
||||||
else:
|
else:
|
||||||
return settings.paths.get('build')
|
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):
|
def tmplvars(self, posts=[], c=False, p=False, n=False):
|
||||||
if p:
|
if p:
|
||||||
p = {
|
p = self.navlink(p)
|
||||||
'url': "%s%s/" % (self.url, p.format('YYYY')),
|
|
||||||
'label': p.format('YYYY')
|
|
||||||
}
|
|
||||||
|
|
||||||
if n:
|
if n:
|
||||||
n = {
|
n = self.navlink(n)
|
||||||
'url': "%s%s/" % (self.url, n.format('YYYY')),
|
|
||||||
'label': n.format('YYYY')
|
|
||||||
}
|
|
||||||
|
|
||||||
if not c:
|
if not c:
|
||||||
c = self[0].published.format('YYYY')
|
post = self[list(self.keys()).pop()]
|
||||||
|
c = post.published.format(self.trange)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'site': settings.site,
|
'site': settings.site,
|
||||||
|
@ -1462,10 +1456,9 @@ class Category(dict):
|
||||||
await self.render_flat()
|
await self.render_flat()
|
||||||
return
|
return
|
||||||
|
|
||||||
time_format = 'YYYY'
|
|
||||||
by_time = {}
|
by_time = {}
|
||||||
for key in self.sortedkeys:
|
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:
|
if trange not in by_time:
|
||||||
by_time.update({
|
by_time.update({
|
||||||
trange: []
|
trange: []
|
||||||
|
@ -1474,12 +1467,12 @@ class Category(dict):
|
||||||
|
|
||||||
keys = list(by_time.keys())
|
keys = list(by_time.keys())
|
||||||
for p, c, n in zip([None]+keys[:-1], keys, keys[1:]+[None]):
|
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
|
renderdir = self.renderdir
|
||||||
else:
|
else:
|
||||||
renderdir = os.path.join(
|
renderdir = os.path.join(
|
||||||
self.renderdir,
|
self.renderdir,
|
||||||
c.format(time_format)
|
c.format(self.trange)
|
||||||
)
|
)
|
||||||
#
|
#
|
||||||
if not os.path.isdir(renderdir):
|
if not os.path.isdir(renderdir):
|
||||||
|
|
|
@ -20,10 +20,10 @@
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
var current = localStorage.getItem("stylesheet");
|
var current = localStorage.getItem("stylesheet");
|
||||||
if (current.length) {
|
if (current != null) {
|
||||||
document.querySelector('#css_alt').setAttribute("media", current);
|
document.querySelector('#css_alt').setAttribute("media", current);
|
||||||
}
|
}
|
||||||
else if(window.matchMedia("(prefers-color-scheme: light)").matches) {
|
else if( ! window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
||||||
toggleStylesheet(this);
|
toggleStylesheet(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue