#!/bin/env python3

# Generate a type map file for content language negotiation of the landing page
# based on the alternatives configured in the project file
#
# see https://httpd.apache.org/docs/current/mod/mod_negotiation.html#typemaps

import glob
from lektor.environment.config import Config

projectfile = glob.glob(r"./*.lektorproject")[0]
conf = Config(projectfile)

with open("assets/index.html.var", "w") as f:
    f.write("URI: index.html\n\n")
    for alt in conf["ALTERNATIVES"].items():
        f.write("Content-type: text/html\n")
        f.write(f"Content-language: {alt[0]}\n")
        f.write(f"URI: {alt[1]['url_prefix']}index.html\n\n")
