#!/bin/sh VERSION=0.1.1 if [ ! ${EDITOR} ]; then EDITOR="vim" fi MARGIN=72 FORMAT=html INDEX=index.html DIR=.bj DRAFT=${DIR}/.bj.tmp.$$ DATE=`date` YEAR=`date "+%Y"` TIME=`date "+%Y-%m-%dT%H:%M:%S"` SEC=`date "+%s"` TITLE= INDEXTITLE="The Italian BlogJob" DEFAULT_TITLE="Entry # ${SEC}"; HEADERTXT= # text or `cat some.header.txt` FOOTERTXT= #"Powered by blogjob - © MMVIII" TOP_TPL=./bj-top.tpl BOT_TPL=./bj-bottom.tpl PREFORMAT_FILTER=./bj-filter # the filter is assumed to be executable, else it is ignored USE_EDITOR=1 LISTENSTDIN=0 SORT_ALL="sort -t. +0f -1 +1nr" # sorts all in file listing SORT_NEWEST="sort -t. -nr" # sorts all new to old SORT_OLDEST="sort -t. -r" # sorts all old to new #PUBLISHED=`date "+%m/%d/%Y"` # date formated for index page entry PUBLISHED=$SEC OUTPUT_TOP=output_top OUTPUT_BOT=output_bottom # define custome formatting FORMAT_FUNC=format_with_par FORMAT_DISPATCHER=default_set_format_func FORMAT_CUSTOM_DISPATCHER=custom_set_format_func # define custom functions file; see example in bj/sample-custom-format/ FORMAT_CUSTOM_DEFS=./bj-custom.sh UPDATE_INDEX=default_update_index CUSTOM_SETUP=default_setup #ROOT="$HOME/public_html" FTPDEST="stixx" # # bj is a zero configuration, commandline blog tool that # requires NO installation other than dropping the bj # script into your ~/bin, or someother directory in your PATH # # bj accepts input when in batch mode (-b), so it is well # suited for use in batch situations, such as in a cronjob # # System utilities required via PATH: # cd, pwd, ls, sort, head, tail, cat, grep, groff, fold, expr (built in) disclaimer() { echo "Copyright (c) 2007 Joe Galaxy" echo "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:" echo "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software." echo "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE." } # # bj - the minimal, zero configuration command line blog thingy # # Instructions: # 1. put in directory accessible via PATH # 2. go to a web visible directory and type 'bj' # 3. put in your title and write your post in vi # 4. tell your mom to visit: http://..../yourdir/bj.html # # Tips: # # 1 You can force the index to be index.html using "-I", or # you can specify the index with "-i somefile.html". But, # if you do this, you'll have to specify this for all other # commands, otherwise bj defaults to bj.html # # 2 bj respects your EDITOR environmental variable # # CREDITS # Francois Saint-Jacques (fsaintjacques@networkdump.com) supplied 2nd patch ever :) # efbeha (efbeha@gmail.com) - supplied first patch ever :) # Oliver @ forums.bsdnexus.com # arun @ chat.taucher.net #bsd # J65nko @ bsdforums.com # The people beyond http://www.0x743.com/vee # vee version 0.0.9zeta # Joe Galaxy (joegalaxy at gmail dot com) # ideas: default_set_format_func() { case "$1" in default) FORMAT_FUNC=format_with_groff ;; groff) FORMAT_FUNC=format_with_groff ;; fold) FORMAT_FUNC=format_with_fold ;; par) FORMAT_FUNC=format_with_par ;; none) FORMAT_FUNC=with_no_formatting ;; # if not a supplied format, see if it is in the custom format file, if it exists *) if [ -e "${FORMAT_CUSTOM_DEFS}" ]; then # call dispatch function that is defined in # the custom format file, pass on format nickname ${FORMAT_CUSTOM_DISPATCHER} "${1}" else echo "bad format type" die_cleanly fi esac echo using $FORMAT_FUNC } usage() { echo " " echo "bj - the Zero-conf, commandline blog tool thingy " echo " " echo "Version: ${VERSION} " echo " " echo "Usage: " echo " See below. " echo " " echo "Options: " echo " -b batch mode; used when piping in msg via stdin " echo " -B file define bottom template; default is ./bj-bottom.tpl " echo " -c [1-9\d*] specify the number of characters 'fold' allows per line " echo " this only applies when 'fold' (-f) is used " echo " -d 'publis_dir' specify the directory .bj is in - defaults to PWD " echo " -f 'format' use defined format instead of the default, groff;" echo " 'groff', 'fold', and 'none' are supported out of the box" echo " -F publish the given source directory to ftp destination " echo " Remember you must supply a valid directory name. " echo " -h prints this blurb " echo " -i 'custom.html' specify a custom index file over the default " echo " -I force index file to be \"index.html\" " echo " -l edit latest post's *.txt; used with '-r' publishes changes;" echo " calls reformat automatically; " echo " -L [1-9\d*] edit the Nth latest, relative to last post; lp starts at 1" echo " -m 'message ...' specify entry message at commandline and avoid vi " echo " -n lists all entries, newest first, then quits " echo " -o lists all entries, oldest first, then quits " echo " -p see what *raw files don't have an entry in the INDEX " echo " -P forever deletes all *raw and formatted files associated with" echo " posts that are listed with -p; " echo " -r [1-9\d*] reformats the Nth latest post " echo " -R reformats _all_ .bj/*.txt files; -c applies as well " echo " -s "summary" placed below title in INDEX " echo " -t 'title' specify title at commandline and avoid annoying default prompt" echo " -T file define top template; default is ./bj-top.tpl " echo " -v version and exit " echo " -x filter defines filter if not using default "./bj-pre"; filter " echo " must be executable, i.e., chmod 755 bj-pre " echo " " echo "Examples: " echo " " echo "%bj " echo " " echo " user will be prompted for title and presented with vi " echo " " echo " if no default dir/files are found, they will be created " echo " " echo "%bj -t \"this is the title\" " echo " " echo " user will just be presented with a vi session; " echo " " echo "%cat text.txt | bj -b -t \"my title\" -m \"text to go before stdin\" " echo " " echo " publishes contents of text.txt with provided title; -m's msg will be " echo " shown above the cat'd text " echo " " echo "%bj -l # edit and reformat the latest post " echo "%bj -L 5 # allows one to edit and reformats the fifth latest post " echo "%bj -r 8 # reformats the 8th latest post " echo "%bj -R # reformats ALL posts that have *.txt files " echo " " echo "To delete a post forever: " echo "1) delete the entry in the INDEX " echo "2) purge the entry: " echo " bj -p # make sure it is the one you want to purge" echo " bj -P # purge it!" echo " " echo " brings up the latest entry as a vi sessions; when changes are save, " echo " all messages are reformatted " echo " " echo "Notes: " echo " " echo "1. Batch mode looks for piped input via STDIN; if none after a short time, " echo " message creation fails UNLESS something was passed in via '-m' as well. " echo " If nothing was passed in via '-t' for the title, some default is used; " echo " This is set at the top of the script as 'DEFAULT_TITLE'. " echo " " echo "2. Interactive mode (default) prompts for a title if no '-t' is provided. " echo " Such is the case even if '-m' is used. If '-m' is not used in this " echo " " echo "3. Patches are welcome; the goal is not more feature bloat, but a nicer " echo " way of dealing with standard in, etc would be welcomed. " echo " " echo `disclaimer` exit 1 } # formats post link on index page default_update_index() { echo "${PUBLISHED}: ${TITLE}" >> ${INDEX} if [ -n "${SUMMARY}" ]; then SEC=`expr $SEC - 1` echo "${SUMMARY}" >> ${INDEX} fi } output_top() { echo ${HEADERTXT} > ${FINAL} if [ -e "${TOP_TPL}" ]; then cat "${TOP_TPL}" >> ${FINAL} echo "
" >> ${FINAL}
else
# echo "" >> ${FINAL}
# echo "" >> ${FINAL}
# echo "${TITLE} - ${DATE} " >> ${FINAL}
# echo "" >> ${FINAL}
# echo "" >> ${FINAL}
# echo "[index][raw][main]" >> ${FINAL}
echo " " >> ${FINAL}
echo "${INDEXTITLE} " >> ${FINAL}
echo "" >> ${FINAL}
echo " " >> ${FINAL}
echo "
" >> ${FINAL}
echo "
" >> ${FINAL}
echo "" >> ${FINAL}
fi
echo >> ${FINAL}
}
output_bottom()
{ echo >> ${FINAL}
echo >> ${FINAL}
echo ${FOOTERTXT} >> ${FINAL}
if [ -e "${BOT_TPL}" ]; then
cat "${BOT_TPL}" >> ${FINAL}
else
# echo "" >> ${FINAL}
# echo "" >> ${FINAL}
# echo "" >> ${FINAL}
echo "" >> ${FINAL}
echo "" >> ${INDEX}
# header stuff
echo "" >> ${INDEX}
echo "" >> ${INDEX}
echo "" >> ${INDEX}
# footer stuff
echo "" >> ${INDEX}
echo "