#!/usr/bin/env python3 from flask import Flask, abort import markdown as Markdown from os.path import join, isfile from functools import cache from os import getenv data_path = getenv('DATA_PATH', 'data') app = Flask(__name__) @cache def pathfinder(path): if path == '/': path = '' for local_path in [ join(data_path, f'{path}.md'), join(data_path, path, 'index.md'), ]: if isfile(local_path): return local_path abort(404) @cache @app.route('/', defaults={'path': ''}) @app.route('/') def catch_all(path): local_path = pathfinder(path) if isfile(local_path): with open(local_path, 'r') as file: return Markdown.markdown(file.read()) @app.route('/favicon.ico') def favicon(): return ""