From e988ef6e1088a35d3628167c345ab8e792828b5b Mon Sep 17 00:00:00 2001 From: Sweetbread Date: Sat, 17 Jan 2026 18:55:25 +0300 Subject: [PATCH] Put personal pages into subdomains --- .gitignore | 4 +- Dockerfile | 6 +-- app.py | 36 ++++++++---------- blueprints/risdeveau/__init__.py | 31 +++++++++++++++ blueprints/risdeveau/modules/style.py | 9 +++++ .../risdeveau/static/img}/wallets/evm.webp | Bin .../risdeveau/static/img}/wallets/ton.webp | Bin .../risdeveau/static/img}/wallets/xmr.webp | Bin .../risdeveau/static}/style/risdeveau.scss | 0 .../risdeveau/templates/index.html | 8 ++-- blueprints/root/__init__.py | 28 ++++++++++++++ blueprints/root/modules/style.py | 9 +++++ .../root/static}/font/Monocraft.ttc | Bin .../root/static}/font/PixelMPlus/Bold.ttf | Bin .../root/static}/font/PixelMPlus/LICENSE_E | 0 .../root/static}/font/PixelMPlus/Regular.ttf | Bin .../root/static}/font/Pixeloid/License.txt | 0 .../static}/font/Pixeloid/otf/Sans-Bold.otf | Bin .../root/static}/font/Pixeloid/otf/Sans.otf | Bin .../font/Pixeloid/woff/Sans-Bold.woff2 | Bin .../static}/font/Pixeloid/woff/Sans.woff2 | Bin .../root/static}/font/SOURCES | 0 .../root/static}/icon/lair.webp | Bin .../root/static}/icon/service/gitea.webp | Bin .../root/static}/icon/service/sharkey.webp | Bin .../root/static}/icon/us/chest.webp | Bin .../root/static}/icon/us/risdeveau.webp | Bin .../root/static}/icon/us/zxcqirara.webp | Bin .../root/static}/script/copy-mono.js | 0 .../root/static}/style/main.scss | 0 .../root/templates}/base.tmpl | 0 .../root/templates}/footer.tmpl | 0 .../root/templates}/header.tmpl | 8 ++-- .../root/templates}/host.html | 0 .../root/templates}/index.html | 0 .../root/templates}/us.html | 2 +- 36 files changed, 106 insertions(+), 35 deletions(-) create mode 100644 blueprints/risdeveau/__init__.py create mode 100644 blueprints/risdeveau/modules/style.py rename {static/img/risdeveau => blueprints/risdeveau/static/img}/wallets/evm.webp (100%) rename {static/img/risdeveau => blueprints/risdeveau/static/img}/wallets/ton.webp (100%) rename {static/img/risdeveau => blueprints/risdeveau/static/img}/wallets/xmr.webp (100%) rename {static => blueprints/risdeveau/static}/style/risdeveau.scss (100%) rename templates/personal/risdeveau.html => blueprints/risdeveau/templates/index.html (91%) create mode 100644 blueprints/root/__init__.py create mode 100644 blueprints/root/modules/style.py rename {static => blueprints/root/static}/font/Monocraft.ttc (100%) rename {static => blueprints/root/static}/font/PixelMPlus/Bold.ttf (100%) rename {static => blueprints/root/static}/font/PixelMPlus/LICENSE_E (100%) rename {static => blueprints/root/static}/font/PixelMPlus/Regular.ttf (100%) rename {static => blueprints/root/static}/font/Pixeloid/License.txt (100%) rename {static => blueprints/root/static}/font/Pixeloid/otf/Sans-Bold.otf (100%) rename {static => blueprints/root/static}/font/Pixeloid/otf/Sans.otf (100%) rename {static => blueprints/root/static}/font/Pixeloid/woff/Sans-Bold.woff2 (100%) rename {static => blueprints/root/static}/font/Pixeloid/woff/Sans.woff2 (100%) rename {static => blueprints/root/static}/font/SOURCES (100%) rename {static => blueprints/root/static}/icon/lair.webp (100%) rename {static => blueprints/root/static}/icon/service/gitea.webp (100%) rename {static => blueprints/root/static}/icon/service/sharkey.webp (100%) rename {static => blueprints/root/static}/icon/us/chest.webp (100%) rename {static => blueprints/root/static}/icon/us/risdeveau.webp (100%) rename {static => blueprints/root/static}/icon/us/zxcqirara.webp (100%) rename {static => blueprints/root/static}/script/copy-mono.js (100%) rename {static => blueprints/root/static}/style/main.scss (100%) rename {templates => blueprints/root/templates}/base.tmpl (100%) rename {templates => blueprints/root/templates}/footer.tmpl (100%) rename {templates => blueprints/root/templates}/header.tmpl (65%) rename {templates => blueprints/root/templates}/host.html (100%) rename {templates => blueprints/root/templates}/index.html (100%) rename {templates => blueprints/root/templates}/us.html (92%) diff --git a/.gitignore b/.gitignore index f80ac9a..d7f8826 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,5 @@ __pycache__/ *$py.class .python-version -static/style/*.css -static/style/*.css.map +*.css +*.css.map diff --git a/Dockerfile b/Dockerfile index f0ea489..bfc6d69 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,8 @@ FROM node:18-alpine as sass RUN NODE_OPTIONS=--dns-result-order=ipv4first npm install -g sass WORKDIR /build -COPY ./static/style ./style -RUN sass ./style:./style \ +COPY ./blueprints ./blueprints +RUN sass ./blueprints:./blueprints \ --no-source-map \ --style=compressed @@ -13,7 +13,7 @@ FROM python:3.11-slim WORKDIR /app COPY . . -COPY --from=sass /build/style/ ./static/style/ +COPY --from=sass /build/blueprints/ ./blueprints/ RUN pip install --no-cache-dir -r requirements.txt diff --git a/app.py b/app.py index 274c7d0..3dfce46 100644 --- a/app.py +++ b/app.py @@ -1,11 +1,15 @@ -from os import system as console from configparser import ConfigParser -from htmlmin import minify + +from blueprints.root import bp as root_bp +from blueprints.risdeveau import bp as rdv_bp + +import blueprints.root.modules.style +import blueprints.risdeveau.modules.style + from flask import ( Flask, g, request, - render_template, ) @@ -29,7 +33,9 @@ def load_translations(lang): def get_locale(): return request.accept_languages.best_match(('en', 'ru', 'de', 'fr', 'ja'), 'en') -app = Flask(__name__) +app = Flask(__name__, static_folder=None, subdomain_matching=True) +app.register_blueprint(root_bp) +app.register_blueprint(rdv_bp) @app.before_request @@ -59,21 +65,9 @@ def inject_translations(): if app.debug: - console("sass static/style/main.scss static/style/main.css") - console("sass static/style/risdeveau.scss static/style/risdeveau.css") + blueprints.root.modules.style.compile_styles() + blueprints.risdeveau.modules.style.compile_styles() -@app.route("/") -def index(): - return minify(render_template('index.html'), remove_empty_space=True) - -@app.route("/host") -def host(): - return minify(render_template('host.html'), remove_empty_space=True) - -@app.route("/us") -def us(): - return minify(render_template('us.html'), remove_empty_space=True) - -@app.route("/risdeveau") -def risdeveau(): - return minify(render_template('personal/risdeveau.html'), remove_empty_space=True) + app.config['SERVER_NAME'] = "localhost:5000" +else: + app.config['SERVER_NAME'] = "lair.moe" diff --git a/blueprints/risdeveau/__init__.py b/blueprints/risdeveau/__init__.py new file mode 100644 index 0000000..af98cae --- /dev/null +++ b/blueprints/risdeveau/__init__.py @@ -0,0 +1,31 @@ +import os +from pathlib import Path +from htmlmin import minify +from flask import Blueprint, render_template, send_from_directory, send_file, abort + +bp = Blueprint( + "risdeveau", + __name__, + subdomain="risdeveau", + template_folder="..", + static_folder=None +) + +def render_tmpl(filename: str) -> str: + template_path = os.path.join("risdeveau/templates", filename) + return minify( + render_template(template_path), + remove_empty_space=True + ) + +@bp.route("/static/") +def static(filename: str): + static_folders = ("static", "../root/static") + for dir in static_folders: + if os.path.exists(path := os.path.join("blueprints/risdeveau", dir, filename)): + return send_file(path) + return abort(404) + +@bp.route("/") +def index(): + return render_tmpl('index.html') diff --git a/blueprints/risdeveau/modules/style.py b/blueprints/risdeveau/modules/style.py new file mode 100644 index 0000000..21d1b72 --- /dev/null +++ b/blueprints/risdeveau/modules/style.py @@ -0,0 +1,9 @@ +from os import system as console +from os.path import join + +def compile_styles(): + dir = "blueprints/risdeveau/static/style" + files = ("risdeveau",) + + for file in files: + console(f"sass {join(dir, file+'.scss')} {join(dir, file+'.css')}") \ No newline at end of file diff --git a/static/img/risdeveau/wallets/evm.webp b/blueprints/risdeveau/static/img/wallets/evm.webp similarity index 100% rename from static/img/risdeveau/wallets/evm.webp rename to blueprints/risdeveau/static/img/wallets/evm.webp diff --git a/static/img/risdeveau/wallets/ton.webp b/blueprints/risdeveau/static/img/wallets/ton.webp similarity index 100% rename from static/img/risdeveau/wallets/ton.webp rename to blueprints/risdeveau/static/img/wallets/ton.webp diff --git a/static/img/risdeveau/wallets/xmr.webp b/blueprints/risdeveau/static/img/wallets/xmr.webp similarity index 100% rename from static/img/risdeveau/wallets/xmr.webp rename to blueprints/risdeveau/static/img/wallets/xmr.webp diff --git a/static/style/risdeveau.scss b/blueprints/risdeveau/static/style/risdeveau.scss similarity index 100% rename from static/style/risdeveau.scss rename to blueprints/risdeveau/static/style/risdeveau.scss diff --git a/templates/personal/risdeveau.html b/blueprints/risdeveau/templates/index.html similarity index 91% rename from templates/personal/risdeveau.html rename to blueprints/risdeveau/templates/index.html index ca476d1..5ad3f1e 100644 --- a/templates/personal/risdeveau.html +++ b/blueprints/risdeveau/templates/index.html @@ -15,7 +15,7 @@
- Lair + Lair
@@ -70,17 +70,17 @@

POL, BNB

- +

TON

- +

XMR

- +
diff --git a/blueprints/root/__init__.py b/blueprints/root/__init__.py new file mode 100644 index 0000000..903dc7d --- /dev/null +++ b/blueprints/root/__init__.py @@ -0,0 +1,28 @@ +from htmlmin import minify +from flask import Blueprint, render_template, request, jsonify + +bp = Blueprint( + "root", + __name__, + template_folder="templates", + static_folder="static" +) + +def render_tmpl(filename: str) -> str: + return minify( + render_template(filename), + remove_empty_space=True + ) + + +@bp.route("/") +def index(): + return render_tmpl('index.html') + +@bp.route("/host") +def host(): + return render_tmpl('host.html') + +@bp.route("/us") +def us(): + return render_tmpl('us.html') diff --git a/blueprints/root/modules/style.py b/blueprints/root/modules/style.py new file mode 100644 index 0000000..dc30d2d --- /dev/null +++ b/blueprints/root/modules/style.py @@ -0,0 +1,9 @@ +from os import system as console +from os.path import join + +def compile_styles(): + dir = "blueprints/root/static/style" + files = ("main",) + + for file in files: + console(f"sass {join(dir, file+'.scss')} {join(dir, file+'.css')}") \ No newline at end of file diff --git a/static/font/Monocraft.ttc b/blueprints/root/static/font/Monocraft.ttc similarity index 100% rename from static/font/Monocraft.ttc rename to blueprints/root/static/font/Monocraft.ttc diff --git a/static/font/PixelMPlus/Bold.ttf b/blueprints/root/static/font/PixelMPlus/Bold.ttf similarity index 100% rename from static/font/PixelMPlus/Bold.ttf rename to blueprints/root/static/font/PixelMPlus/Bold.ttf diff --git a/static/font/PixelMPlus/LICENSE_E b/blueprints/root/static/font/PixelMPlus/LICENSE_E similarity index 100% rename from static/font/PixelMPlus/LICENSE_E rename to blueprints/root/static/font/PixelMPlus/LICENSE_E diff --git a/static/font/PixelMPlus/Regular.ttf b/blueprints/root/static/font/PixelMPlus/Regular.ttf similarity index 100% rename from static/font/PixelMPlus/Regular.ttf rename to blueprints/root/static/font/PixelMPlus/Regular.ttf diff --git a/static/font/Pixeloid/License.txt b/blueprints/root/static/font/Pixeloid/License.txt similarity index 100% rename from static/font/Pixeloid/License.txt rename to blueprints/root/static/font/Pixeloid/License.txt diff --git a/static/font/Pixeloid/otf/Sans-Bold.otf b/blueprints/root/static/font/Pixeloid/otf/Sans-Bold.otf similarity index 100% rename from static/font/Pixeloid/otf/Sans-Bold.otf rename to blueprints/root/static/font/Pixeloid/otf/Sans-Bold.otf diff --git a/static/font/Pixeloid/otf/Sans.otf b/blueprints/root/static/font/Pixeloid/otf/Sans.otf similarity index 100% rename from static/font/Pixeloid/otf/Sans.otf rename to blueprints/root/static/font/Pixeloid/otf/Sans.otf diff --git a/static/font/Pixeloid/woff/Sans-Bold.woff2 b/blueprints/root/static/font/Pixeloid/woff/Sans-Bold.woff2 similarity index 100% rename from static/font/Pixeloid/woff/Sans-Bold.woff2 rename to blueprints/root/static/font/Pixeloid/woff/Sans-Bold.woff2 diff --git a/static/font/Pixeloid/woff/Sans.woff2 b/blueprints/root/static/font/Pixeloid/woff/Sans.woff2 similarity index 100% rename from static/font/Pixeloid/woff/Sans.woff2 rename to blueprints/root/static/font/Pixeloid/woff/Sans.woff2 diff --git a/static/font/SOURCES b/blueprints/root/static/font/SOURCES similarity index 100% rename from static/font/SOURCES rename to blueprints/root/static/font/SOURCES diff --git a/static/icon/lair.webp b/blueprints/root/static/icon/lair.webp similarity index 100% rename from static/icon/lair.webp rename to blueprints/root/static/icon/lair.webp diff --git a/static/icon/service/gitea.webp b/blueprints/root/static/icon/service/gitea.webp similarity index 100% rename from static/icon/service/gitea.webp rename to blueprints/root/static/icon/service/gitea.webp diff --git a/static/icon/service/sharkey.webp b/blueprints/root/static/icon/service/sharkey.webp similarity index 100% rename from static/icon/service/sharkey.webp rename to blueprints/root/static/icon/service/sharkey.webp diff --git a/static/icon/us/chest.webp b/blueprints/root/static/icon/us/chest.webp similarity index 100% rename from static/icon/us/chest.webp rename to blueprints/root/static/icon/us/chest.webp diff --git a/static/icon/us/risdeveau.webp b/blueprints/root/static/icon/us/risdeveau.webp similarity index 100% rename from static/icon/us/risdeveau.webp rename to blueprints/root/static/icon/us/risdeveau.webp diff --git a/static/icon/us/zxcqirara.webp b/blueprints/root/static/icon/us/zxcqirara.webp similarity index 100% rename from static/icon/us/zxcqirara.webp rename to blueprints/root/static/icon/us/zxcqirara.webp diff --git a/static/script/copy-mono.js b/blueprints/root/static/script/copy-mono.js similarity index 100% rename from static/script/copy-mono.js rename to blueprints/root/static/script/copy-mono.js diff --git a/static/style/main.scss b/blueprints/root/static/style/main.scss similarity index 100% rename from static/style/main.scss rename to blueprints/root/static/style/main.scss diff --git a/templates/base.tmpl b/blueprints/root/templates/base.tmpl similarity index 100% rename from templates/base.tmpl rename to blueprints/root/templates/base.tmpl diff --git a/templates/footer.tmpl b/blueprints/root/templates/footer.tmpl similarity index 100% rename from templates/footer.tmpl rename to blueprints/root/templates/footer.tmpl diff --git a/templates/header.tmpl b/blueprints/root/templates/header.tmpl similarity index 65% rename from templates/header.tmpl rename to blueprints/root/templates/header.tmpl index 2ab61dd..e6fe82f 100644 --- a/templates/header.tmpl +++ b/blueprints/root/templates/header.tmpl @@ -1,14 +1,14 @@
- {%- if request.path != url_for('index') %} - Lair + {%- if request.path != url_for('.index') %} + Lair {%- else %}
{%- endif %}