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"
16 mkdir -p "$data_dir/drafts" &&\
17 mkdir -p "$data_dir/published" &&\
18 mkdir -p "$data_dir/html"
23 # add a confirmation of sorts here
25 # deletes all html files and republishes all published files
29 [ -z "$1" ] && echo "please supply a name" && exit 1
32 sanitized=`echo -n "$1" | sed -e 's/[^A-Za-z0-9 _-]//g'| sed -e 's/ /-/g'`
35 $EDITOR "$data_dir/drafts/$sanitized.draft.html"
40 drafts=`ls -1 "$data_dir/drafts" | sed -e 's/\.draft\.html$//'`
41 [ -z "$drafts" ] && echo "No drafts to publish" && exit 0
43 echo "Select which post to publish"
47 to_publish=`ls -1 "$data_dir/drafts/" | sed -n "$choice p"`
48 [ -z "$to_publish" ] && echo "Invalid choice" && exit 1
51 sed -e "s/{{TITLE}}/$to_publish/g;
52 s/{{DATE}}/`date +'%a, %b %d %H:%M'`/g" |\
53 sed -e "/{{BODY}}/r $data_dir/drafts/$to_publish" |\
54 sed -e "/{{BODY}}/d" \
55 > "$data_dir/html/${to_publish%.draft.html}.html"
57 mv "$data_dir/drafts/$to_publish" "$data_dir/published/"
59 # Add new entry to blog index
67 published=`ls -1 "$data_dir/published" | sed -e 's/\.draft\.html$//'`
68 [ -z "$published" ] && echo "No posts to delete" && exit 0
70 echo "Select which post to delete"
71 echo "$published" | nl
74 to_delete=`ls -1 "$data_dir/published/" | sed -n "$choice p"`
75 [ -z "$to_delete" ] && echo "Invalid choice" && exit 1
77 mv "$data_dir/published/$to_delete" "$data_dir/drafts/" &&\
78 rm "$data_dir/html/${to_delete%.draft.html}.html"
80 # remove entry from blog index
83 # check to see if all required files are present
84 [ ! -f $blog_index_file ] && echo "missing $blog_index_file" && exit 1
85 [ ! -f $rolling_file ] && echo "missing $rolling_file" && exit 1
86 [ ! -f $template_file ] && echo "missing $template_file" && exit 1
87 [ ! -f $rss_file ] && echo "missing $rss_file" && exit 1
89 # possibly also check to see if index and rolling have the proper headers
92 # check if blog dir exists
93 [ ! -d $data_dir ] && init
100 r|refresh) echo "refresh";;
101 h|*) echo "helper" && exit 1;;