JHHM

site

my personal website
git clone https://jhhm.no/repos/site.git

site/bin/makeatom

get raw file: makeatom

1#!/bin/sh
2
3. ./config
4
5DOMAIN="jhhm.no"
6DIR="$DIR_CONTENT/writings"
7FEED_ID="https://jhhm.no/writings/"
8FEED_TITLE="JHHM's Writings"
9LINK="https://jhhm.no/writings/"
10FEED_LINK="https://jhhm.no/writings/atom.xml"
11
12now="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
13
14echo '<?xml version="1.0" encoding="utf-8"?>'
15echo '<feed xmlns="http://www.w3.org/2005/Atom">'
16echo "<title>$FEED_TITLE</title>"
17echo "<author><name>JHHM</name></author>"
18echo "<link rel=\"self\" type=\"application/atom+xml\" href=\"$FEED_LINK\"/>"
19echo "<link href=\"$LINK\"/>"
20echo "<id>$FEED_ID</id>"
21echo "<updated>$now</updated>"
22
23tmp="$(mktemp)"
24
25for file in "$DIR"/*/index.md; do
26    [ -f "$file" ] || continue
27
28    date_line=$(sed -n '3p' "$file" | sed 's/^; *//')
29    iso_date=$(date -u -d "$date_line" +"%Y-%m-%dT%H:%M:%SZ" 2>/dev/null)
30
31    [ -z "$iso_date" ] && iso_date="$now"
32
33    printf "%s|%s\n" "$iso_date" "$file" >> "$tmp"
34done
35
36sort -r "$tmp" | while IFS="|" read -r iso_date file; do
37    title="$(sed -n '1p' "$file" | sed 's/^; *//')"
38    content="$(markup < "$file")"
39
40    base="$(basename "$(dirname "$file")")"
41    url="https://$DOMAIN/writings/$base"
42
43    echo "<entry>"
44    echo "<title>$title</title>"
45    echo "<id>$url</id>"
46    echo "<link rel=\"alternate\" href=\"$url\"/>"
47    echo "<published>$iso_date</published>"
48    echo "<updated>$iso_date</updated>"
49    echo "<content type=\"html\"><![CDATA[$content]]></content>"
50    echo "</entry>"
51done
52
53rm -f "$tmp"
54
55echo '</feed>'