--- /dev/null
+from jinja2 import Environment, FileSystemLoader
+import xml.etree.ElementTree as et
+from datetime import datetime
+from tomllib import load
+from git import Repo
+import requests
+
+"""
+Builds the atom file based on the git repo for multiple protocols: https and gem
+"""
+
+def multi(parent, children):
+ for tag in children:
+ child = et.SubElement(parent, tag)
+ child.text = children[tag]
+
+def page_content(filename):
+ with open(filename, "rb") as f:
+ page = load(f)
+
+ return page["information"]["title"], page["information"]["description"]
+
+# get the repo and the head commit
+
+repo = Repo(".")
+head = repo.heads.main.commit
+updated = datetime.fromtimestamp(head.committed_date).strftime("%Y-%m-%dT%H:%M:%SZ")
+
+# run through pages
+
+entries = []
+for page in head.tree["src"]:
+ commits = list(head.iter_items(repo, head, page.path))
+
+ # run through commit summaries and format for the atom
+
+ summaries = []
+ for (i, commit) in enumerate(commits):
+ created = datetime.fromtimestamp(
+ commit.committed_date
+ ).date().isoformat()
+
+ if i+1 == len(commits):
+ summaries.append(f"(Created {created}) {commit.summary}.")
+ else:
+ summaries.append(f"(Updated {created}) {commit.summary}, ")
+
+ # get the commit time and title, summary
+
+ created = datetime.fromtimestamp(commits[-1].committed_date).strftime("%Y-%m-%dT%H:%M:%SZ")
+ title, summary = page_content(page.path)
+
+ entries.append({
+ "title": title,
+ "summary": summary,
+ "filename": page.path[4:-5],
+ "created": created,
+ "summaries": summaries
+ })
+
+# get the enviroment and template
+
+enviroment = Environment(loader = FileSystemLoader("templates"))
+template = enviroment.get_template("atom.xml")
+
+# render the atoms for different protocols
+
+with open("atom-https.xml", "w") as f:
+ f.write(template.render(
+ protocol="https", filetype="html",
+ entries=entries, updated=updated
+ ))
+
+with open("atom-gemini.xml", "w") as f:
+ f.write(template.render(
+ protocol="gemini", filetype="gmi",
+ entries=entries, updated=updated
+ ))
--- /dev/null
+<feed xmlns="http://www.w3.org/2005/Atom" xml:base="{{ protocol }}://bread.ozva.co.uk/" xml:lang="en">
+ <title>The Bread Machine</title>
+ <subtitle>Changes to the bread site</subtitle>
+ <author><name>Will Greenwood</name></author>
+ <id>{{ protocol }}://bread.ozva.co.uk/</id>
+ <updated>{{ updated }}</updated>
+ <icon>/favicon.ico</icon>
+ <category term="bread" />
+ <link rel="self" href="/atom-{{ protocol }}.xml" />
+ <link rel="alternate" href="/" />
+
+ {% for entry in entries %}
+ <entry>
+ <id>{{ protocol }}://bread.ozva.co.uk/recipes/{{ entry.filename }}.{{ filetype }}</id>
+ <link rel="alternate" title="Recipe page" href="{{ protocol }}://bread.ozva.co.uk/recipes/{{ entry.filename }}.{{ filetype }}" />
+ <link rel="related" title="Git history" href="https://git.ozva.co.uk/?p=bread;a=history;f=src/{{ entry.filename }}.toml" />
+ <title>{{ entry.title }}</title>
+ <updated>{{ entry.created }}</updated>
+ <summary>{{ entry.summary }}</summary>
+ <content type="text">
+ History:
+ {% for summary in entry.summaries -%}
+ {{ summary }}
+ {% endfor -%}
+ </content>
+ </entry>
+ {% endfor %}
+</feed>