import pathlib
import textwrap
-import bs4
-
import bicephalus
import htmlgenerator as h
from feedgen import feed
-from blog import html, page, gemtext, meta
+from blog import html, page, gemtext, meta, pretty
class Entry:
fe.published(datetime.datetime.combine(entry.posted, datetime.datetime.min.time(), tzinfo=datetime.timezone.utc))
fe.title(entry.title)
html = h.render(h.BaseElement(*entry.html()), {})
- html = bs4.BeautifulSoup(html, features="html.parser").prettify()
+ html = pretty.pretty_html(html)
fe.content(html, type="html")
return bicephalus.Response(
-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()
+ ))
+
TITLE = "El blog es mío"
SUBTITLE = "Hay otros como él, pero este es el mío"
BASE_URL = "https://blog.pdp7.net"
+
+LINKS = (
+ ("GitHub", "https://github.com/alexpdp7/"),
+ ("LinkedIn", "https://es.linkedin.com/in/alexcorcoles"),
+ ("Project Euler", "https://projecteuler.net/profile/koalillo.png"),
+ ("Stack Exchange", "https://stackexchange.com/users/13361/alex"),
+)
+
+EMAIL_TEXT = "escríbeme cogiendo el dominio de esta web y cambiando el primer punto por una arroba"
--- /dev/null
+from lxml import etree, html
+
+
+def pretty_html(s):
+ return etree.tostring(html.fromstring(s), pretty_print=True).decode("utf8")
[metadata]
lock-version = "2.0"
python-versions = "^3.9"
-content-hash = "d84139eb7e19e366ef33bb9e36f3c74ca432b9c5931d9f19d6fb1b8693400654"
+content-hash = "97fc5ab9e66a2dd243b910c6408cbf77194f61b070c35ef9d2aca9ea1c329c56"
htmlgenerator = "^1.2.28"
beautifulsoup4 = "^4.12.2"
feedgen = "^0.9.0"
+lxml = "^4.9.3"
[tool.poetry.group.dev.dependencies]
pytest = "^7.4.2"