Admin: add edit page (GET/POST), live preview; list shows Edit button; inject page title + watermark on public pages; clean header (only one logout); alignment via flex; add Dockerfile and docker-compose.yml; add gunicorn
This commit is contained in:
36
app.py
36
app.py
@@ -148,6 +148,26 @@ def create_app():
|
||||
base_url = request.host_url.rstrip("/")
|
||||
return render_template("admin.html", pages=pages, base_url=base_url)
|
||||
|
||||
@app.route("/admin/edit/<int:pid>", methods=["GET", "POST"])
|
||||
def admin_edit(pid: int):
|
||||
login_required()
|
||||
db = get_db()
|
||||
if request.method == "POST":
|
||||
title = request.form.get("title", "").strip()
|
||||
html = request.form.get("html", "").strip()
|
||||
if not html:
|
||||
flash("HTML не может быть пустым.", "error")
|
||||
else:
|
||||
db.execute("UPDATE pages SET title = ?, html = ? WHERE id = ?", (title, html, pid))
|
||||
db.commit()
|
||||
flash("Страница обновлена.", "success")
|
||||
return redirect(url_for("admin"))
|
||||
|
||||
row = db.execute("SELECT id, uuid, title, html, created_at FROM pages WHERE id = ?", (pid,)).fetchone()
|
||||
if row is None:
|
||||
abort(404)
|
||||
return render_template("edit.html", page=row)
|
||||
|
||||
@app.route("/admin/delete/<int:pid>", methods=["POST"])
|
||||
def admin_delete(pid: int):
|
||||
login_required()
|
||||
@@ -201,6 +221,22 @@ def create_app():
|
||||
html = html[:idx] + toolbar + html[idx:]
|
||||
else:
|
||||
html = html + toolbar
|
||||
# Ensure watermark exists on published pages (top-left)
|
||||
wm = (
|
||||
'<link rel="preconnect" href="https://fonts.googleapis.com">'
|
||||
'<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>'
|
||||
'<link href="https://fonts.googleapis.com/css2?family=Pacifico&display=swap" rel="stylesheet">'
|
||||
'<div style="position:fixed;top:16px;left:16px;z-index:2147483647;'
|
||||
"font-family:'Pacifico',cursive;letter-spacing:.2px;color:rgba(255,255,255,.92);"
|
||||
'text-shadow:0 2px 8px rgba(0,0,0,.35);pointer-events:none;user-select:none;">'
|
||||
'Made by Ruslan'</div>'
|
||||
)
|
||||
lower_all = html.lower()
|
||||
if "</body>" in lower_all:
|
||||
i2 = lower_all.rfind("</body>")
|
||||
html = html[:i2] + wm + html[i2:]
|
||||
else:
|
||||
html = html + wm
|
||||
return Response(html, mimetype="text/html; charset=utf-8")
|
||||
|
||||
# Optional: simple 404 page to keep things minimal
|
||||
|
||||
Reference in New Issue
Block a user