lb

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit fe0ff958cf96602e7b1da4643b5c2f2cbbc54e45
parent 9ef0f2633355da1e051c307c3c1359feaf2b4c82
Author: Luke Smith <luke@lukesmith.xyz>
Date:   Sun,  2 Sep 2018 23:46:37 -0400

fixes and new vars

Diffstat:
Mlb | 32+++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/lb b/lb @@ -8,6 +8,8 @@ indexfile="blogindex.html" stylesheet="..\/style.css" # Characters should be escaped for this variable. author="<a href=\"$website\">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 "<h2 id='$url'>$title</h2>\n<small>[<a href=\"$blogfile#$url\">link</a>&mdash;<a href=\"blog/$url.html\">standalone</a>]</small>\n\n<++>" >> "$dir"/blog/.drafts/$url.html && $EDITOR "$dir"/blog/.drafts/$url.html ;} + mkdir -p "$draftdir" + echo -e "<h2 id='$url'>$title</h2>\n<small>[<a href=\"$blogfile#$url\">link</a>&mdash;<a href=\"blog/$url.html\">standalone</a>]</small>\n\n<++>" >> "$draftdir"/$url.html && $EDITOR "$draftdir"/$url.html ;} finalize() { \ - listandReturn "$dir"/blog/.drafts finalize - url=$(cat "$chosen" | grep -o "<h2 id='\(.\)*'>" | cut -d "'" -f2) - title=$(cat "$chosen" | grep -o "<h2 id='\(.\)*h2>" |sed -e 's/<[^>]*>//g') - echo "AddDescription \"$title\" $(basename $chosen)" >> "$dir"/blog/.htaccess + listandReturn "$draftdir" finalize + url=$(grep -o "<h2 id='\(.\)*'>" "$draftdir"/"$chosen" | cut -d "'" -f2) + title=$(grep -o "<h2 id='\(.\)*h2>" "$draftdir"/"$chosen" | sed -e 's/<[^>]*>//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='<li>'$(date '+%Y %b %d')' &ndash; <a href="blog/'$url'.html">'$title'</a></li>' tmpdir=$(mktemp -d) - echo -e "\n<item>\n<title>$title</title>\n<guid>$website$blogfile#$url</guid>\n<pubDate>$rssdate</pubDate>\n<description><![CDATA[\n$(cat $chosen | awk 'a==1;/^$/{a=1}')\n]]></description>\n</item>\n"> $tmpdir/rss.xml - echo -e "\n<div class=\"entry\">\n$(cat $chosen)\n<small>$webdate</small>\n</div>\n" > $tmpdir/html.html + echo -e "\n<item>\n<title>$title</title>\n<guid>$website$blogfile#$url</guid>\n<pubDate>$rssdate</pubDate>\n<description><![CDATA[\n$(awk 'a==1;/^$/{a=1}' "$draftdir"/"$chosen")\n]]></description>\n</item>\n"> $tmpdir/rss.xml + echo -e "\n<div class=\"entry\">\n$(cat "$draftdir"/"$chosen")\n<small>$webdate</small>\n</div>\n" > $tmpdir/html.html sed -i "/<!-- LB -->/r $tmpdir/html.html" $blogfile sed -i "/<!-- LB -->/r $tmpdir/rss.xml" $rssfile sed -i "/<!-- LB -->/a $listformat" $indexfile header="<html>\n<head>\n<title>$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