X-Git-Url: https://git.danieliu.xyz/?p=pb.git;a=blobdiff_plain;f=pb;h=7754f03a51041d846a03f52476c7b82aa34df780;hp=a221306aee845f6a6d9ec46ffccae0c60128f410;hb=adcadf190dca4ecef87ae0e3cb3d2f2affd46542;hpb=afdc3b16d6d77fb03df04c5ed1883e48064e0672 diff --git a/pb b/pb index a221306..7754f03 100755 --- a/pb +++ b/pb @@ -5,6 +5,7 @@ blog_index_file="blogindex.html" rolling_file="rolling.html" template_file="template.html" +index_entry_template="index_entry.html" rss_file="rss.xml" data_dir="blog" @@ -15,9 +16,9 @@ init() { read -p "Initialize blog? [y/n] " ask [ "$ask" != "y" ] && exit 0 - mkdir -p "$data_dir/drafts" &&\ - mkdir -p "$data_dir/published" &&\ - mkdir -p "$data_dir/html" + mkdir -p "$data_dir/drafts" "$data_dir/published" "$data_dir/html" "$data_dir/templates" + + echo '
{{TITLE}}
' >> "$data_dir/templates/$index_entry_template" echo "Created blog files" } @@ -29,8 +30,10 @@ refresh() { read -p "Are you sure you want to refresh? [y/n] " ask [ "$ask" != "y" ] && exit 0 - # delete everything between tokens + # delete everything between tokens (remove dupe code) sed -i "/$start_token/,/$end_token/{/$start_token/!{/$end_token/!d}}" "$blog_index_file" + sed -i "/$start_token/,/$end_token/{/$start_token/!{/$end_token/!d}}" "$rolling_file" + sed -i "/$start_token/,/$end_token/{/$start_token/!{/$end_token/!d}}" "$rss_file" # deletes all html files and republishes all published files } @@ -45,6 +48,14 @@ new() { $EDITOR "$data_dir/drafts/$sanitized.draft.html" } +sub() { + cat - |\ + sed -e "s/{{TITLE}}/$1/g; + s/{{DATE}}/`date +'%a, %b %d %H:%M'`/g" |\ + sed -e "/{{BODY}}/r $data_dir/drafts/$1" |\ + sed -e "/{{BODY}}/d" +} + publish() { drafts=`ls -1 "$data_dir/drafts" | sed -e 's/\.draft\.html$//'` @@ -55,22 +66,20 @@ publish() { read -p '> ' choice to_publish=`ls -1 "$data_dir/drafts/" | sed -n "$choice p"` + to_publish=${to_publish%.draft.html} [ -z "$to_publish" ] && echo "Invalid choice" && exit 1 - cat $template_file |\ - sed -e "s/{{TITLE}}/$to_publish/g; - s/{{DATE}}/`date +'%a, %b %d %H:%M'`/g" |\ - sed -e "/{{BODY}}/r $data_dir/drafts/$to_publish" |\ - sed -e "/{{BODY}}/d" \ - > "$data_dir/html/${to_publish%.draft.html}.html" - - mv "$data_dir/drafts/$to_publish" "$data_dir/published/" + cat $template_file | sub "$to_publish" \ + > "$data_dir/html/$to_publish.html" # Add new entry to blog index (do something about indent??) - sed -i "// a