fixed post trimming
This commit is contained in:
parent
6df84bdb12
commit
324a04ca92
34
shi2.sh
34
shi2.sh
|
@ -57,24 +57,35 @@ get_op_post_html() {
|
||||||
local post_id="$(get_post_data "$post_db_path" "post_id")"
|
local post_id="$(get_post_data "$post_db_path" "post_id")"
|
||||||
local trim="$2" # how many replies to get
|
local trim="$2" # how many replies to get
|
||||||
local post_replies="$(get_post_data "$post_db_path" "replies")"
|
local post_replies="$(get_post_data "$post_db_path" "replies")"
|
||||||
|
local reply_num="$(echo "$post_replies" | wc -l)" # number of replies to the post
|
||||||
|
|
||||||
# id of the most recent reply to be included on the board page
|
|
||||||
local reply_lim="$(echo "$post_replies" | sed -n "$trim"p | tail -c 1)"
|
|
||||||
|
|
||||||
echo "REPLIES $post_replies" >> "$log_file"
|
|
||||||
cat "$post_html_path" \
|
cat "$post_html_path" \
|
||||||
| sed -e ':a' -e 'N' -e '$!ba' \
|
| sed -e ':a' -e 'N' -e '$!ba' \
|
||||||
-e "s/.*\(<!--BEGIN OP POST $post_id-->.*<!--END OP POST $post_id-->\).*/\1/g" \
|
-e "s/.*\(<!--BEGIN OP POST $post_id-->.*<!--END OP POST $post_id-->\).*/\1/g" \
|
||||||
> "$temp_file"
|
> "$temp_file"
|
||||||
|
|
||||||
|
if [ $reply_num -gt $trim ]
|
||||||
|
then
|
||||||
|
# id of the most recent reply to be included on the board page
|
||||||
|
local reply_lim="$(cat "$post_html_path" \
|
||||||
|
| grep -E "<!--END REPLY [0-9]+-->" \
|
||||||
|
| head -n "$(( trim + 1 ))" \
|
||||||
|
| tail -n1 | grep -Eo '[0-9]+')"
|
||||||
|
|
||||||
|
|
||||||
sed -i -e ':a' -e 'N' -e '$!ba' \
|
sed -i -e ':a' -e 'N' -e '$!ba' \
|
||||||
-e "s/<!--BEGIN REPLY $(( post_id - trim ))-->.*<!--END OP POST $post_id-->//g" \
|
-e "s/<!--BEGIN REPLY $reply_lim-->.*<!--END OP POST $post_id-->//g" \
|
||||||
"$temp_file"
|
"$temp_file"
|
||||||
|
|
||||||
cat "$temp_file"
|
cat "$temp_file"
|
||||||
|
|
||||||
# printf "<!--END REPLIES %s-->\n</div>\n</div>\n<!--END OP POST %s-->" \
|
printf "<!--END REPLIES %s-->\n</div>\n</div>\n<!--END OP POST %s-->" \
|
||||||
# "$post_id" "$post_id"
|
"$post_id" "$post_id"
|
||||||
|
else
|
||||||
|
cat "$temp_file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
rm "$temp_file"
|
rm "$temp_file"
|
||||||
}
|
}
|
||||||
|
@ -198,9 +209,20 @@ insert_post() {
|
||||||
# In the future, we will want to display replies in reverse chronological order
|
# In the future, we will want to display replies in reverse chronological order
|
||||||
parent="$(get_post_data "$post_db_path" "parent")"
|
parent="$(get_post_data "$post_db_path" "parent")"
|
||||||
replace="<!--BEGIN REPLY $post_id-->.*<!--END REPLY $post_id-->\n"
|
replace="<!--BEGIN REPLY $post_id-->.*<!--END REPLY $post_id-->\n"
|
||||||
|
# find existing reply end tags in the parent post html
|
||||||
|
insert_at="$(cat "$target_html" | grep -E "<!--END REPLY [0-9]+-->")"
|
||||||
|
echo "inserting at $insert_at" >> "$log_file"
|
||||||
|
if [ -n "$insert_at" ] # if reply end tags are found
|
||||||
|
then
|
||||||
|
# set `insert_at` to the end tag of the lowermost reply
|
||||||
|
insert_at="$(echo "$insert_at" | tail -n1)"
|
||||||
|
else
|
||||||
|
# else set `insert_at` to beginning of replies
|
||||||
insert_at="<!--BEGIN REPLIES $parent-->"
|
insert_at="<!--BEGIN REPLIES $parent-->"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
echo "inserting at $insert_at" >> "$log_file"
|
||||||
|
|
||||||
# remove any existing instances of the post in the html
|
# remove any existing instances of the post in the html
|
||||||
sed -i \
|
sed -i \
|
||||||
|
|
Loading…
Reference in New Issue