diff options
| author | Philip Wittamore <philip@wittamore.com> | 2025-05-07 21:34:07 +0200 | 
|---|---|---|
| committer | Philip Wittamore <philip@wittamore.com> | 2025-05-07 21:34:07 +0200 | 
| commit | 66d9ecaa26925ffcc0947e887cc7a94f79268644 (patch) | |
| tree | cde639475dfa226ad8d5353a7a5142fa23f0649b | |
| download | blog-66d9ecaa26925ffcc0947e887cc7a94f79268644.tar.gz blog-66d9ecaa26925ffcc0947e887cc7a94f79268644.tar.bz2 blog-66d9ecaa26925ffcc0947e887cc7a94f79268644.zip | |
blog scripts
| -rw-r--r-- | README | 1 | ||||
| -rwxr-xr-x | blogarticledate | 13 | ||||
| -rwxr-xr-x | blogrss | 94 | ||||
| -rwxr-xr-x | blogsend | 39 | ||||
| -rwxr-xr-x | blogsend1 | 15 | ||||
| -rwxr-xr-x | blogsend24 | 17 | ||||
| -rwxr-xr-x | blogsend3 | 16 | ||||
| -rwxr-xr-x | blogsitemap | 33 | ||||
| -rwxr-xr-x | blogsitemap.options | 11 | ||||
| -rwxr-xr-x | blogthis | 53 | 
10 files changed, 292 insertions, 0 deletions
| @@ -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 '>.*</h5>' $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 @@ -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 '>.*</h5>' $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 """<?xml version='1.0' encoding='UTF-8' ?> +<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'> +""" > ~/feedtop +echo """ +<channel> +<title>Bloggings - wittamore.com</title> +<link>https://wittamore.com</link> +<description>Ramblings from Brittany, France</description> +<lastBuildDate>$updated</lastBuildDate> +<atom:link href='$rsslink' rel='self' type='application/rss+xml' /> +""" >> ~/feedtop +} + +footer () { +echo """ +</channel> + +</rss> +""" >> ~/feedbottom +} + +# Function: Build Item add to feed + +item () { +        echo """<item> +        <title>$fullTitle</title> +        <pubDate>$postdate</pubDate> +        <link>$linkadd</link> +        <guid>$linkadd</guid> +        <category> </category> +        <description>$description</description> +        <enclosure> </enclosure> +        </item> +        """ >> ~/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 '>.*</h2>' $post | sed 's/\(>\|<\/h2>\)//g') +  postdate=$(grep -o '>.*</h5>' $post | sed 's/\(>\|<\/h5>\)//g') +  postname=${post##*/} +  linkadd="$link"/"$postname" +  guid=$postNum +  description=$(sed -n '/<h4>.*/,/*.<\/h4>/{p;q;}' $post | sed -e 's/<[^>]\+>/ /g' -e 's|<h4>||g' -e 's|</h4>||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 '<?xml version="1.0" encoding="UTF-8"?>' +echo '<!-- generator="Milkys Sitemap Generator, https://github.com/mcmilk/sitemap-generator" -->' +echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' + +# 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 "<url>" +  echo " <loc>${URL}${FILE}</loc>" +  echo " <lastmod>$DATE</lastmod>" +  echo " <changefreq>$FREQ</changefreq>" +  echo "</url>" +done + +# print foot +echo "</urlset>" 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 "<h2>$TITLE</h2>" > $EDITFILE +echo "<h5>$ARTICLEDATE</h5>" >> $EDITFILE +echo "<h4>$DESCRIPTION</h4>" >> $EDITFILE + +micro +4:1 $EDITFILE + +FIXEDTITLE=${TITLE// /-} +ARTICLE="$FIXEDTITLE.html" + +echo "<!doctype html> +<html lang=\"EN\"> +  <head> +    <meta charset=\"utf-8\"> +    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> +    <link rel=\"stylesheet\" href=\"/style.css\"> +    <title>$TITLE</title> +  </head> +  <body> +    <header> +      <h1>Bloggings</h1> +      <a href=\"/index.php\">Back</a> +      <hr> +    </header> +    <!-- article start -->" > $ARTICLE  +cat $EDITFILE >> $ARTICLE +echo '<!-- article end --> +<p> </p> +<hr> +<p>ยง</p> +  </body> +</html>' >> $ARTICLE +mv $ARTICLE $DEST +echo "saved as $DEST/$ARTICLE" | 
