squash merge writepage-fixup + webring supports more than one page
This commit is contained in:
parent
9b2e9ed74d
commit
4e4f2f2a7a
58
microblog.py
58
microblog.py
@ -300,14 +300,12 @@ if __name__ == "__main__":
|
||||
tpl = tpl.replace(css, ("%s%s" % (prepend, css) ))
|
||||
return tpl
|
||||
|
||||
# needs review / clean-up
|
||||
# ideally relate 'lvl' with sub dir instead of hardcoding
|
||||
def writepage(template, timeline, tagcloud, config, subdir = None):
|
||||
count = len(timeline)
|
||||
html = ""
|
||||
with open(template,'r') as f:
|
||||
html = f.read()
|
||||
try:
|
||||
count = len(timeline)
|
||||
p = config["postsperpage"]
|
||||
pagectrl = Paginator(count, p, subdir)
|
||||
except ZeroDivisionError as e:
|
||||
@ -316,33 +314,33 @@ if __name__ == "__main__":
|
||||
except Exception as e:
|
||||
print("error: ",e, ("(number of posts = %i)" % count), file=sys.stderr)
|
||||
exit()
|
||||
latest = timeline if count <= pagectrl.PPP else timeline[:pagectrl.PPP]
|
||||
latest = timeline[:pagectrl.PPP]
|
||||
link_from_top = "./tags/%s/latest.html"
|
||||
link_from_subdir = "../tags/%s/latest.html"
|
||||
link_from_tagdir = "../%s/latest.html"
|
||||
cloud = ""
|
||||
level = 1
|
||||
is_tagline = False
|
||||
if subdir == None: # if top level page
|
||||
lvl = 1
|
||||
tcloud = make_tagcloud(tagcloud, "./tags/%s/latest.html")
|
||||
print(pagectrl.singlepage(html, tcloud, latest))
|
||||
tcloud = make_tagcloud(tagcloud, "../tags/%s/latest.html")
|
||||
pagectrl.paginate(
|
||||
demote_css(html, config["relative_css"], lvl),
|
||||
tcloud, timeline
|
||||
)
|
||||
elif subdir == "placeholder":
|
||||
lvl = 1
|
||||
tcloud = make_tagcloud(tagcloud, "./tags/%s/latest.html")
|
||||
with open ("webring.html", 'w') as f:
|
||||
print(pagectrl.singlepage(html, tcloud, timeline),file=f)
|
||||
else: # if timelines per tag
|
||||
cloud = make_tagcloud(tagcloud, link_from_top)
|
||||
print(pagectrl.singlepage(html, cloud, latest))
|
||||
cloud = make_tagcloud(tagcloud, link_from_subdir)
|
||||
else:
|
||||
if subdir != "webring": # timelines per tag
|
||||
is_tagline = True
|
||||
lvl = 2
|
||||
newhtml = demote_css(html, config["relative_css"], lvl)
|
||||
tcloud = make_tagcloud(tagcloud, "../%s/latest.html")
|
||||
fn = "%s/latest.html" % subdir
|
||||
with open(fn, 'w') as f:
|
||||
pagectrl.written.append(fn)
|
||||
f.write(
|
||||
pagectrl.singlepage(newhtml, tcloud, latest, p=".")
|
||||
)
|
||||
pagectrl.paginate(newhtml, tcloud, timeline, is_tagline)
|
||||
level += 1
|
||||
cloud = make_tagcloud(tagcloud, link_from_tagdir)
|
||||
else:
|
||||
cloud = make_tagcloud(tagcloud, link_from_subdir)
|
||||
demoted = demote_css(html, config["relative_css"], level)
|
||||
filename = "%s/latest.html" % subdir
|
||||
with open(filename, 'w') as f: # landing page for tag
|
||||
pagectrl.written.append(filename)
|
||||
page = pagectrl.singlepage(demoted, cloud, latest, p=".")
|
||||
f.write(page)
|
||||
pagectrl.paginate(
|
||||
demote_css(html, config["relative_css"], level),
|
||||
cloud, timeline, is_tagline)
|
||||
return pagectrl.written
|
||||
|
||||
import toml
|
||||
@ -369,7 +367,7 @@ if __name__ == "__main__":
|
||||
with open(config["file_output"], 'w') as f:
|
||||
print(json.dumps(p), file=f)
|
||||
|
||||
def get_webring(f_cfg): # come up with better name later/
|
||||
def get_webring(f_cfg):
|
||||
import pycurl
|
||||
from io import BytesIO
|
||||
def get_proxy():
|
||||
@ -519,7 +517,7 @@ if __name__ == "__main__":
|
||||
fellows = get_webring(cfg["webring"]["following"] )
|
||||
if fellows != []:
|
||||
updated += writepage(
|
||||
tpl, fellows, tc, cfg["page"], subdir="placeholder" )
|
||||
tpl, fellows, tc, cfg["page"], subdir="webring")
|
||||
with open("updatedfiles.txt", 'w') as f:
|
||||
for filename in updated:
|
||||
print(filename, file=f) # sys.stderr)
|
||||
|
Loading…
x
Reference in New Issue
Block a user