From 15f2bf661c85cb07f3bb595f64815d7767f962db Mon Sep 17 00:00:00 2001 From: p4bl0 Date: Thu, 22 Jul 2010 19:14:50 +0200 Subject: no need for dirs in src --- src/hooks/post-commit.sh | 82 ------------------------------------------------ src/post-commit.sh | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 82 deletions(-) delete mode 100644 src/hooks/post-commit.sh create mode 100644 src/post-commit.sh diff --git a/src/hooks/post-commit.sh b/src/hooks/post-commit.sh deleted file mode 100644 index 55c1ef5..0000000 --- a/src/hooks/post-commit.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/sh - -public_dir=`git config --get fugitive.public-dir` -if [ ! -d "$public_dir" ]; then mkdir -p "$public_dir"; fi -templates_dir=`git config --get fugitive.templates-dir` -articles_dir=`git config --get fugitive.articles-dir` - -added_files=`git log -1 --name-status --pretty="format:" | grep -E '^A' | \ - cut -f2` -modified_files=`git log -1 --name-status --pretty="format:" | grep -E '^M' | \ - cut -f2` -deleted_files=`git log -1 --name-status --pretty="format:" | grep -E '^D' | \ - cut -f2` - -last_published_article=`git log --name-status --pretty="format:" | \ - grep -E '^A' | cut -f2 | grep -E '^$articles_dir' | head -1` - -commit_Hash=`git log -1 --format="%H"` -commit_hash=`git log -1 --format="%h"` -commit_author=`git log -1 --format="%an"` -commit_author_email=`git log -1 --format="%ae" | sed "s/@/[at]/;s/\./(dot)/"` -commit_datetime=`git log -1 --format="%ai" | cut -d' ' -f1,2` -commit_date=`git log -1 --format="%ad" --date="short"` -commit_time=`git log -1 --format="%ai" | cut -d' ' -f2` -commit_timestamp=`git log -1 --format="%at"` -commit_subject=`git log -1 --format="%s"` -commit_slug=`git log -1 --format="%f"` -commit_body() { - tmp=`tempfile -p "fugitive"` - git log -1 --format="%b" > "$tmp" - (sleep 5 && rm -f "$tmp") & # this message will self-destruct in 5s - echo "$tmp" -} - -article_get_title() { - head -1 "$1" -} -article_get_content() { - tmp=`tempfile -p "fugitive"` - tail -n+2 "$1" > "$tmp" - (sleep 5 && rm -f "$tmp") & # this message will self-destruct in 5s - echo "$tmp" -} - -replace_var_by_string() { - sed "s/<\!--$1-->/$2/" -} -replace_var_by_file() { - sed "/<\!--$1-->/ { - r $2 - d }" -} -replace_commit_info() { - replace_var_by_string "commit_Hash" "$commit_Hash" | \ - replace_var_by_string "commit_hash" "$commit_hash" | \ - replace_var_by_string "commit_author" "$commit_author" | \ - replace_var_by_string "commit_author_email" "$commit_author_email" | \ - replace_var_by_string "commit_date" "$commit_date" | \ - replace_var_by_string "commit_subject" "$commit_subject" | \ - replace_var_by_string "commit_slug" "$commit_slug" | \ - replace_var_by_file "commit_body" "`commit_body`" -} - -for f in $deleted_files; do - if [ "$f" != "${f#$articles_dir}" ]; then - echo -n "Deleting $public_dir/${f#$articles_dir/}.html... " - rm $public_dir/${f#$articles_dir/}.html - echo "done." - fi -done - -for f in $added_files $modified_files; do - if [ "$f" != "${f#$articles_dir}" ]; then - echo -n "Generating $public_dir/${f#$articles_dir/}.html from $f... " - cat $templates_dir/article.html | \ - replace_commit_info | \ - replace_var_by_string "article_title" "`article_get_title \"$f\"`" | \ - replace_var_by_file "article_content" "`article_get_content \"$f\"`" | \ - cat > $public_dir/${f#$articles_dir/}.html - echo "done." - fi -done diff --git a/src/post-commit.sh b/src/post-commit.sh new file mode 100644 index 0000000..55c1ef5 --- /dev/null +++ b/src/post-commit.sh @@ -0,0 +1,82 @@ +#!/bin/sh + +public_dir=`git config --get fugitive.public-dir` +if [ ! -d "$public_dir" ]; then mkdir -p "$public_dir"; fi +templates_dir=`git config --get fugitive.templates-dir` +articles_dir=`git config --get fugitive.articles-dir` + +added_files=`git log -1 --name-status --pretty="format:" | grep -E '^A' | \ + cut -f2` +modified_files=`git log -1 --name-status --pretty="format:" | grep -E '^M' | \ + cut -f2` +deleted_files=`git log -1 --name-status --pretty="format:" | grep -E '^D' | \ + cut -f2` + +last_published_article=`git log --name-status --pretty="format:" | \ + grep -E '^A' | cut -f2 | grep -E '^$articles_dir' | head -1` + +commit_Hash=`git log -1 --format="%H"` +commit_hash=`git log -1 --format="%h"` +commit_author=`git log -1 --format="%an"` +commit_author_email=`git log -1 --format="%ae" | sed "s/@/[at]/;s/\./(dot)/"` +commit_datetime=`git log -1 --format="%ai" | cut -d' ' -f1,2` +commit_date=`git log -1 --format="%ad" --date="short"` +commit_time=`git log -1 --format="%ai" | cut -d' ' -f2` +commit_timestamp=`git log -1 --format="%at"` +commit_subject=`git log -1 --format="%s"` +commit_slug=`git log -1 --format="%f"` +commit_body() { + tmp=`tempfile -p "fugitive"` + git log -1 --format="%b" > "$tmp" + (sleep 5 && rm -f "$tmp") & # this message will self-destruct in 5s + echo "$tmp" +} + +article_get_title() { + head -1 "$1" +} +article_get_content() { + tmp=`tempfile -p "fugitive"` + tail -n+2 "$1" > "$tmp" + (sleep 5 && rm -f "$tmp") & # this message will self-destruct in 5s + echo "$tmp" +} + +replace_var_by_string() { + sed "s/<\!--$1-->/$2/" +} +replace_var_by_file() { + sed "/<\!--$1-->/ { + r $2 + d }" +} +replace_commit_info() { + replace_var_by_string "commit_Hash" "$commit_Hash" | \ + replace_var_by_string "commit_hash" "$commit_hash" | \ + replace_var_by_string "commit_author" "$commit_author" | \ + replace_var_by_string "commit_author_email" "$commit_author_email" | \ + replace_var_by_string "commit_date" "$commit_date" | \ + replace_var_by_string "commit_subject" "$commit_subject" | \ + replace_var_by_string "commit_slug" "$commit_slug" | \ + replace_var_by_file "commit_body" "`commit_body`" +} + +for f in $deleted_files; do + if [ "$f" != "${f#$articles_dir}" ]; then + echo -n "Deleting $public_dir/${f#$articles_dir/}.html... " + rm $public_dir/${f#$articles_dir/}.html + echo "done." + fi +done + +for f in $added_files $modified_files; do + if [ "$f" != "${f#$articles_dir}" ]; then + echo -n "Generating $public_dir/${f#$articles_dir/}.html from $f... " + cat $templates_dir/article.html | \ + replace_commit_info | \ + replace_var_by_string "article_title" "`article_get_title \"$f\"`" | \ + replace_var_by_file "article_content" "`article_get_content \"$f\"`" | \ + cat > $public_dir/${f#$articles_dir/}.html + echo "done." + fi +done -- cgit v1.2.3