feat: add markdown support for privacy policy
All checks were successful
Python Package CI/CD / Publish to PyPI (push) Successful in 39s
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:
parent
b2721c7de1
commit
cc450e10ff
4 changed files with 19 additions and 3 deletions
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue