From cc450e10ff4cfb08e7ef8af03730cfd0b3f8ef3d Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 8 Jun 2024 20:07:58 +0200 Subject: [PATCH] feat: add markdown support for privacy policy Introduced markdown rendering for the privacy policy alongside plain text support. This change enriches the presentation of the privacy policy by allowing markdown-formatted files. To facilitate this, the markdown2 library was added as a dependency, and the logic in the privacy policy route was adjusted to prioritize `.md` files over `.txt` when available. This update also includes a minor version bump and the addition of a markdown-related entry to `.gitignore`. These changes enhance the flexibility and user experience by supporting more visually structured privacy policies. The removal of the default privacy file path (`privacy.txt`) from the environment configuration encourages explicit file path specification, accommodating the new markdown feature more seamlessly. --- .gitignore | 1 + pyproject.toml | 3 ++- src/structables/config.py | 2 +- src/structables/routes/main.py | 16 +++++++++++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7fcfbdc..e9fb3cf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ venv/ __pycache__/ .vscode privacy.txt +privacy.md /dist/ \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 48c35bc..af0ddf7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "structables" -version = "0.3.5" +version = "0.3.6" authors = [ { name="Private.coffee Team", email="support@private.coffee" }, ] @@ -20,6 +20,7 @@ classifiers = [ dependencies = [ "flask", "bs4", + "markdown2[all]", ] [project.scripts] diff --git a/src/structables/config.py b/src/structables/config.py index fd9dc36..738df6d 100644 --- a/src/structables/config.py +++ b/src/structables/config.py @@ -6,7 +6,7 @@ class Config: LISTEN_HOST = os.environ.get("STRUCTABLES_LISTEN_HOST", "127.0.0.1") INVIDIOUS = os.environ.get("STRUCTABLES_INVIDIOUS") UNSAFE = os.environ.get("STRUCTABLES_UNSAFE", False) - PRIVACY_FILE = os.environ.get("STRUCTABLES_PRIVACY_FILE", "privacy.txt") + PRIVACY_FILE = os.environ.get("STRUCTABLES_PRIVACY_FILE") @staticmethod def init_app(app): diff --git a/src/structables/routes/main.py b/src/structables/routes/main.py index 2ea749b..d6441d9 100644 --- a/src/structables/routes/main.py +++ b/src/structables/routes/main.py @@ -4,6 +4,7 @@ from urllib.error import HTTPError from bs4 import BeautifulSoup from urllib.parse import quote from werkzeug.exceptions import InternalServerError +from markdown2 import Markdown from traceback import print_exc import pathlib import json @@ -342,11 +343,24 @@ def init_main_routes(app): content = "No privacy policy found." - path = app.config.get("PRIVACY_FILE", "privacy.txt") + path = app.config.get("PRIVACY_FILE") + + if not path: + if pathlib.Path("privacy.md").exists(): + path = "privacy.md" + + elif pathlib.Path("privacy.txt").exists(): + path = "privacy.txt" try: with pathlib.Path(path).open() as f: content = f.read() + + print(path, content) + + if path.endswith(".md"): + content = Markdown().convert(content) + except OSError: pass