From 7d773221e7711c4e534e89264c719b4cc5aabb1f Mon Sep 17 00:00:00 2001 From: Jefferson Julio Date: Wed, 2 Jun 2021 23:38:09 -0300 Subject: support for comments on pages --- components/comments.sh | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 components/comments.sh (limited to 'components/comments.sh') 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_MESSAGE
+
+
+ $( + for attach in "${POST_FILES[@]}"; do + FMIME=$(file --mime-type -b "$SCRIPT_DIR$attach") + if [ "${FMIME/\/*/}" = "image" ]; then + echo "attachment
" + fi + echo "Download attachment" + done + ) +
+ +POST +)" + done + + echo "$CONTENT" +} + +PARSED_COMMENTS="$(parse-all-posts)" -- cgit v1.2.3