Implement /robots.txt and /sitemap.xml. Update dev proxy to all-by-default.
This commit is contained in:
@@ -7,11 +7,10 @@ import vueDevTools from 'vite-plugin-vue-devtools'
|
|||||||
|
|
||||||
const backendUrl = process.env.PAGERITE_BACKEND_URL || 'http://localhost:3200'
|
const backendUrl = process.env.PAGERITE_BACKEND_URL || 'http://localhost:3200'
|
||||||
|
|
||||||
// Proxy content pages (/slug, /path/to/slug) to the FastAPI backend in dev.
|
// Proxy everything except Vite's own dev-time paths and the backend machinery
|
||||||
// Excludes Vite internals (/@..., /src, /node_modules, /__...) and the
|
// to the FastAPI backend in dev. /_api, /_f, /_themes and /_a are handled by
|
||||||
// backend's /_ prefix. /_api, /_f, /_themes and the /_a analytics ping are
|
// the fastapi-vue plugin, and /@..., /src, /node_modules, /__... stay with Vite.
|
||||||
// handled by the fastapi-vue plugin.
|
const CONTENT_PROXY = '^(?!/_|/@|/src|/node_modules|/__).*$'
|
||||||
const CONTENT_PROXY = '^\\/(?!_|@|src|node_modules|__)(?:[^./?]+(?:\\/[^./?]+)*)?(?:\\?.*)?$'
|
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
|||||||
+31
-9
@@ -1008,32 +1008,54 @@ async def front_page(request: Request) -> Response:
|
|||||||
async def sitemap(request: Request) -> Response:
|
async def sitemap(request: Request) -> Response:
|
||||||
"""Dynamically generate a sitemap of all published article pages."""
|
"""Dynamically generate a sitemap of all published article pages."""
|
||||||
base = str(request.base_url).rstrip("/")
|
base = str(request.base_url).rstrip("/")
|
||||||
entries: list[tuple[str, datetime]] = []
|
entries: list[tuple[str, datetime, int]] = []
|
||||||
|
|
||||||
def walk(nodes: dict[str, Node], prefix: str) -> None:
|
def walk(
|
||||||
|
nodes: dict[str, Node], prefix: str, parent_has_content: bool = True
|
||||||
|
) -> None:
|
||||||
|
first_content_slug = next(
|
||||||
|
(
|
||||||
|
slug
|
||||||
|
for slug, node in sorted_nodes(nodes)
|
||||||
|
if node.published and node.content is not None
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)
|
||||||
for slug, node in sorted_nodes(nodes):
|
for slug, node in sorted_nodes(nodes):
|
||||||
path = f"{prefix}/{slug}" if prefix else slug
|
path = f"{prefix}/{slug}" if prefix else slug
|
||||||
|
depth = path.count("/") if path else 0
|
||||||
|
if (
|
||||||
|
not parent_has_content
|
||||||
|
and slug == first_content_slug
|
||||||
|
and node.published
|
||||||
|
and node.content is not None
|
||||||
|
and depth > 0
|
||||||
|
):
|
||||||
|
depth -= 1
|
||||||
if node.published and node.content is not None:
|
if node.published and node.content is not None:
|
||||||
entries.append((path, node.modified))
|
entries.append((path, node.modified, depth))
|
||||||
walk(node.children, path)
|
if node.children:
|
||||||
|
walk(node.children, path, node.content is not None)
|
||||||
|
|
||||||
walk(data.menu, "")
|
walk(data.menu, "")
|
||||||
|
|
||||||
def priority(path: str) -> float:
|
def priority(depth: int) -> float:
|
||||||
return 1.0 if path == "" else max(0.1, 0.8 - path.count("/") * 0.2)
|
return max(0.1, 1.0 - depth * 0.2)
|
||||||
|
|
||||||
lines = [
|
lines = [
|
||||||
'<?xml version="1.0" encoding="UTF-8"?>',
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
||||||
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
||||||
]
|
]
|
||||||
for path, modified in entries:
|
for path, modified, depth in entries:
|
||||||
loc = xml_escape(f"{base}/{path}" if path else base)
|
loc = xml_escape(f"{base}/{path}" if path else base)
|
||||||
lastmod = modified.astimezone(UTC).isoformat()
|
lastmod = (
|
||||||
|
modified.astimezone(UTC).replace(microsecond=0).isoformat().replace("+00:00", "Z")
|
||||||
|
)
|
||||||
lines.append(
|
lines.append(
|
||||||
f" <url>"
|
f" <url>"
|
||||||
f"<loc>{loc}</loc>"
|
f"<loc>{loc}</loc>"
|
||||||
f"<lastmod>{lastmod}</lastmod>"
|
f"<lastmod>{lastmod}</lastmod>"
|
||||||
f"<priority>{priority(path):.1f}</priority>"
|
f"<priority>{priority(depth):.1f}</priority>"
|
||||||
f"</url>"
|
f"</url>"
|
||||||
)
|
)
|
||||||
lines.append("</urlset>")
|
lines.append("</urlset>")
|
||||||
|
|||||||
Reference in New Issue
Block a user