aboutsummaryrefslogtreecommitdiff
path: root/index.sh
diff options
context:
space:
mode:
Diffstat (limited to 'index.sh')
-rwxr-xr-xindex.sh95
1 files changed, 95 insertions, 0 deletions
diff --git a/index.sh b/index.sh
new file mode 100755
index 0000000..16eb31c
--- /dev/null
+++ b/index.sh
@@ -0,0 +1,95 @@
+#!/bin/bash
+
+if [ "$REQUEST_URI" = '/favicon.ico' ]; then
+ exit 0
+fi
+
+RESPONSE_CONTENT_TYPE="text/html"
+STATUS=200
+
+HEADER_TITLE='source ./programadores/Jefferson Júlio/site/home.sh'
+HEADER_TITLE_MOBILE='cd ./programadores/ && \\ ;> source Jefferson Júlio/\\ ;> site/home.sh'
+
+urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
+
+html () {
+ cat <<HTML
+<html lang="pt-br">
+ <head>
+ <meta charset="utf-8" />
+ <title>jefferson.sh</title>
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
+
+ <style>
+ $(cat ./styles.css)
+ </style>
+ </head>
+
+ <body>
+ $(source ./nav.sh)
+ $(source ./header.sh)
+
+ <main>
+ $BODY
+ </main>
+
+ $(source ./footer.sh)
+ </body>
+</html>
+HTML
+}
+
+router () {
+ REQUEST_URI=$(urldecode "$REQUEST_URI")
+
+ case "$REQUEST_URI" in
+ /)
+ BODY=$(source ./pages/home.sh)
+ ;;
+ /contato)
+ HEADER_TITLE="source ./pages/contato.sh"
+ HEADER_TITLE_MOBILE="$HEADER_TITLE"
+ BODY=$(source ./pages/contato.sh)
+ ;;
+ /artigo/*.txt)
+ ARTICLE_FILE=./pages/articles/${REQUEST_URI/\/artigo\//}
+ HEADER_TITLE="cat $ARTICLE_FILE"
+ HEADER_TITLE_MOBILE="$HEADER_TITLE"
+ BODY=$(source ./pages/article.sh)
+ ;;
+ /json)
+ RESPONSE_CONTENT_TYPE="application/json"
+ STATUS=200
+ BODY=$(cat <<JSON
+{
+ "teste": "JSON"
+}
+JSON
+)
+ ;;
+ *)
+ STATUS=404
+ HEADER_TITLE="cat .$REQUEST_URI"
+ HEADER_TITLE_MOBILE="$HEADER_TITLE"
+ BODY="<p class='err-404'>cat: .$REQUEST_URI: Arquivo ou diretório inexistente</p>"
+ ;;
+ esac
+}
+
+router
+
+case "$RESPONSE_CONTENT_TYPE" in
+ "text/html")
+ RESPONSE_BODY=$(html)
+ ;;
+ *)
+ RESPONSE_BODY=$BODY
+esac
+
+
+cat <<INDEX
+Content-Type: $RESPONSE_CONTENT_TYPE
+Status: $STATUS
+
+$RESPONSE_BODY
+INDEX