shii.moe

Source for `shii.moe' website.
git clone git://git.knutsen.co/shii.moe
Log | Files | Refs | README | LICENSE

commit e1287f607213b69c393c9e383fb4879c51e5095d
parent 67bee3b8b2e6eb50c1fab78babdd89b208e7b5f6
Author: knutsen <samuel@knutsen.co>
Date:   Tue, 22 Jun 2021 19:48:20 +0100

Clean up directory structure, add 404 page.

Diffstat:
Rbackground-300x300.png -> public/background-300x300.png | 0
Rbackground.png -> public/background.png | 0
Rclassical.jpg -> public/classical.jpg | 0
Remo7.png -> public/emo7.png | 0
Apublic/favicon.ico | 2++
Rgita.jpg -> public/gita.jpg | 0
Rimage.js -> public/image.js | 0
Rlemon.mp3 -> public/lemon.mp3 | 0
Rmascots/1-square.png -> public/mascots/1-square.png | 0
Rmascots/1.png -> public/mascots/1.png | 0
Rmascots/10-square.png -> public/mascots/10-square.png | 0
Rmascots/10.png -> public/mascots/10.png | 0
Rmascots/11-square.png -> public/mascots/11-square.png | 0
Rmascots/11.png -> public/mascots/11.png | 0
Rmascots/12-square.png -> public/mascots/12-square.png | 0
Rmascots/12.png -> public/mascots/12.png | 0
Rmascots/13-square.png -> public/mascots/13-square.png | 0
Rmascots/13.png -> public/mascots/13.png | 0
Rmascots/14-square.png -> public/mascots/14-square.png | 0
Rmascots/14.png -> public/mascots/14.png | 0
Rmascots/2-square.png -> public/mascots/2-square.png | 0
Rmascots/2.png -> public/mascots/2.png | 0
Rmascots/3-square.png -> public/mascots/3-square.png | 0
Rmascots/3.png -> public/mascots/3.png | 0
Rmascots/4-square.png -> public/mascots/4-square.png | 0
Rmascots/4.png -> public/mascots/4.png | 0
Rmascots/5-square.png -> public/mascots/5-square.png | 0
Rmascots/5.png -> public/mascots/5.png | 0
Rmascots/6-square.png -> public/mascots/6-square.png | 0
Rmascots/6.png -> public/mascots/6.png | 0
Rmascots/7-square.png -> public/mascots/7-square.png | 0
Rmascots/7.png -> public/mascots/7.png | 0
Rmascots/8-square.png -> public/mascots/8-square.png | 0
Rmascots/8.png -> public/mascots/8.png | 0
Rmascots/9-square.png -> public/mascots/9-square.png | 0
Rmascots/9.png -> public/mascots/9.png | 0
Rmaths.pdf -> public/maths.pdf | 0
Rmy favourite things_8.jpg -> public/my favourite things_8.jpg | 0
Rnorsk.png -> public/norsk.png | 0
Rrio.mp3 -> public/rio.mp3 | 0
Rshiimoe.rsa -> public/shiimoe.pub | 0
Rstyle.css -> public/style.css | 0
Ryui.png -> public/yui.png | 0
Rcrop-mascots.sh -> scripts/crop-mascots.sh | 0
Mshiimoe.py | 45++++++++++++++++++++++++++++++++++++---------
Astatic/404.html | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Rbooks.html -> static/books.html | 0
Rindex.html -> static/index.html | 0
Rmusic.html -> static/music.html | 0
Rnorsk.html -> static/norsk.html | 0
Rschool.html -> static/school.html | 0
51 files changed, 88 insertions(+), 9 deletions(-)

diff --git a/background-300x300.png b/public/background-300x300.png Binary files differ. diff --git a/background.png b/public/background.png Binary files differ. diff --git a/classical.jpg b/public/classical.jpg Binary files differ. diff --git a/emo7.png b/public/emo7.png Binary files differ. diff --git a/public/favicon.ico b/public/favicon.ico @@ -0,0 +1 @@ +./mascots/1-square.png+ \ No newline at end of file diff --git a/gita.jpg b/public/gita.jpg Binary files differ. diff --git a/image.js b/public/image.js diff --git a/lemon.mp3 b/public/lemon.mp3 Binary files differ. diff --git a/mascots/1-square.png b/public/mascots/1-square.png Binary files differ. diff --git a/mascots/1.png b/public/mascots/1.png Binary files differ. diff --git a/mascots/10-square.png b/public/mascots/10-square.png Binary files differ. diff --git a/mascots/10.png b/public/mascots/10.png Binary files differ. diff --git a/mascots/11-square.png b/public/mascots/11-square.png Binary files differ. diff --git a/mascots/11.png b/public/mascots/11.png Binary files differ. diff --git a/mascots/12-square.png b/public/mascots/12-square.png Binary files differ. diff --git a/mascots/12.png b/public/mascots/12.png Binary files differ. diff --git a/mascots/13-square.png b/public/mascots/13-square.png Binary files differ. diff --git a/mascots/13.png b/public/mascots/13.png Binary files differ. diff --git a/mascots/14-square.png b/public/mascots/14-square.png Binary files differ. diff --git a/mascots/14.png b/public/mascots/14.png Binary files differ. diff --git a/mascots/2-square.png b/public/mascots/2-square.png Binary files differ. diff --git a/mascots/2.png b/public/mascots/2.png Binary files differ. diff --git a/mascots/3-square.png b/public/mascots/3-square.png Binary files differ. diff --git a/mascots/3.png b/public/mascots/3.png Binary files differ. diff --git a/mascots/4-square.png b/public/mascots/4-square.png Binary files differ. diff --git a/mascots/4.png b/public/mascots/4.png Binary files differ. diff --git a/mascots/5-square.png b/public/mascots/5-square.png Binary files differ. diff --git a/mascots/5.png b/public/mascots/5.png Binary files differ. diff --git a/mascots/6-square.png b/public/mascots/6-square.png Binary files differ. diff --git a/mascots/6.png b/public/mascots/6.png Binary files differ. diff --git a/mascots/7-square.png b/public/mascots/7-square.png Binary files differ. diff --git a/mascots/7.png b/public/mascots/7.png Binary files differ. diff --git a/mascots/8-square.png b/public/mascots/8-square.png Binary files differ. diff --git a/mascots/8.png b/public/mascots/8.png Binary files differ. diff --git a/mascots/9-square.png b/public/mascots/9-square.png Binary files differ. diff --git a/mascots/9.png b/public/mascots/9.png Binary files differ. diff --git a/maths.pdf b/public/maths.pdf Binary files differ. diff --git a/my favourite things_8.jpg b/public/my favourite things_8.jpg Binary files differ. diff --git a/norsk.png b/public/norsk.png Binary files differ. diff --git a/rio.mp3 b/public/rio.mp3 Binary files differ. diff --git a/shiimoe.rsa b/public/shiimoe.pub diff --git a/style.css b/public/style.css diff --git a/yui.png b/public/yui.png Binary files differ. diff --git a/crop-mascots.sh b/scripts/crop-mascots.sh diff --git a/shiimoe.py b/shiimoe.py @@ -7,11 +7,11 @@ import pymdownx, pymdownx.emoji import bleach from datetime import datetime -from os import path +import os import json import re -app = Flask(__name__, static_url_path="", static_folder="./") +app = Flask(__name__, static_folder="./public") md = markdown.Markdown( extensions=['fenced_code', 'codehilite', 'pymdownx.emoji'], extension_configs={ @@ -48,10 +48,31 @@ def read_comments(): return comments +STATIC_PATH = os.path.realpath('./static') +PUBLIC_PATH = os.path.realpath('./public') + +def is_subpath(path, dir): + return path.startswith(dir) + +def send_static_page(path, filename): + path = os.path.realpath(f'{STATIC_PATH}/{path}') + if not is_subpath(path, STATIC_PATH): + return 403 + + if not filename.endswith('.html'): + filename += '.html' + return send_from_directory(path, filename) + +def send_public_asset(path, filename): + path = os.path.realpath(f'{PUBLIC_PATH}/{path}') + if not is_subpath(path, PUBLIC_PATH): + return 403 + + return send_from_directory(path, filename) @app.route('/') def home(): - return send_from_directory('./', 'index.html') + return send_static_page('./', 'index.html') def render_guestbook(**kw): comments = read_comments() @@ -66,6 +87,7 @@ def render_guestbook(**kw): return render_template('guestbook.html', **kw) @app.route('/guestbook') +@app.route('/guestbook.html') def guestbook(): return render_guestbook() @@ -112,12 +134,17 @@ def postcomment(): return redirect('/guestbook', code=302) -@app.route('/<p>') -def serve_static(p): - print("testets") - if path.exists(p + '.html'): - return send_from_directory('./', p + '.html') - return send_from_directory('./', p) +@app.route('/<path:filepath>') +def serve_static(filepath): + path, filename = os.path.split(filepath) + if os.path.exists(f'{PUBLIC_PATH}/{path}/{filename}'): + return send_public_asset(path, filename) + if not filename.endswith('.html'): + filename += '.html' + if os.path.exists(f'{STATIC_PATH}/{path}/{filename}'): + return send_static_page(path, filename) + # Otherwise, 404. + return send_static_page('./', '404.html'), 404 if __name__ == "__main__": app.run(debug=True) diff --git a/static/404.html b/static/404.html @@ -0,0 +1,50 @@ +<!DOCTYPE html> +<html lang="en"> + +<head> + <title>Shimo Couldn't Find That!!</title> + <link rel='stylesheet' type='text/css' href="/style.css"> + <link rel='icon' type='image/png' href="/mascots/1-square.png"> + <meta charset="utf-8"/> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> +</head> +<body> + <div id="content"> + + <a href="/"><h1>Shimo!!</h1></a> + + <div class="titleBar"> + <div class="titleButton"><a href="/music">Musik</a></div> + <div class="titleButton"><a href="/school">Skole</a></div> + <div class="titleButton"><a href="/norsk">Norsk</a></div> + <div class="titleButton"><a href="/books">Bøker</a></div> + </div> + + <h1>404, Not Found!</h1> + <p id="bottom" align="center">Couldn't find that page, sorry!!</p> + + <style> + body, html { + overflow: hidden; + } + #mascot { + transition: all .3s ease; + opacity: 0; + bottom: 0; + left: 50%; + height: 0; + transform: translateX(-50%); + } + </style> + <img src="/mascots/1.png" id="mascot"></img> + <script src="image.js"></script> + <script> + const bottom = document.getElementById('bottom'); + mascot.style.height = + `${window.innerHeight - (bottom.offsetTop + bottom.offsetHeight)}px`; + </script> + <script> + setTimeout(() => mascot.style.opacity = '1', 30); + </script> +</body> +</html> diff --git a/books.html b/static/books.html diff --git a/index.html b/static/index.html diff --git a/music.html b/static/music.html diff --git a/norsk.html b/static/norsk.html diff --git a/school.html b/static/school.html