]> OzVa Git service - bread/commitdiff
Added atom file generator
authorMax Value <greenwoodw50@gmail.com>
Thu, 5 Mar 2026 13:27:14 +0000 (13:27 +0000)
committerMax Value <greenwoodw50@gmail.com>
Thu, 5 Mar 2026 13:27:14 +0000 (13:27 +0000)
.gitignore
atom.py [new file with mode: 0644]
requirements.txt
templates/atom.xml [new file with mode: 0644]

index bc95d3eefc4051d52758d212b574d32cb0c6e954..7fa217d63ad1426d92ba0fbb2fdc3e6b7b044297 100644 (file)
@@ -1,4 +1,5 @@
 build/*
 recipes/*
-/index.html
+index*
+atom-*
 *.pdf
diff --git a/atom.py b/atom.py
new file mode 100644 (file)
index 0000000..7fc4fcc
--- /dev/null
+++ b/atom.py
@@ -0,0 +1,78 @@
+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
+       ))
index 1b2b710e9352d865928606621e5b9b4a31d3ea3e..922f1aacf88e02c7bb69e6b6bc3395dc72083cf3 100644 (file)
@@ -1,3 +1,5 @@
+gitpython
+requests
+feedgen
 jinja2
 tqdm
-feedgen
diff --git a/templates/atom.xml b/templates/atom.xml
new file mode 100644 (file)
index 0000000..1e32cc8
--- /dev/null
@@ -0,0 +1,28 @@
+<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>