backend changes. previews appear with basename

This commit is contained in:
Luke Smith 2018-09-02 18:55:12 -04:00
parent 010f65edd6
commit 46fe698dd6
1 changed files with 12 additions and 11 deletions

23
lb
View File

@ -22,9 +22,10 @@ getHelp() { \
listandReturn() { \
echo "Listing contents of $1."
ls -rc $1 | nl
ls -rc $1 | awk -F '/' '{print $NF}' | nl
read -rp "Pick an entry by number to $2, or press ctrl-c to cancel. " number
chosen=$(basename $(ls -rc $1 | nl | grep -w "$number" | awk '{print $2}'))
chosen=$(ls -rc $1 | nl | grep -w "$number" | awk '{print $2}')
#chosen=$(basename $(ls -rc $1 | nl | grep -w "$number" | awk '{print $2}'))
}
getTitle() { \
@ -38,22 +39,22 @@ postNew() { \
finalize() { \
listandReturn "$dir"/blog/.drafts finalize
url=$(cat "$dir"/blog/.drafts/"$chosen" | grep -o "<h2 id='\(.\)*'>" | cut -d "'" -f2)
title=$(cat "$dir"/blog/.drafts/"$chosen" | grep -o "<h2 id='\(.\)*h2>" |sed -e 's/<[^>]*>//g')
echo "AddDescription \"$title\" $chosen" >> "$dir"/blog/.htaccess
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
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 "$dir"/blog/.drafts/$chosen | awk 'a==1;/^$/{a=1}')\n]]></description>\n</item>\n"> $tmpdir/rss.xml
echo -e "\n<div class=\"entry\">\n$(cat "$dir"/blog/.drafts/$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$(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
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" "$dir"/blog/.drafts/"$chosen" > "$dir"/blog/"$chosen"
rm "$dir"/blog/.drafts/"$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" "$chosen" > "$dir"/blog/"$(basename $chosen)"
rm "$chosen"
}
delete() { \
@ -61,7 +62,7 @@ delete() { \
base=$(echo "$chosen" | cut -f1 -d'.')
read -rp "Really delete \"$base\"? (y/N) " choice
[[ $choice =~ [Yy] ]] || exit
rm "$dir"/blog/"$chosen" && echo "Blog post deleted from directories."
rm "$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."
@ -72,7 +73,7 @@ discard() { \
base=$(echo "$chosen" | cut -f1 -d'.')
read -rp "Really discard \"$base\"? (y/N) " choice
[[ $choice =~ [Yy] ]] || exit
rm "$dir"/blog/.drafts/"$chosen" && echo "Blog draft discarded."
rm "$chosen" && echo "Blog draft discarded."
}
case "$1" in