diff options
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | buetow.org.conf | 2 | ||||
| -rwxr-xr-x | buetow.org.sh | 28 | ||||
| -rw-r--r-- | packages/atomfeed.source.sh | 6 | ||||
| -rw-r--r-- | packages/gemfeed.source.sh | 12 | ||||
| -rw-r--r-- | packages/generate.source.sh | 25 | ||||
| -rw-r--r-- | packages/git.source.sh | 31 |
8 files changed, 83 insertions, 28 deletions
@@ -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 @@ -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 <<END +The content base directory, does not exist. Run the following to create: + + mkdir -p $CONTENT_BASE_DIR/{meta,md,html} + git clone --branch content-gemtext https://github.com/snonux/buetow.org $CONTENT_BASE_DIR/gemtext + rm -Rf $CONTENT_BASE_DIR/gemtext/.git + +Once done, you are ready to edit the files in $CONTENT_BASE_DIR/gemtext. Every +time you want to generate other formats from Gemtext (e.g. HTML, Markdown), run +the $0 script again. + +Pro tip: You could make all the directories in $CONTENT_BASE_DIR separate git +repositories or branches. + +END + exit 1 + fi +} + main () { local -r arg="$1"; shift - case $ARG in + setup + + case $arg in --test) html::test md::test @@ -60,5 +84,5 @@ main () { return 0 } -main $ARG +main "$ARG" exit $? diff --git a/packages/atomfeed.source.sh b/packages/atomfeed.source.sh index f17b00fb..4bfc60c5 100644 --- a/packages/atomfeed.source.sh +++ b/packages/atomfeed.source.sh @@ -29,7 +29,7 @@ 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_file" + test $is_draft == no && git::add meta "$meta_file" return fi @@ -54,7 +54,7 @@ atomfeed::content () { # Generate an atom.xml feed file. atomfeed::generate () { - local -r gemfeed_dir="$CONTENT_DIR/gemtext/gemfeed" + local -r gemfeed_dir="$CONTENT_BASE_DIR/gemtext/gemfeed" local -r atom_file="$gemfeed_dir/atom.xml" local -r now=$($DATE --iso-8601=seconds) log INFO "Generating Atom feed to $atom_file" @@ -114,7 +114,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 "$ADD_GIT" == yes && git add "$atom_file" + test "$USE_GIT" == yes && 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 33ea0c8d..bc91eaff 100644 --- a/packages/gemfeed.source.sh +++ b/packages/gemfeed.source.sh @@ -1,6 +1,6 @@ # Filter out blog posts from other files in the gemfeed dir. gemfeed::get_posts () { - local -r gemfeed_dir="$CONTENT_DIR/gemtext/gemfeed" + local -r gemfeed_dir="$CONTENT_BASE_DIR/gemtext/gemfeed" local -r gmi_pattern='^[0-9]{4}-[0-9]{2}-[0-9]{2}-.*\.gmi$' local -r draft_pattern='\.draft\.gmi$' @@ -12,8 +12,8 @@ gemfeed::get_posts () { # Add the links from gemfeed/index.gmi to the main index site. gemfeed::updatemainindex () { - local -r index_gmi="$CONTENT_DIR/gemtext/index.gmi" - local -r gemfeed_dir="$CONTENT_DIR/gemtext/gemfeed" + local -r index_gmi="$CONTENT_BASE_DIR/gemtext/index.gmi" + local -r gemfeed_dir="$CONTENT_BASE_DIR/gemtext/gemfeed" log VERBOSE "Updating $index_gmi with posts from $gemfeed_dir" @@ -23,12 +23,12 @@ gemfeed::updatemainindex () { $SED -n '/^=> / { 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 > "$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 - +} |
