Files
website/blog.sh
2025-11-19 06:59:37 -08:00

54 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env sh
# Site specific settings
DOMAIN="https://iiogama.0x212.com"
TITLE="iiogama@0x212.com"
DESCRIPTION="Some dude compulsively online, like so many others"
COPYRIGHT="Copyright $(date +%Y), Thai Noodles"
#AUTHOR="Thai Noodles, (iiogama@0x212.com)"
CONTENT_DIR="content"
#ASSET_DIR="assets"
OUTPUT_DIR="_output"
build_pages() {
rsync -r --exclude="*.html" --exclude="*.xml" "$CONTENT_DIR/" "$OUTPUT_DIR/"
#rsync -r "$ASSET_DIR/" "$OUTPUT_DIR/"
find $CONTENT_DIR -type f -name "*.html" | while read -r file; do
OUTPUT_FILE="$(echo "$file" | sed "s/$CONTENT_DIR/$OUTPUT_DIR/")"
if [ ! -f "$OUTPUT_FILE" ]; then
printf '<!DOCTYPE html>\n' > "$OUTPUT_FILE"
printf '<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">\n' >> "$OUTPUT_FILE"
sed "s!<title>!&$TITLE!" "templates/_head.html" >> "$OUTPUT_FILE"
printf '<body>\n' >> "$OUTPUT_FILE"
cat "templates/_nav.html" "$file" "templates/_footer.html" >> "$OUTPUT_FILE"
printf '</body>\n' >> "$OUTPUT_FILE"
printf '</html>\n' >> "$OUTPUT_FILE"
fi
done
}
build_feeds() {
find $CONTENT_DIR -type f -name "*.xml" | while read -r file; do
OUTPUT_FILE="$(echo "$file" | sed "s/$CONTENT_DIR/$OUTPUT_DIR/")"
if [ ! -f "$OUTPUT_FILE" ]; then
printf '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' > "$OUTPUT_FILE"
printf '<?xml-stylesheet href="style.xsl" type="text/xsl"?>\n' >> "$OUTPUT_FILE"
printf '<rss version="2.0">\n' >> "$OUTPUT_FILE"
printf '<channel>' >> "$OUTPUT_FILE"
printf '<title>%s</title>\n' "$TITLE" >> "$OUTPUT_FILE"
printf '<link>%s</link>\n' "$DOMAIN" >> "$OUTPUT_FILE"
printf '<description>%s</description>\n' "$DESCRIPTION" >> "$OUTPUT_FILE"
printf '<copyright>%s</copyright>\n' "$COPYRIGHT" >> "$OUTPUT_FILE"
cat "$file" >> "$OUTPUT_FILE"
printf '</channel>\n' >> "$OUTPUT_FILE"
printf '</rss>\n' >> "$OUTPUT_FILE"
fi
done
}
case "$1" in
build)
build_pages
build_feeds
#xsltproc "$OUTPUT_DIR/index.xml" > "$OUTPUT_DIR/blog/index.html"
;;
esac