aboutsummaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorJefferson Julio <[email protected]>2021-06-02 23:38:09 -0300
committerJefferson Julio <[email protected]>2021-06-02 23:38:09 -0300
commit7d773221e7711c4e534e89264c719b4cc5aabb1f (patch)
treebaf59501215d3ee874b865c70c9b9d1408545a16 /components
parent5caf63d3897f353717fd69be9174d028fd078b23 (diff)
downloadblog.sh-7d773221e7711c4e534e89264c719b4cc5aabb1f.tar.bz2
blog.sh-7d773221e7711c4e534e89264c719b4cc5aabb1f.zip
support for comments on pages
Diffstat (limited to 'components')
-rwxr-xr-xcomponents/comments.sh55
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)"