This commit is contained in:
retoor 2025-11-16 01:48:39 +01:00
parent 57c37750ec
commit 2cc2a31ab2
4 changed files with 160 additions and 55 deletions

View File

@ -53,37 +53,110 @@ class LegalDocument(ABC):
return self.get_header() + self.get_content() + self.get_footer()
def to_html(self) -> str:
"""Generate the complete document in HTML format."""
# Content is already HTML, just wrap in basic HTML structure
"""Generate the complete document as Jinja2 template extending base.html."""
html_content = self.get_content()
html_content = f"""<html>
<head>
<title>{self.title}</title>
template_content = f"""{{% extends "base.html" %}}
{{% block title %}}{self.title} - MyWebdav{{% endblock %}}
{{% block description %}}{self.title} for MyWebdav cloud storage service.{{% endblock %}}
{{% block extra_css %}}
<style>
body {{
font-family: 'Times New Roman', serif;
line-height: 1.6;
max-width: 800px;
.legal-content {{
max-width: 900px;
margin: 0 auto;
padding: 20px;
padding: 3rem 2rem;
background: white;
border-radius: 8px;
}}
.legal-title {{
font-size: 2.5rem;
font-weight: 700;
color: #1565c0;
margin-bottom: 1rem;
padding-bottom: 1rem;
border-bottom: 3px solid #1976d2;
}}
.legal-updated {{
color: #666;
font-style: italic;
margin-bottom: 2rem;
}}
.legal-content h2 {{
font-size: 1.75rem;
color: #333;
margin-top: 2rem;
margin-bottom: 1rem;
padding-bottom: 0.5rem;
border-bottom: 2px solid #e0e0e0;
}}
.legal-content h3 {{
font-size: 1.25rem;
color: #555;
margin-top: 1.5rem;
margin-bottom: 0.75rem;
}}
.legal-content p {{
line-height: 1.8;
color: #555;
margin-bottom: 1rem;
}}
.legal-content ul {{
margin-left: 2rem;
margin-bottom: 1rem;
}}
.legal-content li {{
margin-bottom: 0.5rem;
line-height: 1.6;
color: #555;
}}
.legal-content strong {{
color: #333;
font-weight: 600;
}}
.legal-contact {{
margin-top: 3rem;
padding: 2rem;
background: #f5f5f5;
border-radius: 8px;
border-left: 4px solid #1976d2;
}}
.legal-contact h3 {{
color: #1565c0;
margin-top: 0;
}}
@media (max-width: 768px) {{
.legal-title {{
font-size: 2rem;
}}
.legal-content {{
padding: 2rem 1rem;
}}
h1, h2, h3 {{
color: #2c3e50;
margin-top: 30px;
}}
h1 {{ font-size: 2em; border-bottom: 2px solid #3498db; padding-bottom: 10px; }}
h2 {{ font-size: 1.5em; border-bottom: 1px solid #bdc3c7; padding-bottom: 5px; }}
ul {{ margin-left: 20px; }}
li {{ margin-bottom: 8px; }}
strong {{ color: #2c3e50; }}
</style>
</head>
<body>
<h1>{self.title}</h1>
<p><em>Last Updated: {self.last_updated}</em></p>
{{% endblock %}}
{{% block content %}}
<div class="legal-content">
<h1 class="legal-title">{self.title}</h1>
<p class="legal-updated">Last Updated: {self.last_updated}</p>
{html_content}
<hr>
<div class="legal-contact">
<h3>Contact Information</h3>
<p>If you have any questions about this {self.title.lower()}, please contact us:</p>
<ul>
@ -91,10 +164,11 @@ class LegalDocument(ABC):
<li><strong>Website:</strong> <a href="{self.website}">{self.website}</a></li>
<li><strong>Address:</strong> MyWebdav Technologies, European Union</li>
</ul>
<p>MyWebdav Technologies</p>
</body>
</html>"""
return html_content
</div>
</div>
{{% endblock %}}
"""
return template_content
class PrivacyPolicy(LegalDocument):
@ -867,28 +941,21 @@ def get_all_legal_documents() -> Dict[str, LegalDocument]:
}
def generate_legal_documents(output_dir: str = "static/legal"):
"""Generate all legal documents as Markdown and HTML files."""
def generate_legal_documents(template_dir: str = "templates/legal"):
"""Generate all legal documents as Jinja2 templates."""
import os
os.makedirs(output_dir, exist_ok=True)
os.makedirs(template_dir, exist_ok=True)
documents = get_all_legal_documents()
for doc_name, doc in documents.items():
# Generate Markdown
md_filename = f"{doc_name}.md"
md_path = os.path.join(output_dir, md_filename)
with open(md_path, "w") as f:
f.write(doc.to_markdown())
# Generate HTML
html_filename = f"{doc_name}.html"
html_path = os.path.join(output_dir, html_filename)
html_path = os.path.join(template_dir, html_filename)
with open(html_path, "w") as f:
f.write(doc.to_html())
print(f"Generated {md_filename} and {html_filename}")
print(f"Generated {html_filename}")
if __name__ == "__main__":

View File

@ -4,7 +4,8 @@ import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI, Request, HTTPException, status
from fastapi.staticfiles import StaticFiles
from fastapi.responses import HTMLResponse, JSONResponse, Response
from fastapi.responses import HTMLResponse, JSONResponse, Response, RedirectResponse
from fastapi.templating import Jinja2Templates
from tortoise.contrib.fastapi import register_tortoise
from .settings import settings
from .routers import (
@ -101,6 +102,8 @@ app = FastAPI(
lifespan=lifespan,
)
templates = Jinja2Templates(directory="templates")
app.include_router(auth.router)
app.include_router(users.router)
app.include_router(folders.router)
@ -150,8 +153,41 @@ async def http_exception_handler(request: Request, exc: HTTPException):
)
@app.get("/", response_class=HTMLResponse) # Change response_class to HTMLResponse
async def read_root():
@app.get("/", response_class=HTMLResponse)
async def splash_page(request: Request):
return templates.TemplateResponse("splash.html", {"request": request})
@app.get("/features", response_class=HTMLResponse)
async def features_page(request: Request):
return templates.TemplateResponse("features.html", {"request": request})
@app.get("/pricing", response_class=HTMLResponse)
async def pricing_page(request: Request):
return templates.TemplateResponse("pricing.html", {"request": request})
@app.get("/support", response_class=HTMLResponse)
async def support_page(request: Request):
return templates.TemplateResponse("support.html", {"request": request})
@app.get("/legal/{document_name}", response_class=HTMLResponse)
async def legal_document(request: Request, document_name: str):
try:
return templates.TemplateResponse(f"legal/{document_name}.html", {"request": request})
except Exception:
raise HTTPException(status_code=404, detail="Legal document not found")
@app.get("/login")
async def login_redirect():
return RedirectResponse(url="/app", status_code=302)
@app.get("/app", response_class=HTMLResponse)
async def web_app():
with open("static/index.html", "r") as f:
return f.read()

View File

@ -32,6 +32,7 @@ ffmpeg-python = "*"
gunicorn = "*"
aiosmtplib = "*"
stripe = "*"
jinja2 = "*"
[tool.poetry.group.dev.dependencies]
black = "*"

View File

@ -118,3 +118,4 @@ websockets==15.0.1
yarl==1.22.0
zstandard==0.25.0
aiosmtplib==5.0.0
jinja2