From afd9fdf7ca0800c457959b540c4378d20f802dc0 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 19 May 2021 19:46:20 +0100 Subject: add git package --- Makefile | 6 ++---- README.md | 1 - buetow.org.conf | 2 +- buetow.org.sh | 28 ++++++++++++++++++++++++++-- packages/atomfeed.source.sh | 6 +++--- packages/gemfeed.source.sh | 12 ++++++------ packages/generate.source.sh | 25 ++++++++++++++----------- packages/git.source.sh | 31 +++++++++++++++++++++++++++++++ 8 files changed, 83 insertions(+), 28 deletions(-) create mode 100644 packages/git.source.sh diff --git a/Makefile b/Makefile index 07ce729c..681a9c96 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,7 @@ generate: git submodule update bash ./buetow.org.sh --generate publish: - ADD_GIT=yes ./buetow.org.sh --generate - cp ./content/md/index.md index.md - git add index.md + USE_GIT=yes ./buetow.org.sh --generate git commit -a git push test: shellcheck @@ -16,5 +14,5 @@ shellcheck: --norc \ --external-sources \ --check-sourced \ - --exclude=SC2155,SC2010,SC2154,SC1090 \ + --exclude=SC2155,SC2010,SC2154,SC1090,SC2012 \ buetow.org.sh diff --git a/README.md b/README.md index c7fd7468..4d7261ae 100644 --- a/README.md +++ b/README.md @@ -25,5 +25,4 @@ These are things I want to do with this project in near future: * Speed it up a bit: Make it so, that only changed .gmi files (or changed HTML templates) result into re-generating other formats. * Write a blog post about buetow.org.sh script -* Fix the submodules. e.g. make sure that public submodules are checked out by default only (e.g. https://) and document a way to add your own submodules for RW access. * Custom alt.buetow.org domain for GitHub page. diff --git a/buetow.org.conf b/buetow.org.conf index 3d6a73d7..c0aac6f3 100644 --- a/buetow.org.conf +++ b/buetow.org.conf @@ -1,7 +1,7 @@ declare -xr DOMAIN=buetow.org declare -xr SUBTITLE='Having fun with computers!' -declare -xr CONTENT_DIR=./content declare -xr AUTHOR='Paul Buetow' declare -xr EMAIL='comments@mx.buetow.org' declare -xr IMAGE_PATTERN='\.(jpg|png|gif)$' declare -xr ATOM_MAX_ENTRIES=42 +declare -xr CONTENT_BASE_DIR=../buetow.org-content diff --git a/buetow.org.sh b/buetow.org.sh index 57535b99..7f63c9d8 100755 --- a/buetow.org.sh +++ b/buetow.org.sh @@ -16,6 +16,7 @@ readonly GREP source buetow.org.conf source ./packages/assert.source.sh +source ./packages/git.source.sh source ./packages/atomfeed.source.sh source ./packages/gemfeed.source.sh source ./packages/generate.source.sh @@ -33,10 +34,33 @@ $0's possible arguments: HELPHERE } +setup () { + if [ ! -d "$CONTENT_BASE_DIR" ]; then + cat < / { s| ./| ./gemfeed/|; p; }' "$gemfeed_dir/index.gmi" >> "$index_gmi.tmp" mv "$index_gmi.tmp" "$index_gmi" - test "$ADD_GIT" == yes && git add "$index_gmi" + test "$USE_GIT" == yes && git::add gemtext "$index_gmi" } # Generate a index.gmi in the ./gemfeed subdir. gemfeed::generate () { - local -r gemfeed_dir="$CONTENT_DIR/gemtext/gemfeed" + local -r gemfeed_dir="$CONTENT_BASE_DIR/gemtext/gemfeed" log INFO "Generating Gemfeed index for $gemfeed_dir" cat < "$gemfeed_dir/index.gmi.tmp" @@ -48,7 +48,7 @@ GEMFEED done mv "$gemfeed_dir/index.gmi.tmp" "$gemfeed_dir/index.gmi" - test "$ADD_GIT" == yes && git add "$gemfeed_dir/index.gmi" + test "$USE_GIT" == yes && git::add gemtext "$gemfeed_dir/index.gmi" gemfeed::updatemainindex } diff --git a/packages/generate.source.sh b/packages/generate.source.sh index 83bf69ee..25c292f4 100644 --- a/packages/generate.source.sh +++ b/packages/generate.source.sh @@ -40,7 +40,7 @@ generate::fromgmi_add_docs () { test ! -d "$dest_dir" && mkdir -p "$dest_dir" cp "$src" "$dest" - test "$ADD_GIT" == yes && git add "$dest" + test "$USE_GIT" == yes && git::add "$format" "$dest" } # Remove docs from output format which aren't present in Gemtext anymore. @@ -50,7 +50,7 @@ generate::fromgmi_cleanup_docs () { local dest=${src/.$format/.gmi} dest=${dest/$format/gemtext} - test ! -f "$dest" && test "$ADD_GIT" == yes && git rm "$src" + test ! -f "$dest" && test "$USE_GIT" == yes && git::rm "$format" "$src" } # Convert the Gemtext Atom feed to a HTML Atom feed. @@ -61,10 +61,10 @@ generate::convert_gmi_atom_to_html_atom () { log INFO 'Converting Gemtext Atom feed to HTML Atom feed' $SED 's|.gmi|.html|g; s|gemini://|https://|g' \ - < $CONTENT_DIR/gemtext/gemfeed/atom.xml \ - > $CONTENT_DIR/html/gemfeed/atom.xml + < $CONTENT_BASE_DIR/gemtext/gemfeed/atom.xml \ + > $CONTENT_BASE_DIR/html/gemfeed/atom.xml - test "$ADD_GIT" == yes && git add "$CONTENT_DIR/html/gemfeed/atom.xml" + test "$USE_GIT" == yes && git::add "$format" "$CONTENT_BASE_DIR/html/gemfeed/atom.xml" } # Internal helper function for generate::fromgmi @@ -88,7 +88,7 @@ generate::_fromgmi () { test -z "title" && title=$SUBTITLE $SED -i "s|%%TITLE%%|$title|g" "$dest.tmp" mv "$dest.tmp" "$dest" - test "$ADD_GIT" == yes && git add "$dest" + test "$USE_GIT" == yes && git::add "$format" "$dest" } # Generate a given output format from a Gemtext file. @@ -103,7 +103,7 @@ generate::fromgmi () { for format in "$@"; do generate::_fromgmi "$src" "$format" done - done < <(find "$CONTENT_DIR/gemtext" -type f -name \*.gmi) + done < <(find "$CONTENT_BASE_DIR/gemtext" -type f -name \*.gmi) log INFO "Converted $num_gmi_files Gemtext files" @@ -115,7 +115,7 @@ generate::fromgmi () { for format in "$@"; do generate::fromgmi_add_docs "$src" "$format" done - done < <(find "$CONTENT_DIR/gemtext" -type f | $GREP -E -v '(.gmi|atom.xml|.tmp)$') + done < <(find "$CONTENT_BASE_DIR/gemtext" -type f | $GREP -E -v '(\.git.*|\.gmi|atom.xml|\.tmp)$') log INFO "Added $num_doc_files other documents to each of $*" @@ -124,14 +124,17 @@ generate::fromgmi () { generate::convert_gmi_atom_to_html_atom "$format" done - # Remove obsolete files from ./html/ + # Remove obsolete files from ./html/. + # Note: The _config.yml is the config file for GitHub pages (md format). for format in "$@"; do - find "$CONTENT_DIR/$format" -type f | while read -r src; do + find "$CONTENT_BASE_DIR/$format" -type f | + $GREP -E -v '(\.git.*|_config.yml)$'| + while read -r src; do generate::fromgmi_cleanup_docs "$src" "$format" done done for format in "$@"; do - log INFO "$format can be found in $CONTENT_DIR/$format now" + 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 new file mode 100644 index 00000000..1484e93d --- /dev/null +++ b/packages/git.source.sh @@ -0,0 +1,31 @@ +# Add a static content file to git +git::add () { + local -r content_dir="$CONTENT_BASE_DIR/$1"; shift + local file="$1"; shift + file=${file/$content_dir/} + + cd $content_dir + echo git add $file + cd - +} + +# Remove a static content file from git +git::rm () { + local -r content_dir="$CONTENT_BASE_DIR/$1"; shift + local file="$1"; shift + file=${file/$content_dir/} + + cd $content_dir + echo git rm $file + cd - +} + +# Commit all changes +git::commit () { + local -r content_dir="$CONTENT_BASE_DIR/$1"; shift + local -r message="$1"; shift + + cd $content_dir + echo git commit -a -m "$message" + cd - +} -- cgit v1.2.3