summaryrefslogtreecommitdiffstats
path: root/genblog
diff options
context:
space:
mode:
authorSquibid <me@zacharyscheiman.com>2023-07-15 04:41:40 -0400
committerSquibid <me@zacharyscheiman.com>2023-07-15 04:41:40 -0400
commit81e150fbd84e0bff8a5d4b80f93a128cabeb4433 (patch)
tree6931c2c515632488cc83990bdd0a6234cbf197d6 /genblog
parent224a8f75949ecfeec9ef6dc4cd822abb9a6ffed6 (diff)
downloadsite-81e150fbd84e0bff8a5d4b80f93a128cabeb4433.tar.gz
site-81e150fbd84e0bff8a5d4b80f93a128cabeb4433.tar.bz2
site-81e150fbd84e0bff8a5d4b80f93a128cabeb4433.zip
new genblog script, remove old gen scripts new blog layout
Diffstat (limited to '')
-rwxr-xr-xgenblog51
1 files changed, 51 insertions, 0 deletions
diff --git a/genblog b/genblog
new file mode 100755
index 0000000..12bb7fe
--- /dev/null
+++ b/genblog
@@ -0,0 +1,51 @@
+#!/bin/sh
+#
+# genblog is a script to take data from my blogs and format it into html for
+# my website
+#
+# by: Squibid
+#
+
+#
+# Helper variables and functions
+#
+bloglist=$(ls -t1 blog/*.html | grep -oP '(?<=\/).*?(?=\.)')
+top5=$(printf "$bloglist\n" | head -5)
+
+blogdate() {
+ grep -oP '(?<=\<meta name="date" content=").*(?="\>)' "blog/$1.html"
+}
+blogtitle() { grep -oP '(?<=\<title\>).*(?=\<\/title\>)' "blog/$1.html"; }
+htmlline() {
+ printf "<a href=\"/blog/$1\">\ $(blogtitle $1)</a>\
+<span>$(blogdate $1)</span><br>\n"
+}
+
+# set file dates properly
+for i in $bloglist; do
+ if $(touch -cd "$(blogdate $i)T00:00:00" /tmp/file); then
+ touch -amt "$(blogdate $i | sed 's/\///g')0000" "blog/$i.html"
+ fi
+done
+
+#
+# Start modifing our files
+#
+
+# delete old bloglist
+sed -i -n '1,/.*<!-- b script marker blog -->/p;/.*<!-- e script marker blog -->/,$p' index.html
+sed -i -n '1,/.*<!-- b script marker blog -->/p;/.*<!-- e script marker blog -->/,$p' blog.html
+
+# top 5 blogs
+for i in $top5; do
+ line=$(htmlline $i)
+ # add new bloglist
+ sed -i "/.*<!-- e script marker blog -->/i $line" index.html
+done
+
+# generate the full blog list
+for i in $bloglist; do
+ line=$(htmlline $i)
+ # add new bloglist
+ sed -i "/.*<!-- e script marker blog -->/i $line" blog.html
+done