diff options
author | Alexey Shpakovsky <alexey@shpakovsky.ru> | 2014-06-24 06:51:27 +0200 |
---|---|---|
committer | Alexey Shpakovsky <alexey@shpakovsky.ru> | 2014-06-24 06:51:27 +0200 |
commit | a52f2e6758ce35ec1a0be5107ccf89d7897acd9c (patch) | |
tree | cc31ce1e58de4356153a187ccae3759e136c34e3 /bb.sh | |
parent | b34c7fbd0fa703feb7b5689795664e944dceb0a3 (diff) |
tags_in_post() to list all tags referenced in one post file
Diffstat (limited to 'bb.sh')
-rwxr-xr-x | bb.sh | 24 |
1 files changed, 11 insertions, 13 deletions
@@ -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 |