make rebuild_tags() optionally accept 2 lists (of filenames and tags)
This commit is contained in:
parent
97f413e666
commit
b34c7fbd0f
29
bb.sh
29
bb.sh
|
@ -769,14 +769,37 @@ rebuild_index() {
|
||||||
chmod 644 "$index_file"
|
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() {
|
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 "
|
echo -n "Rebuilding tag pages "
|
||||||
n=0
|
n=0
|
||||||
|
if [ $all_tags ]; then
|
||||||
rm ./$prefix_tags*.html &> /dev/null
|
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
|
# First we will process all files and create temporal tag files
|
||||||
# with just the content of the posts
|
# with just the content of the posts
|
||||||
for i in $(ls -t ./*.html); do
|
for i in $files; do
|
||||||
is_boilerplate_file "$i" && continue;
|
is_boilerplate_file "$i" && continue;
|
||||||
echo -n "."
|
echo -n "."
|
||||||
tmpfile="$(mktemp tmp.XXX)"
|
tmpfile="$(mktemp tmp.XXX)"
|
||||||
|
@ -792,7 +815,9 @@ rebuild_tags() {
|
||||||
for dirty_tag in "${tags[@]}"; do # extract html around it
|
for dirty_tag in "${tags[@]}"; do # extract html around it
|
||||||
tag="$(expr "$dirty_tag" : ".*>\(.*\)</a" | tr " " "_")"
|
tag="$(expr "$dirty_tag" : ".*>\(.*\)</a" | tr " " "_")"
|
||||||
# Add the content of this post to the tag file
|
# Add the content of this post to the tag file
|
||||||
|
if [ "$all_tags" ] || [[ " $tags " == *" $tag "* ]]; then
|
||||||
cat "$tmpfile" >> "$prefix_tags$tag".tmp.html
|
cat "$tmpfile" >> "$prefix_tags$tag".tmp.html
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue
Block a user