diff options
Diffstat (limited to 'components')
-rwxr-xr-x | components/comments.sh | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/components/comments.sh b/components/comments.sh new file mode 100755 index 0000000..5e0caca --- /dev/null +++ b/components/comments.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +parse-all-posts () { + CONTENT="" + + if [ "$(ls "$COMMENTS_FOLDER" | wc -l)" = "0" ]; then + echo "" + return 1 + fi + + for post in "$COMMENTS_FOLDER/"*; do + POST_FILE="$post/post" + POST_ID="$(basename "$post")" + + # If is a private post, ignore + if [ -n "$(head -n 1 "$POST_FILE")" ]; then + continue + fi + + POST_NAME="$(sed -n '2p' "$POST_FILE")" + POST_EMAIL="$(sed -n '3p' "$POST_FILE")" + POST_MESSAGE="$(tail -n +5 "$POST_FILE")" + + IFS=';' read -ra POST_FILES <<< "$(sed -n "4p" "$POST_FILE")" + + CONTENT="$CONTENT$(cat <<POST +<article class="post" id="post-id-$POST_ID"> + <section class="post-metadata"> + <a class="post-id" href="$REQUEST_URI#post-id-$POST_ID"># $POST_ID</a> + <p class="post-name">$POST_NAME</p> + <a class="post-email" href="mailto:$POST_EMAIL">$POST_EMAIL</a> + </section> + <section class="post-message"> + <pre>$POST_MESSAGE</pre> + </section> + <section class="post-attachment"> + $( + for attach in "${POST_FILES[@]}"; do + FMIME=$(file --mime-type -b "$SCRIPT_DIR$attach") + if [ "${FMIME/\/*/}" = "image" ]; then + echo "<img src="$attach" alt="attachment" /><br/>" + fi + echo "<a href=\"$attach\">Download attachment</a>" + done + ) + </section> +</article> +POST +)" + done + + echo "$CONTENT" +} + +PARSED_COMMENTS="$(parse-all-posts)" |