X-Git-Url: https://git.danieliu.xyz/?p=pb.git;a=blobdiff_plain;f=pb;h=5f85f3cb2e31af714815d95a6631dbeca60b66be;hp=7905b54c34ad079cc1343be2f00f6fd691cfb5b9;hb=4cf95efbc3d417d5fe04a038f7fe9a5c0907d364;hpb=eb9cbcb1755771257e005eb86c1225113365fae8 diff --git a/pb b/pb index 7905b54..5f85f3c 100755 --- a/pb +++ b/pb @@ -2,7 +2,7 @@ # pinosaur's blog script data_dir="blog" -website_url="https://www.youtube.com/watch?v=oHg5SJYRHA0/" +website_url="https://www.youtube.com/watch?v=oHg5SJYRHA0/" # no ending slash blog_index_file="blogindex.html" rolling_file="rolling.html" rss_file="rss.xml" @@ -18,13 +18,20 @@ init() { [ "$ask" != "y" ] && echo "Cancelled init" && exit 0 mkdir -p "$data_dir/drafts" "$data_dir/published" "$data_dir/html" "$data_dir/templates" "$data_dir/backups" - echo '

{{TITLE}}

' >> "$data_dir/templates/$index_template" + echo '{{TITLE}}' >> "$data_dir/templates/$index_template" echo -e '
\n

{{TITLE}}

\n

{{DATE}}

\n

{{BODY}}

\n
' >> "$data_dir/templates/$rolling_template" echo -e '\n{{TITLE}}\n\n<\description>\n<\item>' \ >> "$data_dir/templates/$rss_template" echo "Successfully created blog files." } +refresh() { + read -p "Are you sure you want to refresh? [y/n] " ask + [ "$ask" != "y" ] && echo "Aborting..." && exit 0 + + echo -e "$blog_index_file\n$rolling_file\n$rss_file" | xargs sed -i "//,//{//!{//!d}}" + echo "Successfully refreshed." +} backup() { backup_name=`mktemp --tmpdir="$data_dir/backups" -d "backup_$(date +'%b-%d')_XXX"` @@ -46,8 +53,8 @@ sub() { sed "\$a " |\ sed "s|{{TITLE}}|$1|g; s|{{DATE}}|`date +'%a, %b %d %H:%M'`|g; - s|{{URL}}|$website_url/$1|g" |\ - sed "/{{BODY}}/r $data_dir/drafts/$1" |\ + s|{{URL}}|$website_url/blog/html/$1.html|g" |\ + sed "/{{BODY}}/r $data_dir/drafts/$1.draft.html" |\ sed "/{{BODY}}/d" } @@ -98,7 +105,7 @@ delete() { } # check to see if all required files are present -[ -f $blog_index_file ] && [ -f $rolling_file ] && [ -f $blog_template ] && [ -f $rss_file ] || { echo "You are missing a file, please check that you have $blog_index_file, $template_file, $rolling_file and $rss_file in your home directory" && exit 1; } +[ -f $blog_index_file ] && [ -f $rolling_file ] && [ -f $blog_template ] && [ -f $rss_file ] || { echo "You are missing a file, please check that you have $blog_index_file, $blog_template, $rolling_file and $rss_file in your home directory" && exit 1; } # check if blog dir exists [ ! -d $data_dir ] && init && exit 0 @@ -108,5 +115,6 @@ case $1 in p|publish) publish;; d|delete) delete;; b|backup) backup;; + r|refresh) refresh;; h|*) echo -e "=-=-=-=-=-=-= Pb =-=-=-=-=-=-=\nAvailable commands:\nn - new blog post\np - publish existing blog post\nd - deletes published post\nb - creates a backup";; esac