Author:
Hash:
Timestamp:
+71 -9 +/-4 browse
Kevin Schoon [me@kevinschoon.com]
2ac9053d4454d853e400d56bf40f153fb45b437b
Tue, 13 May 2025 15:47:55 +0000 (6 months ago)
| 1 | diff --git a/assets/style.xsl b/assets/style.xsl |
| 2 | new file mode 100644 |
| 3 | index 0000000..10b5101 |
| 4 | --- /dev/null |
| 5 | +++ b/assets/style.xsl |
| 6 | @@ -0,0 +1,54 @@ |
| 7 | + <?xml version="1.0" encoding="utf-8"?> |
| 8 | + <xsl:stylesheet version="3.0" |
| 9 | + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 10 | + xmlns:atom="http://www.w3.org/2005/Atom" |
| 11 | + xmlns:dc="http://purl.org/dc/elements/1.1/" |
| 12 | + xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"> |
| 13 | + <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/> |
| 14 | + <xsl:template match="/"> |
| 15 | + <html lang="en"> |
| 16 | + <head> |
| 17 | + <title> |
| 18 | + <xsl:value-of select="/rss/channel/title"/> |
| 19 | + </title> |
| 20 | + <link rel="stylesheet" href="/main.css" /> |
| 21 | + </head> |
| 22 | + <body> |
| 23 | + <main class="rss-page"> |
| 24 | + <article> |
| 25 | + <header> |
| 26 | + <h1> |
| 27 | + <img class="me" src="/ks_stylized.png"/> |
| 28 | + <a> |
| 29 | + <xsl:attribute name="href"> <xsl:value-of select="/rss/channel/link"/> </xsl:attribute> |
| 30 | + </a> |
| 31 | + </h1> |
| 32 | + <h2><xsl:value-of select="/rss/channel/description"/></h2> |
| 33 | + </header> |
| 34 | + <p><strong>This is an <a href="https://en.wikipedia.org/wiki/RSS">RSS feed</a>.</strong></p> |
| 35 | + <p>Copy the link from the address bar into your feed reader to receive regular updates.</p> |
| 36 | + </article> |
| 37 | + <xsl:for-each select="/rss/channel/item"> |
| 38 | + <article class="card"> |
| 39 | + <header> |
| 40 | + <h3> |
| 41 | + <a> |
| 42 | + <xsl:attribute name="href"> |
| 43 | + <xsl:value-of select="link"/> |
| 44 | + </xsl:attribute> |
| 45 | + <xsl:value-of select="title"/> |
| 46 | + </a> |
| 47 | + </h3> |
| 48 | + </header> |
| 49 | + <xsl:value-of select="description" disable-output-escaping="yes"/> |
| 50 | + <footer class="rss"> |
| 51 | + <xsl:value-of select="author" /><br/> |
| 52 | + <b><xsl:value-of select="pubDate"/></b> |
| 53 | + </footer> |
| 54 | + </article> |
| 55 | + </xsl:for-each> |
| 56 | + </main> |
| 57 | + </body> |
| 58 | + </html> |
| 59 | + </xsl:template> |
| 60 | + </xsl:stylesheet> |
| 61 | diff --git a/build.py b/build.py |
| 62 | index 84292aa..edbb3a4 100755 |
| 63 | --- a/build.py |
| 64 | +++ b/build.py |
| 65 | @@ -85,6 +85,7 @@ if __name__ == "__main__": |
| 66 | w.build("gen/contact.png", "make_qr_code", inputs=["contact.txt"]) |
| 67 | w.build("gen/ks_stylized.png", "copy", inputs=["assets/ks_stylized.png"]) |
| 68 | w.build("gen/favicon.ico", "copy", inputs=["assets/favicon.ico"]) |
| 69 | + w.build("gen/style.xsl", "copy", inputs=["assets/style.xsl"]) |
| 70 | w.build("gen/main.css", "compile_sass", inputs=["main.scss"]) |
| 71 | cmd = _render_rule(w, "index", "/") |
| 72 | w.build( |
| 73 | diff --git a/main.scss b/main.scss |
| 74 | index 4b6e8d0..478f813 100644 |
| 75 | --- a/main.scss |
| 76 | +++ b/main.scss |
| 77 | @@ -77,6 +77,10 @@ img.me { |
| 78 | max-width: 350px; |
| 79 | } |
| 80 | |
| 81 | + main.rss-page { |
| 82 | + margin: 20px; |
| 83 | + } |
| 84 | + |
| 85 | @media (prefers-color-scheme: dark) { |
| 86 | :root { |
| 87 | background-color: #2c2c2c; |
| 88 | diff --git a/render.py b/render.py |
| 89 | index 43bd56a..c0419b7 100755 |
| 90 | --- a/render.py |
| 91 | +++ b/render.py |
| 92 | @@ -122,11 +122,7 @@ def generate(template, content_path, stylesheet, link, sitemap, devmode=False): |
| 93 | out = base.render( |
| 94 | { |
| 95 | "content": env_content.get_template("").render( |
| 96 | - { |
| 97 | - "sitemap": sitemap, |
| 98 | - "tree": tree, |
| 99 | - "variables": sitemap["variables"] |
| 100 | - } |
| 101 | + {"sitemap": sitemap, "tree": tree, "variables": sitemap["variables"]} |
| 102 | ), |
| 103 | "variables": sitemap["variables"], |
| 104 | "is_index": False, |
| 105 | @@ -144,7 +140,10 @@ def generate(template, content_path, stylesheet, link, sitemap, devmode=False): |
| 106 | def generate_rss(sitemap): |
| 107 | sitemap = _load_sitemap(sitemap, "/") |
| 108 | |
| 109 | - rss = ET.Element("rss", attrib={"version": "2.0", "encoding": "UTF-8"}) |
| 110 | + header = ET.Element( |
| 111 | + "xml-stylesheet", attrib={"href": "/feed.xsl", "type": "text/xsl"} |
| 112 | + ) |
| 113 | + rss = ET.Element("rss", attrib={"version": "2.0", "encoding": "utf-8"}) |
| 114 | channel = ET.SubElement(rss, "channel") |
| 115 | |
| 116 | title = ET.SubElement(channel, "title") |
| 117 | @@ -163,11 +162,15 @@ def generate_rss(sitemap): |
| 118 | guid_item.text = absolute_url |
| 119 | description_item = ET.SubElement(item, "description") |
| 120 | title_item.text = entry["name"] |
| 121 | - link_item.attrib["href"] = absolute_url |
| 122 | + link_item.attrib["href"] = absolute_url |
| 123 | description_item.text = entry["tagline"] |
| 124 | |
| 125 | - xml_str = ET.tostring(rss, xml_declaration=True, encoding="utf-8", method="xml") |
| 126 | - sys.stdout.buffer.write(xml_str) |
| 127 | + xml_str = ET.tostring(rss, xml_declaration=True, encoding="unicode", method="xml") |
| 128 | + xml_str = xml_str.replace( |
| 129 | + "<?xml version='1.0' encoding='utf-8'?>", |
| 130 | + "<?xml version='1.0' encoding='utf-8'?><?xml-stylesheet href='/style.xsl' type='text/xsl'?>", |
| 131 | + ) |
| 132 | + sys.stdout.buffer.write(bytes(xml_str, encoding="utf-8")) |
| 133 | |
| 134 | |
| 135 | if __name__ == "__main__": |