summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbacalhau <bacalhau@based.pt>2025-06-10 21:22:11 +0000
committerbacalhau <bacalhau@based.pt>2025-06-10 21:22:11 +0000
commitde931b029741ce9d58df068a099654709673544b (patch)
tree5737da728b0e76aeaf69d1c6addc8b65181c6a93
parent096af534cc7088fef6a1858e3dfb18e50ef8e143 (diff)
finished everythingHEADmaster
-rw-r--r--webgen.sh61
1 files 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/<!-- *date: *\([^ ]*\) *-->/\1/p' "$file")
+ title=$(sed -n 's/<!-- *title: *\(.*[^ ]\) *-->/\1/p' "$file")
+ domain=$(sed -n 's/<!-- *domain: *\(.*[^ ]\) *-->/\1/p' "$file")
+
+ # Append to atom entry list
+ {
+ echo " <entry>"
+ echo " <title>$title</title>"
+ echo " <link href=\"https://$domain/blog/$name\" />"
+ echo " <id>https://$domain/blog/$name/</id>"
+ echo " <updated>$post_date</updated>"
+ echo " <content type=\"xhtml\">"
+ echo " <div xmlns=\"http://www.w3.org/1999/xhtml\">"
+ echo " $(cat "$file" | sed '/<!-- *\(date\|title\|domain\):.*-->/d' | sed 's/^/ /')"
+ echo " </div>"
+ echo " </content>"
+ echo " </entry>"
+ 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
+