Last active
November 13, 2022 22:42
-
-
Save geoffeg/b0a75c30fec60de51e775a9c03072ef2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BLOG_ROOT=~/geoffeg.org/htdocs/blog | |
cp templates/feed-header.tmpl $BLOG_ROOT/feed.xml | |
cp templates/list-header.tmpl $BLOG_ROOT/index.html | |
find posts -not -path '*/\.*' -type f -iname '*.md' -print0 | sort | | |
while IFS= read -r -d '' POST; do | |
echo $POST | |
POST_TITLE=$(head -n1 "$POST" | cut -c3-) | |
DESCRIPTION=$(grep -m 1 '## ' "$POST" | cut -c4-) | |
POST_DATE=$(sed '3q;d' "$POST" | cut -c3-) | |
# Generate the blog post | |
pandoc "$POST" -o $BLOG_ROOT/"$POST_TITLE.html" \ | |
--template templates/post.tmpl \ | |
-B <( echo '<a href="/blog">Parent Directory</a>' ) \ | |
-M author="Geoff Gallaway" \ | |
--css=.style.css \ | |
-f markdown -t html5 -T "geoffeg's blog" | |
# Generate the index file | |
pandoc "$POST" \ | |
--template templates/list-item.tmpl \ | |
-M subtitle="$DESCRIPTION" \ | |
-f markdown -t html5 >> $BLOG_ROOT/index.html | |
# Generate the RSS feed | |
POST_URL="https://geoffeg.org/blog/" | |
POST_URL+=$(urlencode "$POST_TITLE.html") | |
POST_DATE_RSS=$(date +"%a, %d %b %Y %T GMT" --date "$POST_DATE") | |
pandoc "$POST" \ | |
--template templates/feed-item.tmpl \ | |
-M subtitle="$DESCRIPTION" \ | |
-M url="$POST_URL" \ | |
-M date="$POST_DATE_RSS" \ | |
-f markdown -t html5 >> $BLOG_ROOT/feed.xml | |
done | |
cat templates/list-footer.tmpl >> $BLOG_ROOT/index.html | |
cat templates/feed-footer.tmpl >> $BLOG_ROOT/feed.xml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment