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