🎉 init

This commit is contained in:
JMARyA 2022-08-23 02:26:24 +02:00
commit 7bf48daab5
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
10 changed files with 297 additions and 0 deletions

17
src/assets.py Normal file
View 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
View file

@ -0,0 +1,3 @@
import json
CONFIG = json.loads(open("/config/config.json").read())

88
src/index.py Normal file
View 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
View 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)