From fe0ff958cf96602e7b1da4643b5c2f2cbbc54e45 Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Sun, 2 Sep 2018 23:46:37 -0400 Subject: [PATCH] fixes and new vars --- lb | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lb b/lb index 8c0dbea..a416238 100755 --- a/lb +++ b/lb @@ -8,6 +8,8 @@ indexfile="blogindex.html" stylesheet="..\/style.css" # Characters should be escaped for this variable. author="Luke Smith<\/a>" dir=$(pwd) +draftdir="$dir"/blog/.drafts +blogdir="$dir"/blog # See other variables defined later, such as `header` and `webdate` for more customizability. @@ -28,47 +30,47 @@ listandReturn() { \ } getTitle() { \ - echo "Post will be stored as draft in $dir/blog/.drafts until finalized." + echo "Post will be stored as draft in $draftdir until finalized." read -rp "Give a title for your post: " title url=$(echo $title | sed -e "s/'\|\"\|=\|+\|_\|,\|:\|;\|?\|!\|@\|\*\|&\|(\|)\|[\|]\|<\|>//g;s/ /-/g" | tr '[:upper:]' '[:lower:]') ;} postNew() { \ - mkdir -p "$dir"/blog/.drafts - echo -e "

$title

\n[
linkstandalone]\n\n<++>" >> "$dir"/blog/.drafts/$url.html && $EDITOR "$dir"/blog/.drafts/$url.html ;} + mkdir -p "$draftdir" + echo -e "

$title

\n[linkstandalone]\n\n<++>" >> "$draftdir"/$url.html && $EDITOR "$draftdir"/$url.html ;} finalize() { \ - listandReturn "$dir"/blog/.drafts finalize - url=$(cat "$chosen" | grep -o "

" | cut -d "'" -f2) - title=$(cat "$chosen" | grep -o "

]*>//g') - echo "AddDescription \"$title\" $(basename $chosen)" >> "$dir"/blog/.htaccess + listandReturn "$draftdir" finalize + url=$(grep -o "

" "$draftdir"/"$chosen" | cut -d "'" -f2) + title=$(grep -o "

]*>//g') + echo "AddDescription \"$title\" $chosen" >> "$blogdir"/.htaccess rssdate=$(date '+%a, %d %b %Y %H:%M:%S %z') webdate=$(date '+%a, %d %b %Y %H:%M:%S %z') listformat='
  • '$(date '+%Y %b %d')' – '$title'
  • ' tmpdir=$(mktemp -d) - echo -e "\n\n$title\n$website$blogfile#$url\n$rssdate\n\n\n"> $tmpdir/rss.xml - echo -e "\n
    \n$(cat $chosen)\n$webdate\n
    \n" > $tmpdir/html.html + echo -e "\n\n$title\n$website$blogfile#$url\n$rssdate\n\n\n"> $tmpdir/rss.xml + echo -e "\n
    \n$(cat "$draftdir"/"$chosen")\n$webdate\n
    \n" > $tmpdir/html.html sed -i "//r $tmpdir/html.html" $blogfile sed -i "//r $tmpdir/rss.xml" $rssfile sed -i "//a $listformat" $indexfile header="\n\n$title<\/title>\n<link rel='stylesheet' type='text\/css' href='$stylesheet'>\n<meta charset='utf-8'\/>\n<\/head>\n<body>" footer="<\/body>\n<footer>by <strong>$author<\/strong><\/footer>\n<\/html>" - sed "s/href=\"/href=\"..\//g;s/\.\.\/http/http/g;0,/^/s//$header/;0,/<h2 id=/s//<h1 id=/;0,/h2>/s//h1>/;\$a$footer" "$chosen" > "$dir"/blog/"$(basename $chosen)" - rm "$chosen" + sed "s/href=\"/href=\"..\//g;s/\.\.\/http/http/g;0,/^/s//$header/;0,/<h2 id=/s//<h1 id=/;0,/h2>/s//h1>/;\$a$footer" "$draftdir"/"$chosen" > "$blogdir"/"$chosen" + rm "$draftdir"/"$chosen" } delete() { \ - listandReturn "$dir/blog/*.html" delete + listandReturn "$blogdir/*.html" delete base=$(echo "$chosen" | cut -f1 -d'.') read -rp "Really delete \"$base\"? (y/N) " choice [[ $choice =~ [Yy] ]] || exit - rm "$chosen" && echo "Blog post deleted from directories." + rm "$blogdir"/"$chosen" && echo "Blog post deleted from directories." sed -i "/<item/{:a;N;/<\/item>/!ba};/$base/d" $rssfile && echo "Entry removed from RSS feed file." sed -i "/<div/{:a;N;/<\/div>/!ba};/$base/d" $blogfile && echo "HTML code removed from blogfile." sed -i "/<li>.*<a href=\"blog\/$base.html\">/d" $indexfile && echo "Index file entry removed." } discard() { \ - listandReturn "$dir/blog/.drafts/*.html" discard + listandReturn "$draftdir/*.html" discard base=$(echo "$chosen" | cut -f1 -d'.') read -rp "Really discard \"$base\"? (y/N) " choice [[ $choice =~ [Yy] ]] || exit @@ -80,6 +82,6 @@ case "$1" in discard) discard ;; finalize) finalize ;; delete) delete ;; - edit) listandReturn "$dir/blog/.drafts/*.html" edit && vim "$chosen" ;; + edit) listandReturn "$draftdir/*.html" edit && vim "$chosen" ;; *) getHelp ;; esac