главная|main page

состояние|status

блог|blog

файлы|files

программы|software

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Shpakovsky <alexey@shpakovsky.ru>2014-06-24 06:51:27 +0200
committerAlexey Shpakovsky <alexey@shpakovsky.ru>2014-06-24 06:51:27 +0200
commita52f2e6758ce35ec1a0be5107ccf89d7897acd9c (patch)
treecc31ce1e58de4356153a187ccae3759e136c34e3
parentb34c7fbd0fa703feb7b5689795664e944dceb0a3 (diff)
tags_in_post() to list all tags referenced in one post file
-rwxr-xr-xbb.sh24
1 files changed, 11 insertions, 13 deletions
diff --git a/bb.sh b/bb.sh
index 664add4..f6ccd83 100755
--- a/bb.sh
+++ b/bb.sh
@@ -769,6 +769,13 @@ rebuild_index() {
chmod 644 "$index_file"
}
+# Finds all tags referenced in one post.
+# Accepts either filename as first argument, or post content at stdin
+# Prints one line with space-separated tags to stdout
+tags_in_post() {
+ sed -n "/^<p>$template_tags_line_header/{s/^<p>$template_tags_line_header//;s/<[^>]*>//g;s/[ ,]\+/ /g;p}" $1
+}
+
# Rebuilds tag_*.html files
# if no arguments given, rebuilds all of them
# if arguments given, they should have this format:
@@ -808,20 +815,11 @@ rebuild_tags() {
else
get_html_file_content 'entry' 'entry' <$i >> "$tmpfile"
fi
- while IFS='' read line; do
- if [[ "$line" = "<p>$template_tags_line_header"* ]]; then
- # 'split' tags by commas
- echo "$line" | cut -c 10- | while IFS="," read -a tags; do
- 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
- if [ "$all_tags" ] || [[ " $tags " == *" $tag "* ]]; then
- cat "$tmpfile" >> "$prefix_tags$tag".tmp.html
- fi
- done
- done
+ for tag in $(tags_in_post $i); do
+ if [ "$all_tags" ] || [[ " $tags " == *" $tag "* ]]; then
+ cat "$tmpfile" >> "$prefix_tags$tag".tmp.html
fi
- done < "$i"
+ done
rm "$tmpfile"
done
# Now generate the tag files with headers, footers, etc