🎉 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

136
.gitignore vendored Normal file
View file

@ -0,0 +1,136 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pdm
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzerw
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
.idea/
# Specific
.DS_Store
/config/
/db/
.vscode

11
Dockerfile Normal file
View file

@ -0,0 +1,11 @@
FROM python:3
COPY requirements.txt /
RUN pip3 install -r /requirements.txt
VOLUME /config
COPY src /app
CMD [ "python3", "/app/main.py" ]

11
Makefile Normal file
View file

@ -0,0 +1,11 @@
fmt:
black .
clean:
fd pycache -I -x rm -rv {}
restart:
docker-compose down
docker-compose build
docker-compose up -d

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# Me Site
Simple website for personal information

11
docker-compose.yml Normal file
View file

@ -0,0 +1,11 @@
version: '3'
services:
app:
build: "."
environment:
TZ: Europe/Berlin
ports:
- 1030:1030
volumes:
- ./config:/config

2
requirements.txt Normal file
View file

@ -0,0 +1,2 @@
Flask
git+https://github.com/jmarya/htmlpy#egg=htmlpy

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)