import os from typing import Optional from flask import request, Response, send_from_directory as send_from_directory_, render_template from .app import app from .config import config from ._sorters import PagesSortByTimeGroupedByFolder def send_from_directory(path: str, file: str, alternative_path: Optional[str] = None, *args, **kwargs): if not os.path.exists(os.path.join(path, file)) and alternative_path: path = alternative_path return send_from_directory_(path, file, *args, **kwargs) @app.route('/', methods=['GET']) def home_route(): return render_template( 'index.html', pages=app.get_pages(sorter=PagesSortByTimeGroupedByFolder), config=config ) @app.route('/img/', methods=['GET']) def img_route(img: str): return send_from_directory(app.img_dir, img, config.default_img_dir) @app.route('/favicon.ico', methods=['GET']) def favicon_route(): return img_route('favicon.ico') @app.route('/css/