aboutsummaryrefslogtreecommitdiff
path: root/barf
diff options
context:
space:
mode:
Diffstat (limited to 'barf')
-rwxr-xr-xbarf59
1 files changed, 56 insertions, 3 deletions
diff --git a/barf b/barf
index 81bbcd2..f77512d 100755
--- a/barf
+++ b/barf
@@ -1,4 +1,19 @@
#!/bin/sh
+
+domain="https://adast.dk"
+
+# Check the operating system
+os_name=$(uname -s)
+
+if [ "$os_name" = "OpenBSD" ]; then
+ alias sed=gsed
+ alias date=gdate
+ alias rsync=openrsync
+elif [ "$os_name" = "Darwin" ]; then
+ alias sed=gsed
+ alias date=gdate
+fi
+
set -eu
MARKDOWN=smu
IFS=' '
@@ -20,13 +35,13 @@ index_html() {
# Intro text
$MARKDOWN index.md
- echo "<ul>"
+ echo '<ul class="posts">'
# Posts
while read -r f title created; do
link=$(echo "$f" | sed -E 's|.*/(.*).md|\1/|')
created=$(echo $(head -3 "$f" | tail -1))
- echo "<li>$created &middot; <a href=\"$link\">$title</a></li>"
+ echo "<li><span>$created</span><a href=\"$link\">$title</a></li>"
done < "$1" | sort -r
echo "</ul>"
@@ -37,7 +52,6 @@ index_html() {
atom_xml() {
uri=$(sed -rn '/atom.xml/ s/.*href="([^"]*)".*/\1/ p' header.html)
- domain=$(echo "$uri" | sed 's/atom.xml//g' | sed 's|/[^/]*$||')
first_commit_date=$(git log --pretty='format:%ai' . | cut -d ' ' -f1 | tail -1)
cat <<EOF
@@ -74,6 +88,44 @@ EOF
echo '</feed>'
}
+rss_xml() {
+ uri=$(sed -rn '/rss.xml/ s/.*href="([^"]*)".*/\1/ p' header.html)
+ first_commit_date=$(git log --pretty='format:%ai' . | cut -d ' ' -f1 | tail -1)
+
+ cat <<EOF
+<?xml version="1.0" encoding="utf-8"?>
+<rss version="2.0">
+ <channel>
+ <title>$(sed -n '/^# /{s/# //p; q}' index.md)</title>
+ <link>$domain/rss.xml</link>
+ <description>Adam Stück's blog</description>
+ <lastBuildDate>$(date -u +"%a, %d %b %Y %H:%M:%S %z")</lastBuildDate>
+ <pubDate>$(date -u +"%a, %d %b %Y %H:%M:%S %z")</pubDate>
+ <generator>Custom RSS Generator</generator>
+ <ttl>1800</ttl>
+EOF
+
+ while read -r f title created; do
+ content=$($MARKDOWN "$f" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g')
+ post_link=$(echo "$f" | sed -E 's|posts/(.*).md|\1|')
+ basic_date=$(echo $(head -3 "$f" | tail -1))
+ published_date=$(date -d "$basic_date" -u +"%a, %d %b %Y %H:%M:%S %z")
+
+ cat <<EOF
+ <item>
+ <title>$title</title>
+ <description>$content</description>
+ <link>$domain/$post_link</link>
+ <guid isPermaLink="false">$domain/$post_link</guid>
+ <pubDate>$published_date</pubDate>
+ </item>
+EOF
+ done < "$1"
+
+ echo '</channel>'
+ echo '</rss>'
+}
+
write_page() {
filename=$1
directory=$(echo $(basename "$filename" .md))
@@ -94,6 +146,7 @@ rm -rf build && mkdir build
index_tsv posts | sort -rt " " -k 3 > build/posts.tsv
index_html build/posts.tsv > build/index.html
atom_xml build/posts.tsv > build/atom.xml
+rss_xml build/posts.tsv > build/rss.xml
while read -r f title created; do
write_page "$f" "$title" "$created"
done < build/posts.tsv