3 # pinosaur's blog script
5 blog_index_file="blogindex.html"
6 rolling_file="rolling.html"
7 template_file="template.html"
11 [ ! -z "$EDITOR" ] && EDITOR="vim"
15 read -p "Initialize blog? [y/n] " ask
16 [ "$ask" != "y" ] && exit 0
18 mkdir -p "$data_dir/drafts" &&\
19 mkdir -p "$data_dir/published" &&\
20 mkdir -p "$data_dir/html"
22 echo "Created blog files"
26 start_token="<!-- BLOG START -->"
27 end_token="<!-- BLOG END -->"
29 read -p "Are you sure you want to refresh? [y/n] " ask
30 [ "$ask" != "y" ] && exit 0
32 # delete everything between tokens
33 sed -i "/$start_token/,/$end_token/{/$start_token/!{/$end_token/!d}}" "$blog_index_file"
35 # deletes all html files and republishes all published files
39 [ -z "$1" ] && echo "Please give your blog post a name (you should put it inside quotations)" && exit 1
42 sanitized=`echo -n "$1" | sed -e 's/[^A-Za-z0-9 _-]//g'| sed -e 's/ /-/g'`
45 $EDITOR "$data_dir/drafts/$sanitized.draft.html"
50 drafts=`ls -1 "$data_dir/drafts" | sed -e 's/\.draft\.html$//'`
51 [ -z "$drafts" ] && echo "No drafts to publish" && exit 0
53 echo "Select which draft to publish"
57 to_publish=`ls -1 "$data_dir/drafts/" | sed -n "$choice p"`
58 [ -z "$to_publish" ] && echo "Invalid choice" && exit 1
61 sed -e "s/{{TITLE}}/$to_publish/g;
62 s/{{DATE}}/`date +'%a, %b %d %H:%M'`/g" |\
63 sed -e "/{{BODY}}/r $data_dir/drafts/$to_publish" |\
64 sed -e "/{{BODY}}/d" \
65 > "$data_dir/html/${to_publish%.draft.html}.html"
67 mv "$data_dir/drafts/$to_publish" "$data_dir/published/"
69 # Add new entry to blog index (do something about indent??)
70 sed -i "/<!-- BLOG START -->/ a <h3>$to_publish<\\/h3>" "$blog_index_file"
76 published=`ls -1 "$data_dir/published" | sed -e 's/\.draft\.html$//'`
77 [ -z "$published" ] && echo "No posts to delete" && exit 0
79 echo "Select which post to delete"
80 echo "$published" | nl
83 to_delete=`ls -1 "$data_dir/published/" | sed -n "$choice p"`
84 [ -z "$to_delete" ] && echo "Invalid choice" && exit 1
86 mv "$data_dir/published/$to_delete" "$data_dir/drafts/" &&\
87 rm "$data_dir/html/${to_delete%.draft.html}.html"
89 # remove entry from blog index
92 # check to see if all required files are present
93 [ ! -f $blog_index_file ] && echo "missing $blog_index_file" && exit 1
94 [ ! -f $rolling_file ] && echo "missing $rolling_file" && exit 1
95 [ ! -f $template_file ] && echo "missing $template_file" && exit 1
96 [ ! -f $rss_file ] && echo "missing $rss_file" && exit 1
98 # possibly also check to see if index and rolling have the proper headers
101 # check if blog dir exists
102 [ ! -d $data_dir ] && init