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 +++++++++++++++++++++++++++++++++++++++ config.sh | 15 ++++++++--- index.sh | 6 +++++ pages/article.sh | 46 ++++++++++++++++++++++++++++++++ pages/contato.sh | 28 +++++++++++++------- static/navigator.js | 8 ++++++ static/styles.css | 59 +++++++++++++++++++++++++++++++++++++++--- utils/handle-post-upload.sh | 16 +++++++++--- utils/parse-article-content.sh | 6 ----- 9 files changed, 212 insertions(+), 27 deletions(-) create mode 100755 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)" diff --git a/config.sh b/config.sh index ebc5027..b29dda0 100755 --- a/config.sh +++ b/config.sh @@ -1,22 +1,29 @@ #!/bin/bash +# Enable looping through folders and subfolders +shopt -s globstar + # All relatives paths must end with slash and must not be start by dot and/or slash # Examplo # VAR_PATH=dir/subdir/ # Folder where posts are stored, must be relative and suffed by a slash -ARTICLES_PATH=artigos/ +export ARTICLES_PATH=artigos/ # Supported article file extensions, must be separated by vertical bar # Exemple # ARTICLES_EXTS="txt|html|md" -ARTICLES_EXTS="txt|html|md" +export ARTICLES_EXTS="txt|html|md" # Pages, excluding the index "/"" -PAGES=( +export PAGES=( "/contato" ) -ALLOWED_POST_FOLDERS=( +export ALLOWED_POST_FOLDERS=( "/contato/comments" ) + +for article in "./$ARTICLES_PATH"**/*; do + ALLOWED_POST_FOLDERS+=("${article/./}/comments") +done diff --git a/index.sh b/index.sh index 4cac655..fae78f9 100755 --- a/index.sh +++ b/index.sh @@ -35,6 +35,12 @@ scape-regex () { sed 's/|/\\|/g' } +sanitize-html-entities () { + echo "$1" | + sed 's//\>/g' +} + html () { cat < diff --git a/pages/article.sh b/pages/article.sh index 3cb5ab7..b7270d8 100755 --- a/pages/article.sh +++ b/pages/article.sh @@ -2,6 +2,8 @@ source $SCRIPT_DIR/utils/parse-article.sh +COMMENTS_FOLDER="$SCRIPT_DIR/pages/$REQUEST_URI/comments" source $SCRIPT_DIR/components/comments.sh + if [ $? -gt 0 ]; then STATUS=404 cat < + +
+
+
+

Deixei o seu comentário sobre este artigo

+
+ + + + + +
+ + + +
+ + + + Campos marcados com asterisco (*) são obrigatórios +
+ +
+ + + + +
+ +
+ +
+
+

Discussão

+
+ + $( + if [ -n "$PARSED_COMMENTS" ]; then + echo "$PARSED_COMMENTS" + else + echo '

Sem mensagens para mostrar.

' + fi + ) +
ARTICLE diff --git a/pages/contato.sh b/pages/contato.sh index c63228f..e6bd752 100755 --- a/pages/contato.sh +++ b/pages/contato.sh @@ -1,14 +1,8 @@ #!/bin/bash -cat < - @media screen and (max-width: 600px) { - .contato-page { - text-align: center; - } - } - +COMMENTS_FOLDER="$SCRIPT_DIR/pages/contato/comments" source $SCRIPT_DIR/components/comments.sh +cat <

Formas de contato

@@ -35,7 +29,7 @@ cat <Ou...

- ...mande uma mensagem por aqui mesmo! Prencha o formulário abaixo que sua + ...mande uma mensagem por aqui mesmo! Preencha o formulário abaixo que sua mensagem será publicada. Ela por padrão será postada na área de mensagens abaixo, marque a opção "privado" se não quiser que ela seja visível publicamente, neste caso apenas a administração do site, eu, poderá ver. @@ -43,6 +37,7 @@ cat < + @@ -69,6 +64,21 @@ cat <

+ + +
+
+

Mensagens

+
+ + $( + if [ -n "$PARSED_COMMENTS" ]; then + echo "$PARSED_COMMENTS" + else + echo "

Sem mensagens para mostrar.

" + fi + ) +
PAGE # Celular e Whatsapp: +55 (81) 97326-9793
diff --git a/static/navigator.js b/static/navigator.js index 6d53ee5..b1e7368 100644 --- a/static/navigator.js +++ b/static/navigator.js @@ -4,6 +4,14 @@ let pageTransitionCleared = false; function bindAllRelativeAnchors() { document.querySelectorAll('a[href^="/"]:not([navigator-bind])').forEach((el) => { + const url = new URL(el.href); + + if (url.pathname == window.location.pathname) { + if (url.href.match(/#.+$/)) { + return + } + } + el.setAttribute('navigator-bind', 'true'); el.addEventListener('click', (e) => { e.preventDefault(); diff --git a/static/styles.css b/static/styles.css index 77e1caa..f8049bc 100644 --- a/static/styles.css +++ b/static/styles.css @@ -211,10 +211,10 @@ html::after { /* background-size: 100% 3px; */ background: repeating-linear-gradient( 0deg, - rgba(0, 0, 0, 0.3) 1px, - rgba(0, 0, 0, 0.0) 4px, + rgba(0, 0, 0, 0.2), + rgba(0, 0, 0, 0.2) 2px, transparent, - transparent 4px + transparent 2px ); z-index: 99; pointer-events: none; @@ -402,7 +402,7 @@ header > h2 { text-shadow: none; } -pre { +[role=code] { counter-reset: line; display: block; border: 1px solid; @@ -453,3 +453,54 @@ input[type=file]::-webkit-file-upload-button { background-color: var(--primary-fg); color: var(--primary-bg); } + +.post { + border-left: 1px solid; + margin-bottom: 15px; +} + +.post-metadata { + background-color: var(--primary-fg); + color: var(--primary-bg); + padding-left: 10px; +} + +.post-metadata a { + color: var(--primary-bg); +} + +.post-metadata > p, +.post-metadata > a { + display: inline-block; +} + +.post-email::before { + content: "<"; +} + +.post-email::after { + content: ">"; +} + +.post-metadata *::selection { + background: var(--primary-bg); + color: var(--primary-fg); +} + +.post-metadata *::-moz-selection { + background: var(--primary-bg); + color: var(--primary-fg); +} + +.post > *:not(:first-child) { + margin-left: 10px; +} + +.post-name { + margin: 0; +} + +.post img { + max-width: 100%; + max-height: 300px; +} diff --git a/utils/handle-post-upload.sh b/utils/handle-post-upload.sh index 1aff46c..43f6b19 100755 --- a/utils/handle-post-upload.sh +++ b/utils/handle-post-upload.sh @@ -18,8 +18,8 @@ if [ -d "$CGIBASHOPTS_DIR" ]; then mkdir -p "$FILE_POST_DESTINATION" for file in "$CGIBASHOPTS_DIR/"*; do - cp "$file" "$FILE_POST_DESTINATION" - POST_FILES="${POST_FILES}$FILE_POST_PATH/$(basename "$file");" + cp "$file" "$FILE_POST_DESTINATION/$FORM_attachment" + POST_FILES="${POST_FILES}$FILE_POST_PATH/$FORM_attachment;" done fi @@ -28,7 +28,15 @@ $FORM_is_private $FORM_name $FORM_email $POST_FILES -$FORM_message +$(sanitize-html-entities "$FORM_message") NEW_POST -BODY="OK" +BODY="$(cat < + + +RESPONSE +)" diff --git a/utils/parse-article-content.sh b/utils/parse-article-content.sh index 40593c5..b217632 100755 --- a/utils/parse-article-content.sh +++ b/utils/parse-article-content.sh @@ -2,12 +2,6 @@ # Skip file metadata, first 3 lines -sanitize-html-entities () { - echo "$1" | - sed 's//\>/g' -} - parse-article-content-file () { local PRE_TAG= local IGNORE_NEXT_PRE_TAG= -- cgit v1.2.3