summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2022-07-02 19:33:11 +0300
committerPaul Buetow <paul@buetow.org>2022-07-02 19:33:11 +0300
commitb733f1860f00c61eb33ff33c4368201a4c8161d9 (patch)
treee8c35461bc445e4b57d9fa68566301f84c251a12
parent30f00fa694280a7eaa23c20affba22bd14b91739 (diff)
add new git options
-rw-r--r--IDEA.md4
-rw-r--r--README.md2
-rwxr-xr-xgemtexter17
-rw-r--r--lib/git.source.sh55
4 files changed, 68 insertions, 10 deletions
diff --git a/IDEA.md b/IDEA.md
index 7b4c590..ba70c6a 100644
--- a/IDEA.md
+++ b/IDEA.md
@@ -1,9 +1,5 @@
# IDEAs
-## Maybe don't store results in Git
-
-Just generate the output formats (such as html, md...) and use rsync to push the content to the server. No need to use Git here. Only keep the original .gmi files in git.
-
## Parallel job processing queue
Currently, in order to speed up, Gemtexter forks on certain functions and loops and joins (via `wait`) on the sub-processes. This however can be a problem once a user max process limit is reached.
diff --git a/README.md b/README.md
index 87c8baf..d0f73ac 100644
--- a/README.md
+++ b/README.md
@@ -77,7 +77,7 @@ You will find the `./extras/html/header.html.part` and `./extras/html/footer.htm
## Store all formats in Git
-I personally have for each directory in `../foo.zone-content/` a separate Git repository configured. So whenever something changes I commit and push the content to git.
+I personally have for each directory in `../foo.zone-content/` a separate Git repository configured. So whenever something changes I commit and push the content to git. Gemtexter automatically detects whether a content directory is in git or not (e.g. directories `../foo.zone-content/*/.git` exist). In this case you can use the `./gemtexter --git-add` command to add all files to git and `./gemtexter --git-sync` to sync all content files with the remote repository (which is a Git pull followed by a push). A `./gemtexter --git` will do both, adding and syncing. For a custom commit message can set the `GIT_COMMIT_MESSAGE` environment variable, e.g.: `GIT_COMMIT_MESSAGE='New blog post' ./gemtexter --git`.
## Publishing a blog post
diff --git a/gemtexter b/gemtexter
index 1bd5690..b3d4e46 100755
--- a/gemtexter
+++ b/gemtexter
@@ -29,11 +29,12 @@ fi
source ./lib/assert.source.sh
source ./lib/atomfeed.source.sh
source ./lib/gemfeed.source.sh
-source ./lib/notes.source.sh
source ./lib/generate.source.sh
+source ./lib/git.source.sh
source ./lib/html.source.sh
source ./lib/log.source.sh
source ./lib/md.source.sh
+source ./lib/notes.source.sh
help () {
cat <<HELPHERE
@@ -82,10 +83,6 @@ main () {
html::test
md::test
;;
- --develop)
- # Switch only used for development purposes
- generate::fromgmi html md
- ;;
--feed)
html::test
md::test
@@ -101,6 +98,16 @@ main () {
wait
generate::fromgmi html md
;;
+ --git)
+ git::add_all "$GIT_COMMIT_MESSAGE"
+ git::sync_all
+ ;;
+ --git-add)
+ git::add_all "$GIT_COMMIT_MESSAGE"
+ ;;
+ --git-sync)
+ git::sync_all
+ ;;
--version)
echo "This is gemtexter version $VERSION $VERSION_DESCR"
;;
diff --git a/lib/git.source.sh b/lib/git.source.sh
new file mode 100644
index 0000000..67dc93e
--- /dev/null
+++ b/lib/git.source.sh
@@ -0,0 +1,55 @@
+git::_content_dirs_in_git () {
+ find "$CONTENT_BASE_DIR" -maxdepth 1 -mindepth 1 -type d |
+ while read -r content_dir; do
+ if [ -d "$content_dir/.git" ]; then
+ echo "$content_dir"
+ fi
+ done
+}
+
+git::add_all () {
+ local message="$1"; shift
+ if [ -z "$message" ]; then
+ message='Update content'
+ fi
+
+ git::_content_dirs_in_git | while read -r content_dir; do
+ log INFO "Adding content from $content_dir to git"
+ git::_add_all "$message" "$content_dir" &
+ done
+ wait
+}
+
+git::_add_all () {
+ local -r message="$1"; shift
+ local -r content_dir="$1"; shift
+ cd "$content_dir"
+
+ find . -type f -not -path '*/\.git*' | while read -r file; do
+ git add "$file"
+ done
+
+ local -r format="$(basename "$content_dir")"
+ git commit -a -m "$message for $format"
+
+ cd -
+}
+
+git::sync_all () {
+ git::_content_dirs_in_git | while read -r content_dir; do
+ log INFO "Synchronizing content from $content_dir with remote git"
+ git::_sync_all "$content_dir"
+ done
+}
+
+git::_sync_all () {
+ local -r content_dir="$1"; shift
+ cd "$content_dir"
+
+ git pull
+ git push
+ git status
+
+ cd -
+}
+