From cd9e5d7c5c59fb601413a4167f3f97376359156e Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 8 Oct 2023 20:48:47 +0200 Subject: Add links * Prettify using lxml instead of bs4, because bs4 changes whitespace :( --- blog_experiment/blog/html.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'blog_experiment/blog/html.py') 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() + )) + -- cgit v1.2.3