From de931b029741ce9d58df068a099654709673544b Mon Sep 17 00:00:00 2001 From: bacalhau Date: Tue, 10 Jun 2025 21:22:11 +0000 Subject: finished everything --- webgen.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/webgen.sh b/webgen.sh index 9f6cd5c..c8bd024 100644 --- a/webgen.sh +++ b/webgen.sh @@ -1,24 +1,28 @@ #!/bin/sh + TEMPLATEPAGE="./templates/page.html" TEMPLATEBLOG="./templates/blog.html" +TEMPLATEATOM="./templates/atom.xml" CONTENTPAGE="./content/page" CONTENTBLOG="./content/blog" OUTPUTDIR="./output" STATIC="./static" -mkdir -p templates -mkdir -p content/page -mkdir -p content/blog +# Create necessary directories +mkdir -p templates content/page content/blog static rm -rf "$OUTPUTDIR" -mkdir -p output +mkdir -p "$OUTPUTDIR" +# Copy static files cp -r "$STATIC"/* "$OUTPUTDIR" +# Generate the index page sed '/{{.Content}}/ { - r './content/index.html' + r ./content/index.html d }' "$TEMPLATEPAGE" > "$OUTPUTDIR/index.html" +# Generate content pages for file in "$CONTENTPAGE"/*.html; do name=$(basename -s .html "$file") mkdir -p "$OUTPUTDIR/$name/" @@ -28,3 +32,50 @@ for file in "$CONTENTPAGE"/*.html; do }' "$TEMPLATEPAGE" > "$OUTPUTDIR/$name/index.html" done +# Generate blog posts (only if 'post' is passed as argument) +if [ "$1" = "post" ]; then + mkdir -p tmp + for file in "$CONTENTBLOG"/*.html; do + name=$(basename -s .html "$file") + mkdir -p "$OUTPUTDIR/blog/$name/" + sed '/{{.Content}}/ { + r '"$file"' + d + }' "$TEMPLATEBLOG" > "$OUTPUTDIR/blog/$name/index.html" + + # Metadata + post_date=$(sed -n 's//\1/p' "$file") + title=$(sed -n 's//\1/p' "$file") + domain=$(sed -n 's//\1/p' "$file") + + # Append to atom entry list + { + echo " " + echo " $title" + echo " " + echo " https://$domain/blog/$name/" + echo " $post_date" + echo " " + echo "
" + echo " $(cat "$file" | sed '//d' | sed 's/^/ /')" + echo "
" + echo "
" + echo "
" + echo "" + } >> tmp/entry.xml + done + + # Generate atom with entries injected + sed '/{{.Content}}/ { + r tmp/entry.xml + d + }' "$TEMPLATEATOM" > "$OUTPUTDIR/atom.xml" + + date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + sed "s/{{.Date}}/$date/" "$OUTPUTDIR/atom.xml" > "$OUTPUTDIR/atom.xml.tmp" + mv "$OUTPUTDIR/atom.xml.tmp" "$OUTPUTDIR/atom.xml" + + # Remove tmp directory + rm -r tmp +fi + -- cgit v1.2.3