🎉 init
This commit is contained in:
commit
7bf48daab5
10 changed files with 297 additions and 0 deletions
17
src/assets.py
Normal file
17
src/assets.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
from flask import request, session, Blueprint, Response, send_from_directory
|
||||
from htmlpy import *
|
||||
from config import CONFIG
|
||||
import os
|
||||
|
||||
asset_pages = Blueprint("assets", __name__)
|
||||
|
||||
|
||||
def filesend(path):
|
||||
filename = os.path.basename(path)
|
||||
dirpath = os.path.dirname(path)
|
||||
return send_from_directory(dirpath, filename)
|
||||
|
||||
|
||||
@asset_pages.route("/me", methods=["GET"])
|
||||
def me_picture():
|
||||
return filesend("/config/me.avif")
|
3
src/config.py
Normal file
3
src/config.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
import json
|
||||
|
||||
CONFIG = json.loads(open("/config/config.json").read())
|
88
src/index.py
Normal file
88
src/index.py
Normal file
|
@ -0,0 +1,88 @@
|
|||
from flask import request, session, Blueprint, Response
|
||||
from htmlpy import *
|
||||
from config import CONFIG
|
||||
from os.path import exists
|
||||
|
||||
main_pages = Blueprint("main", __name__)
|
||||
|
||||
BOOTSTRAP = [
|
||||
Reference(
|
||||
"https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css",
|
||||
"stylesheet",
|
||||
),
|
||||
Reference(
|
||||
"https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css",
|
||||
"stylesheet",
|
||||
),
|
||||
Script(
|
||||
src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js"
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def buildSite(content):
|
||||
return Document(
|
||||
head=Head(
|
||||
[Meta(name="viewport", content="width=350, user-scalable=0;"), BOOTSTRAP]
|
||||
),
|
||||
body=Body(
|
||||
content,
|
||||
global_attr=GlobalAttributes(
|
||||
css_class="bg-dark text-white justify-content-center text-center"
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@main_pages.route("/public_key", methods=["GET"])
|
||||
def public_key():
|
||||
try:
|
||||
ret = open("/config/pub.key").read()
|
||||
|
||||
ua = request.user_agent.string.lower()
|
||||
if "chrome" in ua or "safari" in ua or "firefox" in ua:
|
||||
return buildSite(Paragraph(ret.replace("\n", "<br>"))).to_code()
|
||||
|
||||
resp = Response(response=ret, status=200, mimetype="application/pgp-keys")
|
||||
return resp
|
||||
except:
|
||||
return Response(response="", status=502)
|
||||
|
||||
|
||||
# Main
|
||||
@main_pages.route("/", methods=["GET"])
|
||||
def index():
|
||||
return buildSite(
|
||||
[
|
||||
Div(
|
||||
[
|
||||
Image(
|
||||
"/assets/me",
|
||||
200,
|
||||
200,
|
||||
"Me",
|
||||
global_attr=GlobalAttributes(css_class="rounded"),
|
||||
),
|
||||
LineBreak(),
|
||||
LineBreak(),
|
||||
Heading(1, CONFIG["name"]),
|
||||
ThematicBreak(),
|
||||
],
|
||||
global_attr=GlobalAttributes(
|
||||
css_class="container border-dark", style="margin-top: 20px"
|
||||
),
|
||||
),
|
||||
Div(
|
||||
[
|
||||
Heading(1, "Contact"),
|
||||
ThematicBreak(),
|
||||
[Link("/public_key", "My PGP Key"), LineBreak()]
|
||||
if exists("/config/pub.key")
|
||||
else None,
|
||||
Link(f"mailto:{CONFIG['email']}", CONFIG["email"]),
|
||||
LineBreak(),
|
||||
],
|
||||
global_attr=GlobalAttributes(css_class="container border-dark"),
|
||||
),
|
||||
]
|
||||
).to_code()
|
15
src/main.py
Normal file
15
src/main.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from flask import Flask, session, request
|
||||
from config import CONFIG
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = CONFIG["secret_key"]
|
||||
|
||||
from index import main_pages
|
||||
from assets import asset_pages
|
||||
|
||||
app.register_blueprint(main_pages)
|
||||
app.register_blueprint(asset_pages, url_prefix="/assets")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=1030, debug=True, threaded=True)
|
Loading…
Add table
Add a link
Reference in a new issue