summaryrefslogtreecommitdiff
path: root/build.sh
diff options
context:
space:
mode:
authorSteph Enders <steph@senders.io>2024-02-29 10:40:02 -0500
committerSteph Enders <steph@senders.io>2024-02-29 10:40:02 -0500
commit80f5dacf988b1cddd04eea6c4a6f70b165376764 (patch)
tree1e43c117612532c43d85f693b55e6565157694d3 /build.sh
parent2b39175011422a0d8f96d7f598f46e2a781dd28f (diff)
Generate index files and fix page generation in build script
The previous commit had a partial implementation of this so the build script wouldn't work!
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh126
1 files changed, 79 insertions, 47 deletions
diff --git a/build.sh b/build.sh
index 3a2cd6b..20d232b 100755
--- a/build.sh
+++ b/build.sh
@@ -5,7 +5,6 @@ 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 ""
@@ -16,19 +15,76 @@ function extract_metadata() {
fi
}
+function mktemp_file() {
+ name=$1
+ var=$(mktemp -p $BUILD "${name}_XXXXXX")
+ echo "${var}"
+ return 0
+}
+
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
+ echo "Generating index for $base_dir"
+ page_file=$(mktemp_file "index_page")
+ content_file=$(mktemp_file "index_content")
+ title=$(basename ${base_dir})
+ echo "<article>
+ <h1>${title} index</h1>
+ <ul>" > $content_file
+ find $base_dir -type f -iname "*.html" \
+ -exec echo "<li><a href=\"{}\">{}</a></li>" \; >> $content_file
+ echo "</ul>
+ </article>" >> $content_file
+ sed -i "s,${base_dir},.,g" $content_file
+
+ generate_page "index" $content_file $page_file
+
+ # strip out the footer
+ sed -i '1,/<\/footer>/{/<footer>/,$d}' $page_file
+ echo "Copying $page_file to $base_dir/index.html"
+ cp $page_file $base_dir/index.html
+ echo "Searching for more directories to index"
+ for dir in $base_dir/*; do
+ if [ ! -d $dir ]; then
+ continue;
+ fi
+ generate_index $dir
+ done
+}
+# generates the base page structure
+# any "special" functions can go in their various code_paths
+function generate_page() {
+ type=$1
+ content_file=$2
+ page_file=$3
+ echo "Using $page_file for file"
+ cat _templates/page.html > $page_file
+
+ echo "Using $content_file for content"
+ sed -i "/^--/d" $content_file
+
+ echo "Injecting content from $content_file into $page_file"
sed -i -e "/CONTENT/ {
- \<ul\>
- r $index_tmp
- \<\/ul\>
- d}" $page_tmp
+ r ${content_file}
+ d}" $page_file
+
+ echo "Injecting CSS into $page_file"
+ sed -i -e "/STYLE/ {
+ r _templates/index.css
+ d}" $page_file
+
+ echo "Extracting page title"
+ page_title=$(sed -nE "/<\/h1>/s,.*<h1>(.+)</h1>.*,\1,1p" $content_file)
+ sed -i -E "s/[{]PAGE_TITLE[}]/$page_title/1" $page_file
+
+ echo "Setting type"
+ if [ -z "$type" ]; then
+ sed -i -E "s/[{]TYPE[}]//" $page_file
+ else
+ sed -i -E "s,[{]TYPE[}],/${type}," $page_file
+ fi
+
+ return 0
}
echo "Clearing build-cache"
@@ -58,38 +114,16 @@ for post in _posts/*.html; do
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")
+ post_file=$(mktemp_file "post")
+ content_file=$(mktemp_file "content")
+ updated_html_file=$(mktemp_file "updated_html")
+ tags_html_file=$(mktemp_file "tags_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 "Copying $post data into $content_file"
+ cp $post $content_file
+ generate_page $type $content_file $post_file
+
echo "Setting post date"
sed -i -E "s/[{]POST_DATE_ISO[}]/${post_date}/" $post_file
display_date=$(date -d "${post_date}" +"%B %d, %Y")
@@ -115,6 +149,8 @@ for post in _posts/*.html; do
d}" $post_file
fi
+
+ echo "Copying temp_file to www/"
filename=$(basename $post)
if [ "$type" == "blog" ]; then
year=$(date -d "$post_date" +%Y)
@@ -136,12 +172,8 @@ echo "Building http rss"
./tidy.sh
echo "Generating index files"
-for [ obj in www/blog/* ]; do
- if [! -d $obj ]; then
- continue;
- fi
- generate_index "$obj"
-
+dir="www/blog"
+generate_index "$dir"
echo "Building gmi"
# TODO