mirror of
https://git.ludikovsky.name/git/fugitive.git
synced 2024-10-05 15:35:29 +02:00
grep and sed bugfix
This commit is contained in:
parent
eaee2b145e
commit
8d2378fe2b
48
html-gen.sh
48
html-gen.sh
|
@ -54,25 +54,25 @@ get_article_info() {
|
||||||
git log --format="$1" -- "$articles_dir/$2"
|
git log --format="$1" -- "$articles_dir/$2"
|
||||||
}
|
}
|
||||||
get_article_next_file() {
|
get_article_next_file() {
|
||||||
next=`grep -B1 "$1" "$articles_sorted" | head -1`
|
next=`grep -B1 "^$1$" "$articles_sorted" | head -1`
|
||||||
if [ "$next" != "$1" ]; then
|
if [ "$next" != "$1" ]; then
|
||||||
echo "$next"
|
echo "$next"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
get_article_previous_file() {
|
get_article_previous_file() {
|
||||||
previous=`grep -A1 "$1" "$articles_sorted" | tail -1`
|
previous=`grep -A1 "^$1$" "$articles_sorted" | tail -1`
|
||||||
if [ "$previous" != "$1" ]; then
|
if [ "$previous" != "$1" ]; then
|
||||||
echo "$previous"
|
echo "$previous"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
get_deleted_next_file() {
|
get_deleted_next_file() {
|
||||||
next=`grep -B1 "$1" "$articles_sorted_with_delete" | head -1`
|
next=`grep -B1 "^$1$" "$articles_sorted_with_delete" | head -1`
|
||||||
if [ "`echo $deleted_files | grep -c \"$next\"`" = "0" ]; then
|
if [ "`echo $deleted_files | grep -c \"$next\"`" = "0" ]; then
|
||||||
echo "$next"
|
echo "$next"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
get_deleted_previous_file() {
|
get_deleted_previous_file() {
|
||||||
previous=`grep -A1 "$1" "$articles_sorted_with_delete" | tail -1`
|
previous=`grep -A1 "^$1$" "$articles_sorted_with_delete" | tail -1`
|
||||||
if [ "`echo $deleted_files | grep -c \"$previous\"`" = "0" ]; then
|
if [ "`echo $deleted_files | grep -c \"$previous\"`" = "0" ]; then
|
||||||
echo "$previous"
|
echo "$previous"
|
||||||
fi
|
fi
|
||||||
|
@ -105,29 +105,29 @@ sanit_mail() {
|
||||||
|
|
||||||
replace_condition() {
|
replace_condition() {
|
||||||
if [ "$2" = "" ]; then
|
if [ "$2" = "" ]; then
|
||||||
sed "s/<?fugitive\s\+\(end\)\?ifset:$1\s*?>/\n\0\n/g" | \
|
sed "s/<?fugitive[[:space:]]\+\(end\)\?ifset:$1[[:space:]]*?>/\n\0\n/g" | \
|
||||||
sed "/<?fugitive\s\+ifset:$1\s*?>/,/<?fugitive\s\+endifset:$1\s*?>/bdel
|
sed "/<?fugitive[[:space:]]\+ifset:$1[[:space:]]*?>/,/<?fugitive[[:space:]]\+endifset:$1[[:space:]]*?>/bdel
|
||||||
b
|
b
|
||||||
:del
|
:del
|
||||||
s/<?fugitive\s\+endifset:$1\s*?>.*//
|
s/<?fugitive[[:space:]]\+endifset:$1[[:space:]]*?>.*//
|
||||||
/<?fugitive\s\+endifset:$1\s*?>/b
|
/<?fugitive[[:space:]]\+endifset:$1[[:space:]]*?>/b
|
||||||
d"
|
d"
|
||||||
else
|
else
|
||||||
sed "s/<?fugitive\s\+\(end\)\?ifset:$1\s*?>//"
|
sed "s/<?fugitive[[:space:]]\+\(end\)\?ifset:$1[[:space:]]*?>//"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
replace_str() {
|
replace_str() {
|
||||||
esc=`echo $2 | sed 's/\//\\\\\//g'`
|
esc=`echo $2 | sed 's/\//\\\\\//g'`
|
||||||
replace_condition "$1" "$2" | \
|
replace_condition "$1" "$2" | \
|
||||||
sed "s/<?fugitive\s\+$1\s*?>/$esc/g"
|
sed "s/<?fugitive[[:space:]]\+$1[[:space:]]*?>/$esc/g"
|
||||||
}
|
}
|
||||||
|
|
||||||
# REMEMBER: 2nd arg should be a tempfile!
|
# REMEMBER: 2nd arg should be a tempfile!
|
||||||
replace_file() {
|
replace_file() {
|
||||||
if [ -f "$2" ]; then
|
if [ -f "$2" ]; then
|
||||||
sed "s/<?fugitive\s\+$1\s*?>/\n\0\n/g" | \
|
sed "s/<?fugitive[[:space:]]\+$1[[:space:]]*?>/\n\0\n/g" | \
|
||||||
sed "/<?fugitive\s\+$1\s*?>/ {
|
sed "/<?fugitive[[:space:]]\+$1[[:space:]]*?>/ {
|
||||||
r $2
|
r $2
|
||||||
d }"
|
d }"
|
||||||
rm "$2"
|
rm "$2"
|
||||||
|
@ -141,14 +141,14 @@ replace_includes() {
|
||||||
buf2=`mktemp`
|
buf2=`mktemp`
|
||||||
cat > "$buf"
|
cat > "$buf"
|
||||||
includes=`cat "$buf" | \
|
includes=`cat "$buf" | \
|
||||||
sed "s/<?fugitive\s\+include:.\+\s*?>/\n\0\n/g" | \
|
sed "s/<?fugitive[[:space:]]\+include:.\+[[:space:]]*?>/\n\0\n/g" | \
|
||||||
grep -E "<\?fugitive\s+include:.+\s*\?>" | \
|
grep -E "<\?fugitive[[:space:]]+include:.+[[:space:]]*\?>" | \
|
||||||
sed "s/^<?fugitive\s\+include://;s/\s*?>$//"`
|
sed "s/^<?fugitive[[:space:]]\+include://;s/[[:space:]]*?>$//"`
|
||||||
for i in $includes; do
|
for i in $includes; do
|
||||||
esc=`echo -n $i | sed 's/\//\\\\\//g'`
|
esc=`echo -n $i | sed 's/\//\\\\\//g'`
|
||||||
inc="$templates_dir/$i"
|
inc="$templates_dir/$i"
|
||||||
cat "$buf" | \
|
cat "$buf" | \
|
||||||
sed "/<?fugitive\s\+include:$esc\s*?>/ {
|
sed "/<?fugitive[[:space:]]\+include:$esc[[:space:]]*?>/ {
|
||||||
r $inc
|
r $inc
|
||||||
d }" > "$buf2"
|
d }" > "$buf2"
|
||||||
tmpbuf="$buf"
|
tmpbuf="$buf"
|
||||||
|
@ -256,7 +256,7 @@ replace_foreach () {
|
||||||
fe="foreach:$1"
|
fe="foreach:$1"
|
||||||
cat > "$temp"
|
cat > "$temp"
|
||||||
cat "$temp" | \
|
cat "$temp" | \
|
||||||
sed -n "/<?fugitive\s\+$fe\s*?>/,/<?fugitive\s\+end$fe\s*?>/p" | \
|
sed -n "/<?fugitive[[:space:]]\+$fe[[:space:]]*?>/,/<?fugitive[[:space:]]\+end$fe[[:space:]]*?>/p" | \
|
||||||
tail -n +2 | head -n -1 > "$foreach_body"
|
tail -n +2 | head -n -1 > "$foreach_body"
|
||||||
if [ ! -s "$foreach_body" ]; then
|
if [ ! -s "$foreach_body" ]; then
|
||||||
cat "$temp"
|
cat "$temp"
|
||||||
|
@ -264,8 +264,8 @@ replace_foreach () {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
cat "$temp" | \
|
cat "$temp" | \
|
||||||
sed "s/<?fugitive\s\+$fe\s*?>/<?fugitive foreach_body ?>\n\0/" | \
|
sed "s/<?fugitive[[:space:]]\+$fe[[:space:]]*?>/<?fugitive foreach_body ?>\n\0/" | \
|
||||||
sed "/<?fugitive\s\+$fe\s*?>/,/<?fugitive\s\+end$fe\s*?>/d" | \
|
sed "/<?fugitive[[:space:]]\+$fe[[:space:]]*?>/,/<?fugitive[[:space:]]\+end$fe[[:space:]]*?>/d" | \
|
||||||
cat > "$tmpfile"
|
cat > "$tmpfile"
|
||||||
for i in `cat "$2"`; do
|
for i in `cat "$2"`; do
|
||||||
cat "$foreach_body" | replace_$1_info "$i"
|
cat "$foreach_body" | replace_$1_info "$i"
|
||||||
|
@ -287,13 +287,13 @@ generate_article() {
|
||||||
replace_str "blog_url" "$blog_url" | \
|
replace_str "blog_url" "$blog_url" | \
|
||||||
replace_commit_info "-1" | \
|
replace_commit_info "-1" | \
|
||||||
replace_article_info "$art" | \
|
replace_article_info "$art" | \
|
||||||
sed "/^\s*$/d" > "$public_dir/$art.html"
|
sed "/^[[:space:]]*$/d" > "$public_dir/$art.html"
|
||||||
if [ "$preproc" != "" ]; then mv "$preproc_bak" "$1"; fi
|
if [ "$preproc" != "" ]; then mv "$preproc_bak" "$1"; fi
|
||||||
}
|
}
|
||||||
|
|
||||||
regenerate_previous_and_next_article_maybe() {
|
regenerate_previous_and_next_article_maybe() {
|
||||||
if [ "$1" != "" -a \
|
if [ "$1" != "" -a \
|
||||||
"`grep -c \"$1\" \"$generated_files\"`" = "0" ]; then
|
"`grep -c \"^$1$\" \"$generated_files\"`" = "0" ]; then
|
||||||
echo -n "[fugitive] Regenerating $public_dir/$1.html"
|
echo -n "[fugitive] Regenerating $public_dir/$1.html"
|
||||||
echo -n " (as previous article) from $articles_dir/$1... "
|
echo -n " (as previous article) from $articles_dir/$1... "
|
||||||
generate_article "$articles_dir/$1"
|
generate_article "$articles_dir/$1"
|
||||||
|
@ -301,7 +301,7 @@ regenerate_previous_and_next_article_maybe() {
|
||||||
echo "$1" >> "$generated_files"
|
echo "$1" >> "$generated_files"
|
||||||
fi
|
fi
|
||||||
if [ "$2" != "" -a \
|
if [ "$2" != "" -a \
|
||||||
"`grep -c \"$2\" \"$generated_files\"`" = "0" ]; then
|
"`grep -c \"^$2$\" \"$generated_files\"`" = "0" ]; then
|
||||||
echo -n "[fugitive] Regenerating $public_dir/$2.html"
|
echo -n "[fugitive] Regenerating $public_dir/$2.html"
|
||||||
echo -n " (as next article) from $articles_dir/$2... "
|
echo -n " (as next article) from $articles_dir/$2... "
|
||||||
generate_article "$articles_dir/$2"
|
generate_article "$articles_dir/$2"
|
||||||
|
@ -361,7 +361,7 @@ if [ $modification -gt 0 ]; then
|
||||||
replace_str "page_title" "archives" | \
|
replace_str "page_title" "archives" | \
|
||||||
replace_str "blog_url" "$blog_url" | \
|
replace_str "blog_url" "$blog_url" | \
|
||||||
replace_commit_info "-1" | \
|
replace_commit_info "-1" | \
|
||||||
sed "/^\s*$/d" > "$public_dir/archives.html"
|
sed "/^[[:space:]]*$/d" > "$public_dir/archives.html"
|
||||||
echo "done."
|
echo "done."
|
||||||
echo -n "[fugitive] Generating $public_dir/feed.xml... "
|
echo -n "[fugitive] Generating $public_dir/feed.xml... "
|
||||||
last_5_articles=`mktemp`
|
last_5_articles=`mktemp`
|
||||||
|
@ -375,7 +375,7 @@ if [ $modification -gt 0 ]; then
|
||||||
replace_str "page_title" "feed" | \
|
replace_str "page_title" "feed" | \
|
||||||
replace_str "blog_url" "$blog_url" | \
|
replace_str "blog_url" "$blog_url" | \
|
||||||
replace_commit_info "-1" | \
|
replace_commit_info "-1" | \
|
||||||
sed "/^\s*$/d" > "$public_dir/feed.xml"
|
sed "/^[[:space:]]*$/d" > "$public_dir/feed.xml"
|
||||||
echo "done."
|
echo "done."
|
||||||
rm "$last_5_articles" "$last_5_commits"
|
rm "$last_5_articles" "$last_5_commits"
|
||||||
echo -n "[fugitive] Using last published article as index page... "
|
echo -n "[fugitive] Using last published article as index page... "
|
||||||
|
|
Loading…
Reference in a new issue