aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbarf26
1 files changed, 11 insertions, 15 deletions
diff --git a/barf b/barf
index 5c0db4d..bbbe550 100755
--- a/barf
+++ b/barf
@@ -18,7 +18,7 @@ set -eu
MARKDOWN=lowdown
IFS=' '
-# Create tab-separated file with filename, title, creation date, last update
+# Create tab separated file with filename, title, creation date, last update
index_tsv() {
for f in "$1"/*.md
do
@@ -35,13 +35,13 @@ index_html() {
# Intro text
$MARKDOWN index.md
- echo "<ul class='posts'>"
+ echo "<ul>"
# Posts
while read -r f title created; do
- link=$(echo "$f" | sed -E 's|.*/(.*).md|posts/\1/|')
+ link=$(echo "$f" | sed -E 's|.*/(.*).md|\1/|')
created=$(echo $(head -3 "$f" | tail -1))
- echo "<li><span>$created</span><a href=\"$link\">$title</a></li>"
+ echo "<li>$created &middot; <a href=\"$link\">$title</a></li>"
done < "$1" | sort -r
echo "</ul>"
@@ -67,8 +67,9 @@ atom_xml() {
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|posts/\1|')
+ 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 +%Y-%m-%dT10:%M:%SZ)
@@ -106,7 +107,7 @@ 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|posts/\1|')
+ 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")
@@ -128,15 +129,8 @@ EOF
write_page() {
filename=$1
directory=$(echo $(basename "$filename" .md))
- if echo "$filename" | grep -q "^posts/"; then
- # Create a directory under build/posts
- $(mkdir -p build/posts/$directory)
- target=$(echo "$filename" | sed -r 's|posts/(.*).md|build/posts/\1/index.html|')
- else
- # Create a directory under build for pages
- $(mkdir -p build/$directory)
- target=$(echo "$filename" | sed -r 's|pages/(.*).md|build/\1/index.html|')
- fi
+ $(mkdir -p build/$directory)
+ target=$(echo "$filename" | sed -r 's|\w+/(.*).md|build/\1/index.html|')
created=$(echo $(head -3 "$filename" | tail -1))
title=$2
@@ -146,6 +140,8 @@ write_page() {
> "$target" && cat footer.html >> "$target"
}
+rm -rf build && mkdir build
+
# Blog posts
index_tsv posts | sort -rt " " -k 3 > build/posts.tsv
index_html build/posts.tsv > build/index.html