/blog
Last active
December 20, 2015 16:18
Revisions
-
alexander-bauer revised this gist
Aug 5, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -61,7 +61,7 @@ generate_template() { Title: Description: Author: $AUTHOR Date: $(date '+%Y-%m-%d %H:%M') Lang: $LANG --- " > "$1" -
alexander-bauer revised this gist
Aug 5, 2013 . 1 changed file with 7 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,10 +40,14 @@ TEMPFILE="$(tempfile -p blog-)" # FUNCTIONS # ############# # Check flags parses the the argument list for flags, and if it finds # any, ceases normal execution. check_flags() { CURFLAG="$1" if [ "$CURFLAG" == "-r" ]; then echo "Regenerating..." regenerate exit 0 fi } @@ -95,7 +99,7 @@ exit_unfinished() { # exit. trap exit_unfinished INT check_flags $* generate_template "$TEMPFILE" compose -
alexander-bauer created this gist
Aug 5, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,102 @@ #!/bin/bash # ## blog # # This script creates a temporary file with [trofaf][] header data and # opens it with an editor. When this is saved and closed, the file is # moved to a particular directory with a title given either as the # first argument, or read on the command line after completion. # # Once the file has been successfully renamed to markdown, if REGENDIR # is set, the static site is regenerated with 'trofaf -g'. # # [trofaf]: https://github.com/PuerkitoBio/trofaf # ############# # VARIABLES # ############# AUTHOR="Your Name" LANG="en" EDITOR="emacs -nw -f markdown-mode" OUTDIR="$HOME/yourblog/posts" REGENDIR="$HOME/yourblog" REGENOPTIONS='-n "Your Blog Name" -t "Tagline" -b http://blog.you.com' ################## # SANE DEFAUALTS # ################## REGENERATE="trofaf -g" SUFFIX="md" FILENAME="$1" TEMPFILE="$(tempfile -p blog-)" ############# # FUNCTIONS # ############# check_flags() { if [ "$1" == "-r" ]; then regenerate exit fi } regenerate() { cd "$REGENDIR" $REGENERATE $REGENOPTIONS } generate_template() { echo "--- Title: Description: Author: $AUTHOR Date: $(date '+%Y-%M-%d %Hh') Lang: $LANG --- " > "$1" } compose() { # While $FILENAME is length 0, edit the tempfile, ask for a # filename, and read it into $FILENAME. while [ -z "$FILENAME" ]; do $EDITOR "$TEMPFILE" echo -n "Enter post filename: " read FILENAME done } add_post() { mv "$1" "$OUTDIR/$2.$SUFFIX" if [ ! -z "$REGENDIR" ]; then echo "Regenerating..." regenerate fi } exit_unfinished() { echo "\nAbandoning blogpost $TEMPFILE" exit 1 } ######## # MAIN # ######## # If the routine is interrupted, show the path of the tempfile and # exit. trap exit_unfinished INT check_flags generate_template "$TEMPFILE" compose add_post "$TEMPFILE" "$FILENAME"