главная|main page

состояние|status

блог|blog

файлы|files

программы|software

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Shpakovsky <alexey@shpakovsky.ru>2014-06-24 06:25:55 +0200
committerAlexey Shpakovsky <alexey@shpakovsky.ru>2014-06-24 06:25:55 +0200
commitb34c7fbd0fa703feb7b5689795664e944dceb0a3 (patch)
treec52f97dc5189ac9fb8f7e7fc95376ec266cf075f
parent97f413e66682cec9e2bfcd80d71c7894691c5a58 (diff)
make rebuild_tags() optionally accept 2 lists (of filenames and tags)
-rwxr-xr-xbb.sh33
1 files changed, 29 insertions, 4 deletions
diff --git a/bb.sh b/bb.sh
index 2317575..664add4 100755
--- a/bb.sh
+++ b/bb.sh
@@ -769,14 +769,37 @@ rebuild_index() {
chmod 644 "$index_file"
}
-# Rebuilds all tag_*.html files
+# Rebuilds tag_*.html files
+# if no arguments given, rebuilds all of them
+# if arguments given, they should have this format:
+# "FILE1 [FILE2 [...]]" "TAG1 [TAG2 [...]]"
+# where FILEn are files with posts which should be used for rebuilding tags,
+# and TAGn are names of tags which should be rebuilt.
+# example:
+# rebuild_tags "one_post.html another_atricle.html" "example-tag another-tag"
+# mind the tags!
rebuild_tags() {
+ if [ "$#" -lt 2 ]; then
+ # will process all files and tags
+ files="$(ls -t ./*.html)"
+ all_tags="yes"
+ else
+ # will process only given files and tags
+ files="$(ls -t $1)"
+ tags="$2"
+ fi
echo -n "Rebuilding tag pages "
n=0
- rm ./$prefix_tags*.html &> /dev/null
+ if [ $all_tags ]; then
+ rm ./$prefix_tags*.html &> /dev/null
+ else
+ for i in $tags; do
+ rm ./$prefix_tags$i.html &> /dev/null
+ done
+ fi
# First we will process all files and create temporal tag files
# with just the content of the posts
- for i in $(ls -t ./*.html); do
+ for i in $files; do
is_boilerplate_file "$i" && continue;
echo -n "."
tmpfile="$(mktemp tmp.XXX)"
@@ -792,7 +815,9 @@ rebuild_tags() {
for dirty_tag in "${tags[@]}"; do # extract html around it
tag="$(expr "$dirty_tag" : ".*>\(.*\)</a" | tr " " "_")"
# Add the content of this post to the tag file
- cat "$tmpfile" >> "$prefix_tags$tag".tmp.html
+ if [ "$all_tags" ] || [[ " $tags " == *" $tag "* ]]; then
+ cat "$tmpfile" >> "$prefix_tags$tag".tmp.html
+ fi
done
done
fi