aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcomponents/comments.sh55
-rwxr-xr-xconfig.sh15
-rwxr-xr-xindex.sh6
-rwxr-xr-xpages/article.sh46
-rwxr-xr-xpages/contato.sh28
-rw-r--r--static/navigator.js8
-rw-r--r--static/styles.css59
-rwxr-xr-xutils/handle-post-upload.sh16
-rwxr-xr-xutils/parse-article-content.sh6
9 files changed, 212 insertions, 27 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)"
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/</\&lt;/g' |
+ sed 's/>/\&gt;/g'
+}
+
html () {
cat <<HTML
<!DOCTYPE html>
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 <<ERR
@@ -33,5 +35,49 @@ cat <<ARTICLE
</p>
</div>
</section>
+
+ <br />
+ <hr />
+ <section>
+ <h4>Deixei o seu comentário sobre este artigo</h4>
+ <form method="POST" action="/post" enctype="multipart/form-data">
+ <input type="hidden" name="destination" value="$REQUEST_URI/comments" />
+ <input type="hidden" name="redirect_to" value="$REQUEST_URI" />
+
+ <label for="name">Nome</label>
+ <input id="name" type="text" name="name" value="Anônimo" />
+ <br/>
+
+ <label for="email">Email</label>
+ <input id="email" type="email" name="email" />
+ <br/>
+
+ <label for="message">Mensagem *</label>
+ <textarea id="message" name="message" required></textarea>
+ <small>Campos marcados com asterisco (*) são obrigatórios</small>
+ <br />
+
+ <br />
+ <label for="file-attachment">Anexar arquivo</label>
+ <input id="file-attachment" type="file" name="attachment" />
+
+ <input type="submit" value="Enviar" />
+ </form>
+
+ </section>
</article>
+
+<div class="container">
+ <hr />
+ <h4 style="text-align">Discussão</h4>
+ <br />
+
+ $(
+ if [ -n "$PARSED_COMMENTS" ]; then
+ echo "$PARSED_COMMENTS"
+ else
+ echo '<p style="text-align">Sem mensagens para mostrar.</p>'
+ fi
+ )
+</div>
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 <<PAGE
-<style>
- @media screen and (max-width: 600px) {
- .contato-page {
- text-align: center;
- }
- }
-</style>
+COMMENTS_FOLDER="$SCRIPT_DIR/pages/contato/comments" source $SCRIPT_DIR/components/comments.sh
+cat <<PAGE
<article class="contato-page container">
<section>
<h1>Formas de contato</h1>
@@ -35,7 +29,7 @@ cat <<PAGE
<h1>Ou...</h1>
<p>
- ...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 <<PAGE
<form method="POST" action="/post" enctype="multipart/form-data">
<input type="hidden" name="destination" value="/contato/comments" />
+ <input type="hidden" name="redirect_to" value="/contato" />
<label for="name">Nome</label>
<input id="name" type="text" name="name" value="Anônimo" />
@@ -69,6 +64,21 @@ cat <<PAGE
</form>
</section>
</article>
+
+
+<div class="container">
+ <hr />
+ <h4 style="text-align: center">Mensagens</h4>
+ <br />
+
+ $(
+ if [ -n "$PARSED_COMMENTS" ]; then
+ echo "$PARSED_COMMENTS"
+ else
+ echo "<p style=\"text-align: center\">Sem mensagens para mostrar.</p>"
+ fi
+ )
+</div>
PAGE
# Celular e Whatsapp: +55 (81) 97326-9793 <br />
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
+<main>
+ <article>
+ <h1>Post enviado!</h1>
+ <a href="$FORM_redirect_to">Voltar para a página anterior.</a>
+ </article>
+</main>
+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/</\&lt;/g' |
- sed 's/>/\&gt;/g'
-}
-
parse-article-content-file () {
local PRE_TAG=
local IGNORE_NEXT_PRE_TAG=