feat: add markdown support for privacy policy
All checks were successful
Python Package CI/CD / Publish to PyPI (push) Successful in 39s

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.
This commit is contained in:
Kumi 2024-06-08 20:07:58 +02:00
parent b2721c7de1
commit cc450e10ff
Signed by: kumi
GPG key ID: ECBCC9082395383F
4 changed files with 19 additions and 3 deletions

1
.gitignore vendored
View file

@ -3,4 +3,5 @@ venv/
__pycache__/
.vscode
privacy.txt
privacy.md
/dist/

View file

@ -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]

View file

@ -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):

View file

@ -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