diff options
| author | alex <alex@pdp7.net> | 2023-10-08 20:48:47 +0200 |
|---|---|---|
| committer | alex <alex@pdp7.net> | 2023-10-08 20:48:47 +0200 |
| commit | cd9e5d7c5c59fb601413a4167f3f97376359156e (patch) | |
| tree | 11938a0677d6166e9b3ff78927d4abdf34acb50f /blog_experiment/blog/html.py | |
| parent | 9530e8ee47a21f9f0775ed7867d22b02d7445182 (diff) | |
Add links
* Prettify using lxml instead of bs4, because bs4 changes whitespace :(
Diffstat (limited to 'blog_experiment/blog/html.py')
| -rw-r--r-- | blog_experiment/blog/html.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/blog_experiment/blog/html.py b/blog_experiment/blog/html.py index 25a2e82e..c7112ea8 100644 --- a/blog_experiment/blog/html.py +++ b/blog_experiment/blog/html.py @@ -1,25 +1,35 @@ -import bs4 +import itertools + import htmlgenerator as h -from blog import meta +from blog import meta, pretty def html_template(*content, page_title=None): - title = meta.TITLE + title = [h.A(meta.TITLE, href=meta.BASE_URL)] if page_title: title += f" - {page_title}" - return bs4.BeautifulSoup(h.render( + + 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(title), + 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.BASE_URL}/feed/"), ), h.BODY( h.H1(title), h.H2(meta.SUBTITLE), + h.P(*links), *content, ), doctype="html", ), {}, - ), features="html.parser").prettify() + )) + |
