diff options
author | ben <ben@nagy.contact> | 2025-01-10 11:14:29 -0800 |
---|---|---|
committer | ben <ben@nagy.contact> | 2025-01-10 11:14:29 -0800 |
commit | fb4f206e21cc2853e904e8e548b3d4450b208c8d (patch) | |
tree | 92044e436174b598bbb831473412ee4382a05396 /scripts/archive | |
parent | 7339a5dae5f48ba37d44094f8aaa9915695f86e5 (diff) |
added scriptsmain
Diffstat (limited to 'scripts/archive')
-rw-r--r-- | scripts/archive/README.md | 1 | ||||
-rwxr-xr-x | scripts/archive/blog/ab | 442 | ||||
-rw-r--r-- | scripts/archive/blog/doc/data.txt | 5 | ||||
-rw-r--r-- | scripts/archive/blog/doc/templates/index-tag-template.html | 8 | ||||
-rw-r--r-- | scripts/archive/blog/doc/templates/index-template.html | 8 | ||||
-rw-r--r-- | scripts/archive/blog/doc/templates/rss-template.xml | 16 | ||||
-rw-r--r-- | scripts/archive/blog/doc/templates/template.html | 59 | ||||
-rwxr-xr-x | scripts/archive/blog/rss-parse.sh | 46 |
8 files changed, 585 insertions, 0 deletions
diff --git a/scripts/archive/README.md b/scripts/archive/README.md new file mode 100644 index 0000000..9385294 --- /dev/null +++ b/scripts/archive/README.md @@ -0,0 +1 @@ +Retired Scripts diff --git a/scripts/archive/blog/ab b/scripts/archive/blog/ab new file mode 100755 index 0000000..b16c933 --- /dev/null +++ b/scripts/archive/blog/ab @@ -0,0 +1,442 @@ +#!/bin/bash + +blogdir="arachnida_blog" +imgdir="assets/img" +datafile="../doc/data.txt" +drafts="drafts" +template="../doc/templates/template.html" +index_template="../doc/templates/index-template.html" +index_tag_template="../doc/templates/index-tag-template.html" +rss_template="../doc/templates/rss-template.xml" +rss_file="~/Doc/programming/website/arachnida_blog/rss/rss.xml" + +# Colored Output +RED='\033[0;31m' +GREEN='\033[0;32m' +RESET='\033[0m' + +# Update +function update () { + #printf 'Updating: arachnida.blog\n' | dzen2 -bg white -fg black -p 2 -x -375 -y 50 -w 275 -h 50 + rsync -uvrp --delete-after "$blogdir" root@"$DOMAIN":"$REMOTE_LOCATION" + printf "\n\n${GREEN}Website has been updated.${RESET}\n\n" +} + +# Pick an entry +function listitem () { + printf "\nContents of %s:\n" "$1" + case "$(ls --hide "img" "$1" | wc -l)" in + 0) printf "${RED}No drafts made yet.\n\n${GREEN}Redirecting...${RESET}\n\n" && blog ;; + 1) number=1 && printf "Only one draft available.\n" ;; + *) ls -rc --hide "img" "$1" | awk -F '/' '{print $NF}' | sed 's/\.html$//' | nl # edited + printf "\nPick and entry by number to %s" "$2: " | sed 's/blog_//g' && read number + esac + entry="$(ls --hide "img" -rc "$1" | nl | grep -w " $number" | awk '{print $2}')" + basefile="$(basename "$entry")" && base="${basefile%.*}" +} + +# Confirm a choice +function confirm () { read -p "Really $1 \"$base\"? (y/N) " choice && echo "$choice" | grep -qi "^y$" || exit 1; } + +# Create a new blog draft +function blog_draft () { + read -e -p "Give your post a title: " title + + max=0 + while [ $max == 0 ]; do + read -e -p "Enter a description (50 words limit): " description + [ $(echo "$description" | wc -w) -ge "50" ] && echo "Description must be less than 50 words." || max=1 + done + + read -e -r -p "Input an image to reflect your post: " img + while [ ! -e $img ]; do + read -e -r -p "$img does not exist. Please try another path: " img + done + + url="$(echo "$title" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")" + ( [ -f "$drafts"/$url.html ] || [ -f "$blogdir/blog/$url.html" ] ) && + printf "\nThere is already an existing draft or post with the same title.\n\n Redirecting...\n\n" && blog + $EDITOR "$drafts"/$url.html + # Select tags + tags=("informative" "care" "rant" "breeding-report" "off-topic" "seller-review") + tagged=() + menu() { + clear + echo "Choose a tag(s):" + for i in ${!tags[@]}; do + printf "%3d%s) %s\n" $((i+1)) "${choices[i]:- }" "${tags[i]}" + done + if [[ "$msg" ]]; then echo "$msg"; fi + } + + prompt="Check an option (again to uncheck, ENTER when done): " + while menu && read -rp "$prompt" num && [[ "$num" ]]; do + [[ "$num" != *[![:digit:]]* ]] && + (( num > 0 && num <= ${#tags[@]} )) || + { msg="Invalid option: $num"; continue; } + ((num--))#; msg="${tags[num]} was ${choices[num]:+un}checked" + [[ "${choices[num]}" ]] && choices[num]="" || choices[num]="+" + done + for i in ${!tags[@]}; do + [[ "${choices[i]}" ]] && { tagged+=(${tags[i]^}); } + done + TAGS=$(printf "%s, " "${tagged[@]}") + + # image handling + img=$(echo "$img" | cut -f 1 -d '.' >&1) + + if [[ -e "$drafts"/img/$img.jpg || -e "$blogdir"/assets/img/blog/$img.jpg ]] ; then + i="2" + while [[ -e "$drafts"/img/$img-$i.jpg || -e "$blogdir"/assets/img/blog/$img-$i.jpg ]]; do ((i++)); done + mv "$img.jpg" "$img-$i.jpg" && cp "$img-$i.jpg" "$drafts"/img/ && mv "$img-$i.jpg" "$img.jpg" + img="$img-$i.jpg" + else + cp "$img.jpg" "$drafts"/img/ + img="$img.jpg" + fi + + printf "Post: %s\nTitle: %s\nDescription: %s\nImage: %s\nTags:\n" "$url" "$title" "$description" "$img" | cat - "$datafile" | sponge "$datafile" + sed -i "5s/$/ ${TAGS}\n/" "$datafile" + printf "\n${GREEN}Post was saved as a draft: Publish when you are ready to do so.${RESET}\n\n" +} + +# Edit a blog draft. Either title, description, content, or index image +function edit_draft () { + title() { + read -e -r -p "Enter a new title: " title + url="$(echo "$title" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")" + old_url="$(echo $(basename "$basefile" ".html" | sed 's/ /-/g'))" + old_title="$(awk "/Post: $old_url/{getline; print}" "$datafile" | sed 's/^[^:]*: //')" + ( [ -f "$drafts"/$url.html ] || [ -f "$blogdir/blog/$url.html" ] ) && + printf "\nThere is already an existing draft or post with the same title.\n\n Redirecting...\n\n" && title + mv $drafts/$entry $drafts/$url.html + sed -i "s/Post: $old_url/Post: $url/g" "$datafile" + sed -i "s/Title: $old_title/Title: $title/g" "$datafile" + printf "\n${GREEN}Title has been updated.${RESET}\n\n" + } + + descr() { + max=0 + while [ $max == 0 ]; do + read -e -p "Enter a new description (50 words limit): " descript + [ $(echo "$descript" | wc -w) -ge "50" ] && echo "Description must be less than 50 words." || max=1 + done + sed -i "/Post: $(basename "$basefile" ".html")/{n;s/.*/Description: $descript/}" "$datafile" + sed -i "/Description: $descript/{n;d;}" "$datafile" + printf "\n${GREEN}Description has been updated.${RESET}\n\n" + } + + con() { listitem "$drafts" edit && "$EDITOR" "$drafts"/$entry && printf "\nPost's content has been updated.\n\n"; } + + image() { + entry="$(basename "$entry" ".html")" + read -e -r -p "Enter the path to a new image: " img + while [ ! -e "$img" ]; do + read -e -r -p "$img does not exist. Please try another path: " img + done + + img=$(echo "$img" | cut -f 1 -d '.' >&1) + old_img="$(cat "$datafile" | sed -n "/Post: "$entry"/{n;n;n; p}" | sed 's/^[^:]*: //')" + if [[ -e "$drafts"/img/$img.jpg || -e "$blogdir"/assets/img/blog/$img.jpg ]] ; then + i="2" + while [[ -e "$drafts"/img/$img-$i.jpg || -e "$blogdir"/assets/img/blog/$img-$i.jpg ]]; do ((i++)); done + mv "$img.jpg" "$img-$i.jpg" && cp "$img-$i.jpg" "$drafts"/img/ + else cp "$img.jpg" "$imgdir"/blog/ + fi + rm "$drafts"/img/$old_img + sed -i "s/Image: $old_img/Image: $img.jpg/g" "$datafile" + printf "\n${GREEN}Index image has been updated.${RESET}\n\n" + } + + printf "\nEditing %s:\nUsage:\n\tt = Title\n\td = Description\n\tc = Content\n\ti = Image\n\n" "$entry" + read -p "How would you like proceed? " cmd + case "$cmd" in + t) title ;; + d) descr ;; + c) con ;; + i) image ;; + *) printf "Exiting..\n\n" && exit 1 ;; + esac +} + +# Delete a draft +function del_draft () { + printf "${RED}Deleting $entry.${RESET}\n" && rm -f "$drafts"/$entry + sed -i "/Post: $(basename "$entry" ".html")/,+5d" "$datafile" +} + +# Delete a public post +function blog_pub_del () { + title="$(basename $basefile .html | sed 's/-/ /g')" + post='\<a href="..\/'"$basefile"'">' + blog_post='\<a href="blog\/'"$basefile"'">' + + sed -i -n '/'"$blog_post"'/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/blog.html + sed -i -e '/'"$blog_post"'/,+4d' "$blogdir"/blog.html + sed -i "/Post: $(basename "$entry" ".html")/,+5d" "$datafile" + sed -i '/<!-- START: '"$title"'/,/<!-- END: '"$title"'/d' "$rss_file" + + if grep -q "$title" "$blogdir"/index.html; then + sed -i '/'"$title"'/d' "$blogdir"/index.html + fi + + if grep -o -q "$title" "$blogdir"/blog/tags/off-topic.html; then + sed -i -n '/'"$post"'/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/blog/tags/off-topic.html + sed -i -e '/'"$post"'/,+4d' "$blogdir"/blog/tags/off-topic.html + fi + + if grep -o -q "$title" "$blogdir"/blog/tags/breeding-reports.html; then + sed -i -n '/'"$post"'/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/blog/tags/breeding-reports.html + sed -i -e '/'"$post"'/,+4d' "$blogdir"/blog/tags/breeding-reports.html + fi + + if grep -o -q "$title" "$blogdir"/blog/tags/care.html; then + sed -i -n '/'"$post"'/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/blog/tags/care.html + sed -i -e '/'"$post"'/,+4d' "$blogdir"/blog/tags/care.html + fi + + if grep -o -q "$title" "$blogdir"/blog/tags/informative.html; then + sed -i -n '/'"$post"'/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/blog/tags/informative.html + sed -i -e '/'"$post"'/,+4d' "$blogdir"/blog/tags/informative.html + fi + + if grep -o -q "$title" "$blogdir"/blog/tags/seller-reviews.html; then + sed -i -n '/'"$post"'/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/blog/tags/seller-reviews.html + sed -i -e '/'"$post"'/,+4d' "$blogdir"/blog/tags/seller-reviews.html + fi + + if grep -o -q "$title" "$blogdir"/blog/tags/rant.html; then + sed -i -n '/'"$post"'/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/blog/tags/rant.html + sed -i -e '/'"$post"'/,+4d' "$blogdir"/blog/tags/rant.html + fi + + printf "${RED}Deleting $entry.${RESET}\n" && rm -f "$blogdir"/blog/$entry && update +} + +# Publish a draft +function blog_pub () { + tmpdir=$(mktemp -d) + rssdate="$(LC_TIME=en_US date '+%a, %d %b %Y %H:%M:%S %z')" + webdate="$(date '+%Y %b %d')" + url="$(basename "$basefile" ".html")" + title="$(awk "/Post: $url/{getline; print}" "$datafile" | sed 's/^[^:]*: //')" + description="$(awk "/$title/{getline; print}" "$datafile" | sed 's/^[^:]*: //')" + img="$(awk "/$description/{getline; print}" "$datafile" | sed 's/^[^:]*: //')" + tags="$(grep -A1 "$img" "$datafile" | grep -v "$img" | sed -e 's/^[^:]*: //' -e 's/\,//g')" + tagsArr=(${tags}) + post="$(cat "$drafts"/$basefile)" + recent="$(printf "$(basename $basefile ".html")" | sed "s/^.*$/\<li\>\<a href=\"blog\/&.html\"\>$title\<\/a\>\<\/li\>/g" | awk 'BEGIN{FS=OFS=".html\">"} {gsub(/-/," ",$2)}1')" + numofrecent="$(sed -n '/<!-- RECENT POSTS -->/,/<!-- END-RECENT POSTS -->/p' "$blogdir"/index.html | wc -l)" + + printf "$(cat "$index_tag_template")\n" "$basefile" "$img" "$img" "$basefile" "$title" "$webdate" "$description" "$basefile" > "$tmpdir/tagindex" + for i in "${tagsArr[@]}"; do + case ${i} in + "Informative") + printf "$i\n" | sed "s/^.*$/<h3><a href=\"tags\/informative.html\">&<\/a><\/h3>/g" >> "$tmpdir/tag" + sed -i "/<!-- INDEX CONTENT -->/r $tmpdir/tagindex" "$blogdir"/blog/tags/informative.html + ;; + "Care") + printf "$i\n" | sed "s/^.*$/<h3><a href=\"tags\/care.html\">&<\/a><\/h3>/g" >> "$tmpdir/tag" + sed -i "/<!-- INDEX CONTENT -->/r $tmpdir/tagindex" "$blogdir"/blog/tags/care.html + ;; + "Rant") + printf "$i\n" | sed "s/^.*$/<h3><a href=\"tags\/rant.html\">&<\/a><\/h3>/g" >> "$tmpdir/tag" + sed -i "/<!-- INDEX CONTENT -->/r $tmpdir/tagindex" "$blogdir"/blog/tags/rant.html + ;; + "Breeding-report") + printf "$i\n" | sed "s/^.*$/<h3><a href=\"tags\/breeding-reports.html\">&<\/a><\/h3>/g" >> "$tmpdir/tag" + sed -i "/<!-- INDEX CONTENT -->/r $tmpdir/tagindex" "$blogdir"/blog/tags/breeding-reports.html + ;; + "Off-topic") + printf "$i\n" | sed "s/^.*$/<h3><a href=\"tags\/off-topic.html\">&<\/a><\/h3>/g" >> "$tmpdir/tag" + sed -i "/<!-- INDEX CONTENT -->/r $tmpdir/tagindex" "$blogdir"/blog/tags/off-topic.html + ;; + "Seller-review") + printf "$i\n" | sed "s/^.*$/<h3><a href=\"tags\/seller-reviews.html\">&<\/a><\/h3>/g" >> "$tmpdir/tag" + sed -i "/<!-- INDEX CONTENT -->/r $tmpdir/tagindex" "$blogdir"/blog/tags/seller-reviews.html + ;; + *) ;; + esac + done + + printf "$(cat "$template")" "$title" "$description" "$title" "$webdate" > "$blogdir"/blog/"$basefile" # Append draft file to blog directory + sed -i "/<!-- BLOG CONTENT -->/r $drafts/$basefile" "$blogdir"/blog/"$basefile" # Append post in the draft + sed -i "/<!-- TAGS -->/r $tmpdir/tag" "$blogdir"/blog/"$basefile" # Append respective tags in draft + printf "$(cat "$index_template")\n" "$basefile" "$img" "$img" "$basefile" "$title" "$webdate" "$description" "$basefile" > "$tmpdir/blogindex" + sed -i "/<!-- INDEX CONTENT -->/r $tmpdir/blogindex" "$blogdir"/blog.html + printf "$(cat "$rss_template")\n" "$title" "$title" "$(basename "$basefile" ".html")" "$(basename "$basefile" ".html")" "$rssdate" "$(echo "$post" | recode "..html")" "$title" > "$tmpdir/rss" # RSS + sed -i "/<!-- RSS -->/r $tmpdir/rss" "$blogdir/rss/rss.xml" # ↓ + + sed -i -e '/<!-- RECENT POSTS -->/a '"$recent"'' "$blogdir"/index.html + [ "$numofrecent" -ge 7 ] && sed -i -n '/<!-- END-RECENT POSTS -->/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/index.html + + cp $drafts/img/$img "$imgdir"/blog && rm $drafts/img/$img && rm "$drafts"/$basefile + printf "\n${GREEN}Draft has been published.${RESET}\n\n" && update +} + +# Edit or Revise a published blog post +function blog_edit_pub () { + title() { + read -e -r -p "Enter a new title: " title + + url="$(echo "$title" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")" + old_url="$(echo $(basename "$basefile" ".html" | sed 's/ /-/g'))" + old_title="$(awk "/Post: $old_url/{getline; print}" "$datafile" | sed 's/^[^:]*: //')" + tags="$(sed -n "/$old_url/{n;n;n;n; p}" "$datafile" | sed -e 's/^[^:]*: //' -e 's/\,//g')" + tagsArr=(${tags}) + for i in "${tagsArr[@]}"; do + case ${i} in + "Informative") + sed -i -e "s/$old_title/$title/g" -e "s/$old_url/$url/g" "$blogdir"/blog/tags/informative.html + ;; + "Care") + sed -i -e "s/$old_title/$title/g" -e "s/$old_url/$url/g" "$blogdir"/blog/tags/care.html + ;; + "Rant") + sed -i -e "s/$old_title/$title/g" -e "s/$old_url/$url/g" "$blogdir"/blog/tags/rant.html + ;; + "Breeding-report") + sed -i -e "s/$old_title/$title/g" -e "s/$old_url/$url/g" "$blogdir"/blog/tags/breeding-reports.html + ;; + "Off-topic") + sed -i -e "s/$old_title/$title/g" -e "s/$old_url/$url/g" "$blogdir"/blog/tags/off-topic.html + ;; + "Seller-review") + sed -i -e "s/$old_title/$title/g" -e "s/$old_url/$url/g" "$blogdir"/blog/tags/seller-reivews.html + ;; + *) ;; + esac + done + sed -i -e "s/Post: $old_url/Post: $url/g" -e "s/Title: $old_title/Title: $title/g" "$datafile" # Update URL & Title in data file + sed -i -e "s/$old_title/$title/g" "$blogdir"/blog/$entry # Rename title & headings in $entry + sed -i -e "s/$old_title/$title/g" -e "s/$basename/$url/g" "$rss_file" # Update RSS title and URL + sed -i -e "s/"$entry"/"$url.html"/g" -e "s/$old_title/$title/g" "$blogdir"/blog.html # Update URLS & title in blog.html + sed -i -e "s/"$entry"/"$url.html"/g" -e "s/$old_title/$title/g" "$blogdir"/index.html # Update URLS & title in index.html + mv "$blogdir"/blog/$entry "$blogdir/blog/$url.html" # Rename file in /blog + printf "\n${GREEN}Title has been updated.${RESET}\n\n" && update + } + + descr() { + title="$(awk "/Post: $(basename "$basefile" ".html")/{getline; print}" "$datafile" | sed 's/^[^:]*: //')" + old_description="$(sed -n "/Title: $title/{ n; p }" $datafile | sed 's/^[^:]*: //')" + max=0 + while [ $max == 0 ]; do + read -e -p "Enter a new description (50 words limit): " new_description + [ $(echo "$new_description" | wc -w) -ge "50" ] && echo "Description must be less than 50 words." || max=1 + done + + tags="$(sed -n "/$(basename "$basefile" ".html")/{n;n;n;n; p}" "$datafile" | sed -e 's/^[^:]*: //' -e 's/\,//g')" + tagsArr=(${tags}) + for i in "${tagsArr[@]}"; do + case ${i} in + "Informative") + sed -i "s/$old_description/$new_description/g" "$blogdir"/blog/tags/informative.html + ;; + "Care") + sed -i "s/$old_description/$new_description/g" "$blogdir"/blog/tags/care.html + ;; + "Rant") + sed -i "s/$old_description/$new_description/g" "$blogdir"/blog/tags/rant.html + ;; + "Breeding-report") + sed -i "s/$old_description/$new_description/g" "$blogdir"/blog/tags/breeding-reports.html + ;; + "Off-topic") + sed -i "s/$old_description/$new_description/g" "$blogdir"/blog/tags/off-topic.html + ;; + "Seller-review") + sed -i "s/$old_description/$new_description/g" "$blogdir"/blog/tags/seller-reviews.html + ;; + *) ;; + esac + done + sed -i "s/Description: $old_description/Description: $new_description/g" "$datafile" + sed -i "s/$old_description/$new_description/g" "$blogdir"/blog/$entry + sed -i "s/$old_description/$new_description/g" "$blogdir"/blog.html + printf "\n${GREEN}Description has been updated.${RESET}\n\n" && update + } + + content() { + + title="$(basename $basefile .html | sed 's/-/ /g')" + url="$(echo $title | sed 's/ /-/g')" + old_rss="$(sed -n '/<!-- BLOG CONTENT -->/,/<!-- END BLOG CONTENT -->/{/<!-- BLOG CONTENT -->/!{/<!-- END BLOG CONTENT -->/!p}}' "$blogdir/blog/$entry" | recode ..html | sed 's/&/\\&/g')" + "$EDITOR" "$blogdir"/blog/$entry + new_rss="$(sed -n '/<!-- BLOG CONTENT -->/,/<!-- END BLOG CONTENT -->/{/<!-- BLOG CONTENT -->/!{/<!-- END BLOG CONTENT -->/!p}}' "$blogdir/blog/$entry" | recode ..html | sed 's/&/\\&/g')" + sed -i -e "s~$old_rss~~g" -e '/LETS test RSS FEED/n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n; r'<(printf "$new_rss") "$rss_file" + printf "\n${GREEN}Description has been updated.${RESET}\n\n" && update + } + + image() { + read -e -r -p "Enter the path to a new image: " img + while [ ! -e "$img" ]; do + read -e -r -p "$img does not exist. Please try another path: " img + done + + old_img="$(cat "$datafile" | sed -n "/Post: $(basename "$entry" ".html")/{n;n;n; p}" | sed 's/^[^:]*: //' | cut -f 1 -d '.' >&1)" + img=$(echo "$img" | cut -f 1 -d '.' >&1) + if [[ -e "$drafts"/img/$img.jpg || -e "$blogdir"/assets/img/blog/$img.jpg ]] ; then + i="2" + while [[ -e "$drafts"/img/$img-$i.jpg || -e "$blogdir"/assets/img/blog/$img-$i.jpg ]]; do ((i++)); done + mv "$img.jpg" "$img-$i.jpg" + cp "$img-$i.jpg" "$blogdir"/assets/img/blog/ + rm "$blogdir"/assets/img/blog/$old_img.jpg + mv "$img-$i.jpg" "$img.jpg" + else cp "$img.jpg" "$imgdir"/blog/ + fi + + sed -i "s/Image: $old_img/Image: $img/g" "$datafile" + sed -i "s/$old_img/$img/g" "$blogdir"/blog.html + printf "\n${GREEN}Index image has been updated.${RESET}\n\n" && update + } + + printf "\n\nRevising a public entry: %s:\nUsage:\n\tt = Title\n\td = Description\n\tc = Content\n\ti = Image\n\n" "$entry" + read -p "How would you like proceed? " cmd + case "$cmd" in + t) title ;; + d) descr ;; + c) content ;; + i) image ;; + *) printf "Exiting..\n\n" && exit 1 ;; + esac +} + + +# Create, Revise, Publish, +function blog () { + printf "\nEditing arachnida.blog\nUsage:\n\tn = New Draft\n\tp = Publish Draft\n\te = Edit Draft\n\tr = Revise published post\n\tt = Delete draft\n\td = Delete publish post\n\n" + read -p "How would you like proceed? " cmd + case "$cmd" in + n*) blog_draft ;; + p*) listitem "$drafts" publish && blog_pub ;; + e*) listitem "$drafts" edit && edit_draft ;; + r*) listitem "$blogdir/blog" revise public entry && blog_edit_pub ;; + t*) listitem "$drafts" delete && confirm delete && del_draft ;; + d*) listitem "$blogdir/blog" delete && confirm delete && blog_pub_del ;; + *) printf "Exiting..\n\n" && exit 1 ;; + esac +} + + +function shop () { + $empty +} + +function gallery () { + $empty +} + + +# Webpick +case "$1" in + -b*) blog ;; + -s*) shop ;; + -g*) gallery ;; + *) printf "\n\nab blog system by Ben Nagy <ben@arachnida.blog>\n\nUsage:\n ab -b: blog\n ab -s: shop\n ab -g: gallery\n\n" ;; +esac + + +# TODO + +# Allow revision of tags +# calculate article read time diff --git a/scripts/archive/blog/doc/data.txt b/scripts/archive/blog/doc/data.txt new file mode 100644 index 0000000..c034039 --- /dev/null +++ b/scripts/archive/blog/doc/data.txt @@ -0,0 +1,5 @@ +Post: foo post +Title: foo title +Description: foo description +Image: /home/user/foo.jpg +Tags: Informative, Off-topic, diff --git a/scripts/archive/blog/doc/templates/index-tag-template.html b/scripts/archive/blog/doc/templates/index-tag-template.html new file mode 100644 index 0000000..bc63ce9 --- /dev/null +++ b/scripts/archive/blog/doc/templates/index-tag-template.html @@ -0,0 +1,8 @@ +<article> + <a href="../%s"> + <img src="../../assets/img/blog/%s" alt="%s"></a> + <h1><a href="../%s">%s</a></h1> + <h2>%s</h2> + <p>%s</p> + <h3><a href="../%s">Read more...</a></h3> +</article> diff --git a/scripts/archive/blog/doc/templates/index-template.html b/scripts/archive/blog/doc/templates/index-template.html new file mode 100644 index 0000000..64d0992 --- /dev/null +++ b/scripts/archive/blog/doc/templates/index-template.html @@ -0,0 +1,8 @@ +<article> + <a href="blog/%s"> + <img src="assets/img/blog/%s" alt="%s"></a> + <h1><a href="blog/%s">%s</a></h1> + <h2>%s</h2> + <p>%s</p> + <h3><a href="blog/%s">Read more...</a></h3> +</article> diff --git a/scripts/archive/blog/doc/templates/rss-template.xml b/scripts/archive/blog/doc/templates/rss-template.xml new file mode 100644 index 0000000..2022ec1 --- /dev/null +++ b/scripts/archive/blog/doc/templates/rss-template.xml @@ -0,0 +1,16 @@ + +<!-- START: %s --> +<item> + <title>%s</title> + <link>https://arachnida.blog/blog/%s</link> + <guid>https://arachnida.blog/blog/%s</guid> + + <pubDate>%s</pubDate> + + <description> + <![CDATA[ + %s + ]]> + </description> +</item> +<!-- END: %s --> diff --git a/scripts/archive/blog/doc/templates/template.html b/scripts/archive/blog/doc/templates/template.html new file mode 100644 index 0000000..c0c8afb --- /dev/null +++ b/scripts/archive/blog/doc/templates/template.html @@ -0,0 +1,59 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <title>%s</title> + + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <meta name="robots" content="index, follow"> + <meta name="description" content="%s"> + + <link rel="shortcut icon" type="image/x-icon" href="../assets/img/main/logo.ico"> + <link rel="stylesheet" type="text/css" href="../css/main.css"> + <link rel='alternate' type='application/rss+xml' title="Arachnida RSS Feed" href='../rss/rss.xml'> + </head> + + <body> + <div class="container"> + <header> + <h1>Arachnida blog</h1> + </header> + + <nav> + <a href="../index.html"><h3>Home</h3></a> + <a href="../blog.html"><h3 id="active">Blog</h3></a> + <a href="../gallery.html"><h3>Gallery</h3></a> + <a href="https://shop.arachnida.blog"><h3>Shop</h3></a> + </nav> + + <main> + <div class="blog-container"> + <h1 id="blog-title">%s</h1> + <h3>%s</h3> + <div class="blog-content"> + <!-- BLOG CONTENT --> + + <!-- END BLOG CONTENT --> + </div> + </div> + + <section id="tagged"> + <h2>Tagged</h2> + <div class="tagged-content"> + <!-- TAGS --> + </div> + </section> + </main> + + <footer> + <hr> + <h3>arachnida.blog</h3> + + <br> + <a href="../assets/img/main/monero.png" title="Donate"><img src="../assets/img/main/monero.svg" alt="XMR"></a> + <a href="../rss/rss.xml" title="RSS Feed"><img src="../assets/img/main/rss.svg" alt="RSS"></a> + <a href="mailto:ben@arachnida.blog" title="Contact"><img src="../assets/img/main/mail.svg" alt="Email"></a> + </footer> + </div> + </body> +</html> diff --git a/scripts/archive/blog/rss-parse.sh b/scripts/archive/blog/rss-parse.sh new file mode 100755 index 0000000..9f635d4 --- /dev/null +++ b/scripts/archive/blog/rss-parse.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +[ ! -f "$1" ] && + echo "Give \`sup\` a page which has been added/updated." && + exit 1 + +website="https://domain.com" +rssfile="../rss/blog.xml" +replchar='^' + +link="$website/$1" +title="$(sed -n 's/<title>\(.*\)<\/title>/\1/Ip' "$1")" + +if grep -q "<guid.*>$link</guid>" "$rssfile"; then + guid="$link#$(date '+%y%m%d%H%M%S')" + title="$title (Updated)" + echo "Explain the nature of the update:" + read -r content + [ -z "$content" ] && content="New updates to $link" +else + + guid=$link + content="$(tr '\n' $replchar < "$1" | sed " + s/.*<body>// + s/<footer>.*<\/footer>// + s/<nav>.*<\/nav>// + s/<\/body>.*// + " | tr -s $replchar '\n')" +fi + +rssdate="$(LC_TIME=en_US date '+%a, %d %b %Y %H:%M:%S %z')" + +temp="$(mktemp)"; +trap 'rm -f "$temp"' 0 1 2 3 15 +echo " +<item> +<title>$title</title> +<guid>$guid</guid> +<link>$link</link> +<pubDate>$rssdate</pubDate> +<description><![CDATA[$content +]]></description> +</item> +" > "$temp" + +sed -i "/<!-- rss -->/r $temp" "$rssfile" |