Made the colophon on each index page be a file and provided a sample.

main
Mike Lynch 2024-05-04 14:14:36 +10:00
parent 564f366ae2
commit 2e098f7909
2 changed files with 24 additions and 9 deletions

View File

@ -46,7 +46,7 @@ NAME_RES = [
class GlossatoryPost():
class MediaPost():
def __init__(self, year, month, day, file, title):
self.year = year
self.month = month
@ -87,7 +87,7 @@ def process_post(archive, obj):
else:
raise ValueError(f"Couldn't match url {url}")
alt = attachment["name"]
return GlossatoryPost(year, month, day, file, alt)
return MediaPost(year, month, day, file, alt)
def ensure_dir(gmdir):
@ -95,17 +95,26 @@ def ensure_dir(gmdir):
gmdir.mkdir(parents=True)
def write_gemfile(gmdir, title, items):
def load_colophon(cfile):
if cfile:
with open(cfile, "r") as cfh:
colophon = cfh.readlines()
return "".join(colophon)
return None
def write_gemfile(gmdir, colophon, title, items):
ensure_dir(gmdir)
gmi = gmdir / "index.gmi"
with open(gmi, "w") as gfh:
gfh.write(HEADER)
if colophon:
gfh.write(colophon)
gfh.write("\n\n")
gfh.write(f"# {title}\n\n")
for link, text in items:
gfh.write(f"=> {link} {text}\n")
def apub2gmi(archive, output):
def apub2gmi(archive, output, colophon):
with open(f"{archive}/outbox.json", "r") as fh:
js = json.load(fh)
posts = {}
@ -127,12 +136,12 @@ def apub2gmi(archive, output):
print(f"Processing failed: {i}: {e}")
years = [ ( f"{year}/", year ) for year in posts ]
write_gemfile(Path(output), "Glossatory", years)
write_gemfile(Path(output), colophon, "Glossatory", years)
for year in posts:
ydir = Path(output) / year
months = [ ( f"{month}/", MNAMES[month] ) for month in posts[year] ]
write_gemfile(ydir, year, months)
write_gemfile(ydir, colophon, year, months)
for month in posts[year]:
mname = MNAMES[month]
mdir = ydir / month
@ -148,7 +157,7 @@ def apub2gmi(archive, output):
for day in posts[year][month]:
for post in posts[year][month][day]:
links.append((f"{day}/{post.fname}", post.title))
write_gemfile(mdir, f"{mname} {year}", links)
write_gemfile(mdir, colophon, f"{mname} {year}", links)
if __name__ == "__main__":
@ -159,5 +168,10 @@ if __name__ == "__main__":
ap.add_argument(
'-o', '--output', required=True, type=str, help="Output directory"
)
ap.add_argument(
'-c', '--colophon', required=False, type=str,
help="File with text to be included at the top of each index page"
)
args = ap.parse_args()
apub2gmi(args.archive, args.output)
colophon = load_colophon(args.colophon)
apub2gmi(args.archive, args.output, colophon)

1
colophon.gmi 100644
View File

@ -0,0 +1 @@
This is a sample of some text which can be added at the top of every gemfile in the archive.