import csv
from pathlib import Path
OUTDIR = Path("../public/")
OUTDIR.mkdir(exist_ok=True)
REDIRECTS = Path("../templates/redirects.csv")
TEMPLATE = """
lipu sona pona | Redirect
Redirecting...
"""
def redirects():
with open(REDIRECTS) as f:
reader = csv.reader(f)
next(reader) # skip header
for line in reader:
if not line:
continue
dest, origin = line
yield origin, dest
for origin, dest in redirects():
with open(OUTDIR / origin, "w") as f:
f.write(TEMPLATE.format(dest).strip())