diff options
| -rw-r--r-- | packages/atomfeed.source.sh | 14 | ||||
| -rw-r--r-- | packages/gemfeed.source.sh | 4 | ||||
| -rw-r--r-- | packages/generate.source.sh | 42 | ||||
| -rw-r--r-- | packages/git.source.sh | 12 | ||||
| -rw-r--r-- | packages/html.source.sh | 14 | ||||
| -rw-r--r-- | packages/md.source.sh | 8 |
6 files changed, 66 insertions, 28 deletions
diff --git a/packages/atomfeed.source.sh b/packages/atomfeed.source.sh index 4bfc60c5..e1ee4064 100644 --- a/packages/atomfeed.source.sh +++ b/packages/atomfeed.source.sh @@ -11,7 +11,9 @@ atomfeed::meta () { fi local -r meta_dir=$(dirname "$meta_file") - test ! -d "$meta_dir" && mkdir -p "$meta_dir" + if [[ ! -d "$meta_dir" ]]; then + mkdir -p "$meta_dir" + fi if [ ! -f "$meta_file" ]; then # Extract first heading as post title. @@ -29,12 +31,16 @@ local meta_email="$EMAIL" local meta_title="$title" local meta_summary="$summary. .....to read on please visit my site." META - test $is_draft == no && git::add meta "$meta_file" + if [[ $is_draft == no ]]; then + git::add meta "$meta_file" + fi return fi cat "$meta_file" - test $is_draft == yes && rm "$meta_file" + if [[ $is_draft == yes ]]; then + rm "$meta_file" + fi } # Retrieve the core content as XHTML of the blog post. @@ -114,7 +120,7 @@ ATOMFOOTER if ! diff -u <($SED 3d "$atom_file") <($SED 3d "$atom_file.tmp"); then log INFO 'Feed got something new!' mv "$atom_file.tmp" "$atom_file" - test "$USE_GIT" == yes && git::add gemtext "$atom_file" + git::add gemtext "$atom_file" else log INFO 'Nothing really new in the feed' rm "$atom_file.tmp" diff --git a/packages/gemfeed.source.sh b/packages/gemfeed.source.sh index bc91eaff..c842bb13 100644 --- a/packages/gemfeed.source.sh +++ b/packages/gemfeed.source.sh @@ -23,7 +23,7 @@ gemfeed::updatemainindex () { $SED -n '/^=> / { s| ./| ./gemfeed/|; p; }' "$gemfeed_dir/index.gmi" >> "$index_gmi.tmp" mv "$index_gmi.tmp" "$index_gmi" - test "$USE_GIT" == yes && git::add gemtext "$index_gmi" + git::add gemtext "$index_gmi" } # Generate a index.gmi in the ./gemfeed subdir. @@ -48,7 +48,7 @@ GEMFEED done mv "$gemfeed_dir/index.gmi.tmp" "$gemfeed_dir/index.gmi" - test "$USE_GIT" == yes && git::add gemtext "$gemfeed_dir/index.gmi" + git::add gemtext "$gemfeed_dir/index.gmi" gemfeed::updatemainindex } diff --git a/packages/generate.source.sh b/packages/generate.source.sh index 0e1f2e25..98cd2154 100644 --- a/packages/generate.source.sh +++ b/packages/generate.source.sh @@ -38,9 +38,11 @@ generate::fromgmi_add_docs () { local -r dest=${src/gemtext/$format} local -r dest_dir=$(dirname "$dest") - test ! -d "$dest_dir" && mkdir -p "$dest_dir" + if [[ ! -d "$dest_dir" ]]; then + mkdir -p "$dest_dir" + fi cp "$src" "$dest" - test "$USE_GIT" == yes && git::add "$format" "$dest" + git::add "$format" "$dest" } # Remove docs from output format which aren't present in Gemtext anymore. @@ -50,13 +52,17 @@ generate::fromgmi_cleanup_docs () { local dest=${src/.$format/.gmi} dest=${dest/$format/gemtext} - test ! -f "$dest" && test "$USE_GIT" == yes && git::rm "$format" "$src" + if [[ ! -f "$dest" ]]; then + git::rm "$format" "$src" + fi } # Convert the Gemtext Atom feed to a HTML Atom feed. generate::convert_gmi_atom_to_html_atom () { local -r format="$1"; shift - test "$format" != html && return + if [[ "$format" != html ]]; then + return + fi log INFO 'Converting Gemtext Atom feed to HTML Atom feed' @@ -64,7 +70,7 @@ generate::convert_gmi_atom_to_html_atom () { < $CONTENT_BASE_DIR/gemtext/gemfeed/atom.xml \ > $CONTENT_BASE_DIR/html/gemfeed/atom.xml - test "$USE_GIT" == yes && git::add "$format" "$CONTENT_BASE_DIR/html/gemfeed/atom.xml" + git::add "$format" "$CONTENT_BASE_DIR/html/gemfeed/atom.xml" } # Internal helper function for generate::fromgmi @@ -75,7 +81,9 @@ generate::_fromgmi () { dest=${dest/.gmi/.$format} local dest_dir=$(dirname "$dest") - test ! -d "$dest_dir" && mkdir -p "$dest_dir" + if [[ ! -d "$dest_dir" ]]; then + mkdir -p "$dest_dir" + fi if [[ "$format" == html ]]; then cat "$HTML_HEADER" > "$dest.tmp" @@ -87,11 +95,13 @@ generate::_fromgmi () { fi local title=$($SED -n '/^# / { s/# //; p; q; }' "$src" | tr '"' "'") - test -z "title" && title=$SUBTITLE + if [[ -z "$title" ]]; then + title=$SUBTITLE + fi $SED -i "s|%%TITLE%%|$title|g" "$dest.tmp" mv "$dest.tmp" "$dest" - test "$USE_GIT" == yes && git::add "$format" "$dest" + git::add "$format" "$dest" } # Generate a given output format from a Gemtext file. @@ -102,7 +112,7 @@ generate::fromgmi () { log INFO "Generating $* from Gemtext" while read -r src; do - (( num_gmi_files++ )) + num_gmi_files=$(( num_gmi_files + 1 )) for format in "$@"; do generate::_fromgmi "$src" "$format" done @@ -114,7 +124,7 @@ generate::fromgmi () { log VERBOSE "Adding other docs to $*" while read -r src; do - (( num_doc_files++ )) + num_doc_files=$(( num_doc_files + 1 )) for format in "$@"; do generate::fromgmi_add_docs "$src" "$format" done @@ -137,16 +147,14 @@ generate::fromgmi () { done done - if [[ "$USE_GIT" == yes ]]; then - if [[ -z "$GIT_COMMIT_MESSAGE" ]]; then - GIT_COMMIT_MESSAGE='Publishing new version' - fi - git::commit gemtext "$GIT_COMMIT_MESSAGE" - git::commit meta "$GIT_COMMIT_MESSAGE" + if [[ -z "$GIT_COMMIT_MESSAGE" ]]; then + GIT_COMMIT_MESSAGE='Publishing new version' fi + git::commit gemtext "$GIT_COMMIT_MESSAGE" + git::commit meta "$GIT_COMMIT_MESSAGE" for format in "$@"; do - test "$USE_GIT" == yes && git::commit "$format" "$GIT_COMMIT_MESSAGE" + git::commit "$format" "$GIT_COMMIT_MESSAGE" log INFO "$format can be found in $CONTENT_BASE_DIR/$format now" done } diff --git a/packages/git.source.sh b/packages/git.source.sh index ca1f4750..c502b008 100644 --- a/packages/git.source.sh +++ b/packages/git.source.sh @@ -1,5 +1,9 @@ # Add a static content file to git git::add () { + if [[ "$USE_GIT" != yes ]]; then + return + fi + local -r content_dir="$CONTENT_BASE_DIR/$1"; shift local file="$1"; shift file=${file/$content_dir/.\/} @@ -11,6 +15,10 @@ git::add () { # Remove a static content file from git git::rm () { + if [[ "$USE_GIT" != yes ]]; then + return + fi + local -r content_dir="$CONTENT_BASE_DIR/$1"; shift local file="$1"; shift file=${file/$content_dir/.\/} @@ -22,6 +30,10 @@ git::rm () { # Commit all changes git::commit () { + if [[ "$USE_GIT" != yes ]]; then + return + fi + local -r content_dir="$CONTENT_BASE_DIR/$1"; shift local -r message="$1"; shift diff --git a/packages/html.source.sh b/packages/html.source.sh index 5a292f1c..a258781b 100644 --- a/packages/html.source.sh +++ b/packages/html.source.sh @@ -10,7 +10,10 @@ html::encode () { # Make a HTML paragraph. html::make_paragraph () { local -r text="$1"; shift - test -n "$text" && echo "<p>$(html::encode "$text")</p>" + + if [[ -n "$text" ]]; then + echo "<p>$(html::encode "$text")</p>" + fi } # Make a HTML header. @@ -46,8 +49,13 @@ html::make_link () { local link="$1"; shift local descr="$1"; shift - $GREP -F -q '://' <<< "$link" || link=${link/.gmi/.html} - test -z "$descr" && descr="$link" + if $GREP -F -q '://' <<< "$link"; then + link=${link/.gmi/.html} + fi + if [[ -z "$descr" ]]; then + descr="$link" + fi + echo "<a class=\"textlink\" href=\"$link\">$descr</a><br />" } diff --git a/packages/md.source.sh b/packages/md.source.sh index 957b9cf3..ce190ddb 100644 --- a/packages/md.source.sh +++ b/packages/md.source.sh @@ -15,8 +15,12 @@ md::make_link () { local link="$1"; shift local descr="$1"; shift - $GREP -F -q '://' <<< "$link" || link=${link/.gmi/.md} - test -z "$descr" && descr="$link" + if $GREP -F -q '://' <<< "$link"; then + link=${link/.gmi/.md} + fi + if [[ -z "$descr" ]]; then + descr="$link" + fi echo "[$descr]($link) " } |
