aboutsummaryrefslogtreecommitdiff
path: root/blog_experiment/blog/html.py
blob: 5263ca9bdb7b4b56cc20597bb5eebe32d0e2b8e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import itertools

import htmlgenerator as h

from blog import meta, pretty


def html_template(*content, page_title=None):
    title = [h.A(meta.TITLE, href=f"{meta.SCHEMA}://{meta.HOST}")]
    if page_title:
        title += f" - {page_title}"

    title = h.BaseElement(*title)

    links = list(itertools.chain(*[(h.A(text, href=href), ", ") for text, href in meta.LINKS]))

    links += h.BaseElement(f" {meta.EMAIL_TEXT}")

    return pretty.pretty_html(h.render(
        h.HTML(
            h.HEAD(
                h.TITLE(meta.TITLE + (f" - {page_title}" if page_title else "")),
                h.LINK(rel="alternate", type="application/rss+xml", title=meta.TITLE, href=f"{meta.SCHEMA}://{meta.HOST}/feed/"),
            ),
            h.BODY(
                h.H1(title),
                h.H2(meta.SUBTITLE),
                h.P(*links),
                *content,
            ),
            doctype="html",
        ),
        {},
    ))