From 0505357a3273cdf8d4bfb2ded0a351d259ecb078 Mon Sep 17 00:00:00 2001 From: Zachary Vance Date: Wed, 3 Jul 2024 12:32:28 -0400 Subject: [PATCH] Factor out common tagcloud --- blog | 95 +++++++++++++++++++++++++++----- config.yaml | 2 + templates/post.mustache.html | 48 +--------------- templates/tag.mustache.html | 47 +--------------- templates/tagcloud.mustache.html | 47 ++++++++++++++++ 5 files changed, 132 insertions(+), 107 deletions(-) create mode 100644 templates/tagcloud.mustache.html diff --git a/blog b/blog index d505ed7..96b92da 100755 --- a/blog +++ b/blog @@ -1,7 +1,23 @@ #!/bin/python3 +""" +Generates blog.za3k.com from source files. +Source files consist of a YAML "front material", and markdown or HTML body. +Mostly they have been exported from wordpress by wordpress2frontmaterial.py. + +This is one big honking violation of: + + > Explicit is better than implicit. + +There is magic. Templates read directly off objects. Objects' fields are +not documented. + +Other than that I think it's pretty nice! +""" + import argparse import yaml import chevron as mustache +import collections from pathlib import Path import collections import os, os.path @@ -26,6 +42,23 @@ def url_slug(title): title = "".join(x for x in title if x in allowable) return title +def calc_range(l): + it = iter(l) + min = next(it) + max = min + for x in it: + if x < min: + min = x + if x > max: + max = x + return range(min, max) + +def scale(i1, range1, range2): + frac1 = (i1 - range1.start) / (range1.stop - range1.start) + frac2 = frac1 + i2 = frac2 * (range2.stop - range2.start) + range2.start + return i2 + RELOAD_HTML = b"""