@@ -5,6 +5,7 @@ A simple Flask blog powered by markdown files."""import htmlimport jsonimport mathimport osimport random
@@ -24,8 +25,33 @@ from flask import (from weasyprint import HTMLapp = Flask(__name__)app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 31536000CONTENT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "content")MANIFEST_PATH = os.path.join(app.static_folder, ".vite", "manifest.json")_manifest_cache = Nonedef get_vite_manifest(): global _manifest_cache if _manifest_cache is None or app.debug: with open(MANIFEST_PATH) as f: _manifest_cache = json.load(f) return _manifest_cachedef vite_asset(entry, kind="file"): manifest = get_vite_manifest() chunk = manifest.get(entry) if chunk: if kind == "css" and "css" in chunk: return "/static/" + chunk["css"][0] return "/static/" + chunk["file"] return url_for("static", filename=entry)app.jinja_env.globals["vite_asset"] = vite_asset# -- Markdown rendering -------------------------------------------------------
modified
templates/base.html
@@ -10,7 +10,7 @@ {% block extra_head %}{% endblock %} <link href="{{ url_for('static', filename='base.css') }}" rel="stylesheet"> <link href="{{ vite_asset('index.js', 'css') }}" rel="stylesheet"> {% block extra_css %}{% endblock %} {% include 'includes/collector.html' %}
@@ -122,7 +122,7 @@ </div> {% endblock %} <script src="{{ url_for('static', filename='base.js') }}"></script> <script src="{{ vite_asset('index.js') }}"></script> {% block extra_js %}{% endblock %}</body></html>
@@ -7,18 +7,19 @@ export default defineConfig({ build: { outDir: resolve(__dirname, "static"), emptyOutDir: true, manifest: true, rollupOptions: { input: resolve(__dirname, "static_src/index.js"), output: { entryFileNames: "base.js", entryFileNames: "base-[hash].js", assetFileNames: (assetInfo) => { if (/\.(woff2?|eot|ttf|otf)$/.test(assetInfo.name)) { return "fonts/[name][extname]"; } if (/\.css$/.test(assetInfo.name)) { return "base.css"; return "base-[hash].css"; } return "assets/[name][extname]"; return "assets/[name]-[hash][extname]"; }, }, },