~robin_jadoul/blog

96afc4795805532d3e39cea8eae90df059b29a5a — Robin Jadoul 8 months ago 0ce5774
RSS
3 files changed, 42 insertions(+), 2 deletions(-)

M site.py
M templates/base.html
A templates/rss.xml
M site.py => site.py +11 -2
@@ 1,4 1,5 @@
# TODO:
#  - Caching
#  - Improve templates
#    + footer?
#  - Improve homepage


@@ 10,9 11,11 @@
#      * Cite utility
#    + interest
#    + About me
#      * Links to other places
#      * https://indielogin.com/setup
#    + CV?
#  - minimalist/gemini/text-only version??
#  - RSS/atom feed?
#  - prerender KaTeX
import os, datetime, collections, pathlib, typing
os.chdir(os.path.abspath(os.path.dirname(__file__)))



@@ 67,7 70,9 @@ with Site(
        loaders = {".md": YamlFrontmatterLoader()},

        sitename = "/dev/ur4ndom - Robin Jadoul",
        nav = [("Posts", "/posts/")]
        nav = [("Posts", "/posts/")],
        location = "https://ur4ndom.dev",
        description = "Cryptography, CTFs, and more"
        ) as config:
    with gather_directory(curdir / "static"):
        output()


@@ 100,6 105,10 @@ with Site(
        render(tmpls.get("index.html"))
        output()

    with create(pathlib.Path("rss.xml"), metadata={"posts": map(as_linkable, sorted_posts)}):
        render(tmpls.get("rss.xml"))
        output()

    with gather(curdir / "pages", "**/*.md"):
        transform(cleanurl)
        transform(strip_leading)

M templates/base.html => templates/base.html +1 -0
@@ 5,6 5,7 @@
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>{{ metadata.title | default("") }}{% if metadata.title and config.sitename %} | {% endif %}{{ config.sitename | default("") }}</title>
        <link rel="stylesheet" type="text/css" href="/static/css/style.css">
        <link rel="alternate" type="application/rss+xml" title="{{ config.sitename | default('RSS') }}" href="/rss.xml">

        <script type="text/javascript">
            katex_options = {

A templates/rss.xml => templates/rss.xml +30 -0
@@ 0,0 1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    {% if config.location %}<atom:link rel="self" href="{{ config.location }}/rss.xml" type="application/rss+xml" />{% endif %}
    <title>{{ config.sitename | default("") }}</title>
    <link>{{ config.location | default("") }}</link>
    <description>{{ config.description | default("") }}</description>
    <language>en</language>
    <image>
      <url>{{ config.location | default("") }}/static/avatar.png</url>
      <title>{{ config.sitename | default("") }}</title>
      <link>{{ config.location | default("") }}</link>
    </image>
    {% for post in metadata.posts %}
    {% if post.metadata.date %}
    <item>
      <title>{{ post.title }}</title>
      <link>{{ config.location | default("") }}{{ post.link }}</link>
      <description>{{ post.metadata.summary }}</description>
      <pubDate>{{ post.metadata.date.strftime("%a, %d %b %Y %H:%M:%S %z") }}</pubDate>
      <guid {% if not config.location %}isPermaLink="false"{% endif %}>{{ config.location | default("") }}{{ post.link }}</guid>
      <dc:creator>{{ post.metadata.author }}</dc:creator>
      {% for tag in post.metadata.tags %}
      <category domain="{{ config.location }}/tags/">{{ tag }}</category>
      {% endfor %}
    </item>
    {% endif %}
    {% endfor %}
  </channel>
</rss>