From 66d9ecaa26925ffcc0947e887cc7a94f79268644 Mon Sep 17 00:00:00 2001 From: Philip Wittamore Date: Wed, 7 May 2025 21:34:07 +0200 Subject: blog scripts --- README | 1 + blogarticledate | 13 ++++++++ blogrss | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++ blogsend | 39 ++++++++++++++++++++++ blogsend1 | 15 +++++++++ blogsend24 | 17 ++++++++++ blogsend3 | 16 +++++++++ blogsitemap | 33 +++++++++++++++++++ blogsitemap.options | 11 +++++++ blogthis | 53 ++++++++++++++++++++++++++++++ 10 files changed, 292 insertions(+) create mode 100644 README create mode 100755 blogarticledate create mode 100755 blogrss create mode 100755 blogsend create mode 100755 blogsend1 create mode 100755 blogsend24 create mode 100755 blogsend3 create mode 100755 blogsitemap create mode 100755 blogsitemap.options create mode 100755 blogthis diff --git a/README b/README new file mode 100644 index 0000000..76b8846 --- /dev/null +++ b/README @@ -0,0 +1 @@ +various scripts to manage my blog diff --git a/blogarticledate b/blogarticledate new file mode 100755 index 0000000..845ddcf --- /dev/null +++ b/blogarticledate @@ -0,0 +1,13 @@ +#!/bin/sh + +postArray=( $(ls *.html) ) +for posts in "${postArray[@]}"; do + post=$posts + postdate=$(grep -o '>.*' $post | sed 's/\(>\|<\/h5>\)//g') + echo $postdate + #[[CC]YY]MMDDhhmm[.ss] + postdate="${postdate//-}0000" + echo Date=$postdate + echo Item=$post + touch -a -m -t $postdate $post +done diff --git a/blogrss b/blogrss new file mode 100755 index 0000000..59f8f3f --- /dev/null +++ b/blogrss @@ -0,0 +1,94 @@ +#!/bin/bash + +title=Bloggings +link=https://wittamore.com/articles/2025 +description='Ramblings from Brittany, France' +rsslink=https://wittamore.com/rss.xml +feedname=/home/philip/web/rss.xml +postDir=/home/philip/web/articles/2025 +updated=$(date --iso-8601=ns) + +# correct file date to match blog post date +#cd $postDir +#postArray=( $(ls *.html) ) +#for posts in "${postArray[@]}"; do +# post=$posts +# postdate=$(grep -o '>.*' $post | sed 's/\(>\|<\/h5>\)//g') +# #[[CC]YY]MMDDhhmm[.ss] +# postdate="${postdate//-}0000" +# echo Date=$postdate +# echo Item=$post +# touch -a -m -t $postdate $post +#done + +# Build RSS header & footer +header () { +echo """ + +""" > ~/feedtop +echo """ + +Bloggings - wittamore.com +https://wittamore.com +Ramblings from Brittany, France +$updated + +""" >> ~/feedtop +} + +footer () { +echo """ + + + +""" >> ~/feedbottom +} + +# Function: Build Item add to feed + +item () { + echo """ + $fullTitle + $postdate + $linkadd + $linkadd + + $description + + + """ >> ~/feed +} + +# Function: Concatenate everything + +combine () { + header + footer + cat ~/feedtop ~/feed > ~/feedtb + cat ~/feedtb ~/feedbottom > $feedname + rm ~/feedtop ~/feed ~/feedtb ~/feedbottom +} + +# Run through files and create rss.xml + +if [[ -f $feedname ]]; then + rm $feedname +fi +touch $feedname +postArray=( $(ls -t "$postDir"/*.html) ) +numPosts=$(ls "$postDir"/*.html | wc -l) +postNum=0 +for posts in "${postArray[@]}"; do + let postNum+=1 + post=$posts + fullTitle=$(grep -o '>.*' $post | sed 's/\(>\|<\/h2>\)//g') + postdate=$(grep -o '>.*' $post | sed 's/\(>\|<\/h5>\)//g') + postname=${post##*/} + linkadd="$link"/"$postname" + guid=$postNum + description=$(sed -n '/

.*/,/*.<\/h4>/{p;q;}' $post | sed -e 's/<[^>]\+>/ /g' -e 's|

||g' -e 's|

||g' -e 's|"||g') + item $post +done + combine +exit + diff --git a/blogsend b/blogsend new file mode 100755 index 0000000..6aaa041 --- /dev/null +++ b/blogsend @@ -0,0 +1,39 @@ +#!/bin/sh + +# 2025-03-29 15:36:12 +# blogsend : scp blog files to web server +# usage : blogsend hours (if not set default is 1 hour) +# example : blogsend 72 sends files modified over the past 3 days + +# folders +rf=mail:/var/www/html/wittamore.com +mf=~/.local/src/web/wittamore.com +cd $mf + +# test if var is sent +if [[ -z "$1" ]]; then + HOURS=1; +else + # test if va is a number + if [[ "$1" =~ ^[0-9]+$ ]]; then + HOURS=$1; + else + HOURS=1; + fi +fi + +MINUTES=$(($HOURS*60)) + +echo "Sending files modified in the past $HOURS hour(s)..." + +files=$(find * -iname "*.html" -path .tmp -prune -o -mmin -$MINUTES -type f) +for file in $files +do + echo -ne "-> "; + scp -r "$file" "$rf/$file"; +done + +echo "Done." + +exit 0 + diff --git a/blogsend1 b/blogsend1 new file mode 100755 index 0000000..0a12bb6 --- /dev/null +++ b/blogsend1 @@ -0,0 +1,15 @@ +#!/bin/sh + +rf=web:/var/www/wittamore.com +mf=~/src/web/wittamore.com + +cd $mf + +files=$(find * -path .tmp -prune -o -mmin -60 -type f) +for file in $files +do + scp -r "$file" "$rf/$file" +done + +exit 0 + diff --git a/blogsend24 b/blogsend24 new file mode 100755 index 0000000..5d6e53a --- /dev/null +++ b/blogsend24 @@ -0,0 +1,17 @@ +#!/bin/sh +# update blog wittamore.com +# edits in last 24 hours + +rf=web:/var/www/wittamore.com +mf=~/src/web/wittamore.com + +cd $mf + +files=$(find * -path .tmp -prune -o -mtime 0 -type f) +for file in $files +do + scp -r "$file" "$rf/$file" +done + +exit 0 + diff --git a/blogsend3 b/blogsend3 new file mode 100755 index 0000000..19c4bb3 --- /dev/null +++ b/blogsend3 @@ -0,0 +1,16 @@ +#!/bin/sh +# update edits in past 3 hours + +rf=web:/var/www/wittamore.com +mf=/home/philip/src/web/wittamore.com + +cd $mf + +files=`find * -path .git -prune -o -mmin -180 -type f ` +for file in $files +do + scp -r "$file" "$rf/$file" +done + +exit 0 + diff --git a/blogsitemap b/blogsitemap new file mode 100755 index 0000000..bf80013 --- /dev/null +++ b/blogsitemap @@ -0,0 +1,33 @@ +#!/bin/bash + +cd /home/philip/web + +# url configuration +URL="https://wittamore.com/" + +# values: always hourly daily weekly monthly yearly never +FREQ="weekly" + +# begin new sitemap +exec 1> sitemap.xml + +# print head +echo '' +echo '' +echo '' + +# print urls +IFS=$'\r\n' GLOBIGNORE='*' command eval "OPTIONS=($(cat $0.options))" +find . -type f "${OPTIONS[@]}" -printf "%TY-%Tm-%Td%p\n" | \ +while read -r line; do + DATE=${line:0:10} + FILE=${line:12} + echo "" + echo " ${URL}${FILE}" + echo " $DATE" + echo " $FREQ" + echo "" +done + +# print foot +echo "" diff --git a/blogsitemap.options b/blogsitemap.options new file mode 100755 index 0000000..26cebac --- /dev/null +++ b/blogsitemap.options @@ -0,0 +1,11 @@ +-prune +! -iname robots.txt +! -iname counter.txt +! -iname sitemap.\* +! -iname rss.\* +! -iname style.\* +! -iname .\* +! -path ./images/\* +! -path ./rss-bridge/\* + + diff --git a/blogthis b/blogthis new file mode 100755 index 0000000..c736c8f --- /dev/null +++ b/blogthis @@ -0,0 +1,53 @@ +#!/bin/sh + +# create text, assemble html file, add to articles + +#web is a symlink to /home/philip/src/web/wittamore.com +ROOT=/home/philip/web + +mkdir -p $ROOT/.tmp +cd $ROOT/.tmp +EDITFILE="middle.html" +DATE=$(date +%Y-%m-%d) + +read -p "Enter title: " TITLE +read -e -i "$DATE" -p "Enter date: " input +read -p "Enter description: " DESCRIPTION + +ARTICLEDATE="${input:-$DATE}" +YEAR=$(echo $ARTICLEDATE | cut -c 1-4) +DEST="$ROOT/articles/$YEAR" + +echo "

$TITLE

" > $EDITFILE +echo "
$ARTICLEDATE
" >> $EDITFILE +echo "

$DESCRIPTION

" >> $EDITFILE + +micro +4:1 $EDITFILE + +FIXEDTITLE=${TITLE// /-} +ARTICLE="$FIXEDTITLE.html" + +echo " + + + + + + $TITLE + + +
+

Bloggings

+ Back +
+
+ " > $ARTICLE +cat $EDITFILE >> $ARTICLE +echo ' +

 

+
+

ยง

+ +' >> $ARTICLE +mv $ARTICLE $DEST +echo "saved as $DEST/$ARTICLE" -- cgit v1.2.3