seo
This commit is contained in:
9 files changed
+189
-6
No files matched your search
+68
-2
@@ -1,8 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
from __future__ import annotations
|
||||
|
||||
from flask import Blueprint, flash, redirect, render_template, request, url_for
|
||||
from flask import current_app
|
||||
from datetime import date
|
||||
from xml.sax.saxutils import escape as xml_escape
|
||||
|
||||
from flask import Blueprint, Response, current_app, flash, redirect, render_template, request, url_for
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from boker.charts import cumulative_profit_series, player_session_series, session_breakdown_series
|
||||
from boker.config import ELIGIBLE_MIN_SESSIONS
|
||||
@@ -18,11 +21,74 @@ from boker.utils import session_label, session_sort_key
|
||||
public_bp = Blueprint("public", __name__)
|
||||
|
||||
|
||||
def _absolute_url(path: str) -> str:
|
||||
base_url = current_app.config.get("APP_BASE_URL", "https://myboker.org").rstrip("/")
|
||||
return f"{base_url}{path}"
|
||||
|
||||
|
||||
def _sitemap_url(path: str, priority: str, changefreq: str = "weekly") -> str:
|
||||
return (
|
||||
" <url>\n"
|
||||
f" <loc>{xml_escape(_absolute_url(path))}</loc>\n"
|
||||
f" <lastmod>{date.today().isoformat()}</lastmod>\n"
|
||||
f" <changefreq>{changefreq}</changefreq>\n"
|
||||
f" <priority>{priority}</priority>\n"
|
||||
" </url>"
|
||||
)
|
||||
|
||||
|
||||
@public_bp.get("/")
|
||||
def home():
|
||||
return render_template("landing.html")
|
||||
|
||||
|
||||
@public_bp.get("/robots.txt")
|
||||
def robots_txt():
|
||||
body = "\n".join(
|
||||
[
|
||||
"User-agent: *",
|
||||
"Allow: /",
|
||||
"Disallow: /internal/",
|
||||
"Disallow: /account/",
|
||||
"Sitemap: " + _absolute_url(url_for("public.sitemap_xml")),
|
||||
"",
|
||||
]
|
||||
)
|
||||
return Response(body, mimetype="text/plain")
|
||||
|
||||
|
||||
@public_bp.get("/sitemap.xml")
|
||||
def sitemap_xml():
|
||||
urls = [
|
||||
_sitemap_url(url_for("public.home"), "1.0", "weekly"),
|
||||
_sitemap_url(url_for("public.explore"), "0.8", "daily"),
|
||||
_sitemap_url(url_for("public.help"), "0.7", "monthly"),
|
||||
_sitemap_url(url_for("public.privacy"), "0.3", "yearly"),
|
||||
_sitemap_url(url_for("public.terms"), "0.3", "yearly"),
|
||||
]
|
||||
|
||||
from boker.db import database_extensions_available
|
||||
|
||||
if database_extensions_available():
|
||||
try:
|
||||
from boker.league_repositories import list_public_leagues
|
||||
|
||||
for league in list_public_leagues():
|
||||
urls.append(_sitemap_url(url_for("leagues.dashboard", league_ref=league.url_ref), "0.6", "weekly"))
|
||||
urls.append(_sitemap_url(url_for("leagues.leaderboard", league_ref=league.url_ref), "0.5", "weekly"))
|
||||
urls.append(_sitemap_url(url_for("leagues.sessions", league_ref=league.url_ref), "0.5", "weekly"))
|
||||
except SQLAlchemyError:
|
||||
current_app.logger.warning("Sitemap public league query failed", exc_info=True)
|
||||
|
||||
body = (
|
||||
'<?xml version="1.0" encoding="UTF-8"?>\n'
|
||||
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n'
|
||||
+ "\n".join(urls)
|
||||
+ "\n</urlset>\n"
|
||||
)
|
||||
return Response(body, mimetype="application/xml")
|
||||
|
||||
|
||||
@public_bp.get("/help")
|
||||
def help():
|
||||
return render_template("support.html")
|
||||
|
||||
Reference in new issue
Block a user