summaryrefslogtreecommitdiff
path: root/build.sh
diff options
context:
space:
mode:
authorSteph Enders <steph@senders.io>2024-02-29 09:31:15 -0500
committerSteph Enders <steph@senders.io>2024-02-29 09:31:15 -0500
commit2b39175011422a0d8f96d7f598f46e2a781dd28f (patch)
treedd896a1e35e2ec194bfce829afd61f553652464a /build.sh
parent350a5058cf383733a7e75f753abdcd1cb7aae2c5 (diff)
Initial rework commit: Build Script POC and CSS done
I've created the main CSS layout and a proof of concept for the build script: this will actually build any "done" _post/ file and generate it as a workable HTML file. However, no index file generate, rss, or gemini is implemented
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh156
1 files changed, 156 insertions, 0 deletions
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..3a2cd6b
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,156 @@
+#!/usr/bin/env bash
+
+BUILD=.build/
+
+function extract_metadata() {
+ name=$1
+ file=$2
+ # val=$(grep -oE "^--${name}: .+$" $file | sed -E "s/^--${name}: (.+)$/\1/")
+ val=$(sed -nE "/^--${name}: .+$/s/^--${name}: (.+)$/\1/p" $file)
+ if [ -z "$val" ]; then
+ echo ""
+ return 1
+ else
+ echo "$val"
+ return 0
+ fi
+}
+
+function generate_index() {
+ base_dir=$1
+ index_tmp=$(mktemp -p $BUILD "index_${base_dir}_XXXXXX.html")
+ echo "<ul>" > $index_tmp
+ find -type f -iname "*.html" -exec echo "<li><a href=\"{}\">{}\</a></li>" \; >> $index_tmp
+ echo "</ul>" >> $index_tmp
+ page_tmp=$(mktemp -p $BUILD "index_page_XXXXXX.html")
+ cat _templates/page.html > $page_tmp
+ sed -i -e "/CONTENT/ {
+ \<ul\>
+ r $index_tmp
+ \<\/ul\>
+ d}" $page_tmp
+}
+
+echo "Clearing build-cache"
+rm -rf $BUILD
+mkdir $BUILD
+
+echo "Cleaning up prod folders"
+echo "Deleting www"
+rm -rf www
+mkdir www
+
+echo "Deleting gemini"
+rm -rf gemini
+mkdir gemini
+
+echo "Building html"
+# TODO
+for post in _posts/*.html; do
+ post_date=$(extract_metadata "post-date" $post)
+ if [ -z "$post_date" ]; then
+ # post is not ready to be posted
+ # requires a post date
+ echo "No data"
+ continue;
+ fi
+ updated_at=$(extract_metadata "updated-at" $post)
+ tags=$(extract_metadata "tags" $post)
+ type=$(extract_metadata "type" $post)
+
+ post_file=$(mktemp -p $BUILD "post_XXXXXXX.html")
+ content_file=$(mktemp -p $BUILD "content_XXXXXX.html")
+ updated_html_file=$(mktemp -p $BUILD "updated_html_XXXXXX.html")
+ tags_html_file=$(mktemp -p $BUILD "tags_html_XXXXXX.html")
+
+ echo "Using $post_file for file"
+ cat _templates/page.html > $post_file
+
+ echo "Using $content_file for content"
+ grep -vE "^--.+: .+$" $post > $content_file
+
+ echo "Injecting content from $content_file into $post_file"
+ sed -i -e "/CONTENT/ {
+ r ${content_file}
+ d}" $post_file
+
+ echo "Injecting CSS into $post_file"
+ sed -i -e "/STYLE/ {
+ r _templates/index.css
+ d}" $post_file
+
+ echo "Extracting page title"
+ page_title=$(grep -oE -m 1 "<h1>.+</h1>" $content_file | sed -E "s,<h1>(.+)</h1>,\1,")
+ sed -i -E "s/[{]PAGE_TITLE[}]/$page_title/1" $post_file
+
+ echo "Setting type"
+ if [ -z "$type" ]; then
+ sed -i -E "s/[{]TYPE[}]//" $post_file
+ else
+ sed -i -E "s,[{]TYPE[}],/${type}," $post_file
+ fi
+
+ echo "Setting post date"
+ sed -i -E "s/[{]POST_DATE_ISO[}]/${post_date}/" $post_file
+ display_date=$(date -d "${post_date}" +"%B %d, %Y")
+ sed -i -E "s/[{]POST_DATE_DISP[}]/${display_date}/" $post_file
+
+ echo "Setting updated at"
+ if [ -z "$updated_at" ]; then
+ sed -i -E "s/[{]UPDATED[}]//" $post_file
+ else
+ updated_disp=$(date -d "${updated_at}" +"%B %d, %Y")
+ echo "&emsp;Updated at: <time datetime=\"${updated_at}\">${updated_disp}</time>" \
+ > updated_html_file
+ sed -i -e "/UPDATED/{ r ${updated_html_file} d}" $post_file
+ fi
+ echo "Setting tags"
+ if [ -z "$tags" ]; then
+ sed -i -E "s/[{]TAGS[}]//" $post_file
+ else
+ echo "Using tags file $tags_html_file"
+ echo "&emsp; Tags: [ ${tags} ]" > $tags_html_file
+ sed -i -e "/TAGS/ {
+ r $tags_html_file
+ d}" $post_file
+ fi
+
+ filename=$(basename $post)
+ if [ "$type" == "blog" ]; then
+ year=$(date -d "$post_date" +%Y)
+ month=$(date -d "$post_date" +%m)
+ day=$(date -d "$post_date" +%d)
+ mkdir -p www/blog/$year/$month/$day
+ cp $post_file www/blog/$year/$month/$day/$filename
+ else
+ cp $post_file www/$filename
+ fi
+done
+
+echo "Copying static-html"
+cp -r static-html/* www/
+echo "Copying res to www"
+cp -r res/ www/media/
+echo "Building http rss"
+# TODO
+./tidy.sh
+
+echo "Generating index files"
+for [ obj in www/blog/* ]; do
+ if [! -d $obj ]; then
+ continue;
+ fi
+ generate_index "$obj"
+
+
+echo "Building gmi"
+# TODO
+echo "Copying static-gemini"
+cp -r static-gemini/ gemini/
+echo "Copying res to gemini"
+cp -r res/ gemini/media/
+echo "Building gemini atom"
+# TODO
+
+
+