Set page title server-side for link preview compatibility

When a specific relation URL is loaded, fetch_relation_name() makes a
lightweight GET /relation/{id}.json call to get the name tag and pass
it to the template. The <title> and og:title are then set server-side,
so forum link previews and crawlers see the route name in the HTML
without executing JavaScript.

Errors are swallowed silently so a slow or failed API response just
falls back to the default title.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Edward Betts 2026-02-27 21:01:25 +00:00
parent 7a4cdfcca7
commit c2355a053d
3 changed files with 26 additions and 2 deletions

View file

@ -9,6 +9,7 @@ from osm_geojson.pt.core import (
OsmError,
build_route_coords,
fetch_relation_full,
fetch_relation_name,
fetch_route_master_routes,
fetch_sibling_routes,
make_geojson,
@ -96,7 +97,8 @@ def index() -> ResponseReturnValue:
@app.route("/<int:relation_id>")
def route_page(relation_id: int) -> ResponseReturnValue:
"""Render the page with a relation pre-loaded."""
return render_template("index.html", relation_id=relation_id, error=None)
name = fetch_relation_name(relation_id)
return render_template("index.html", relation_id=relation_id, error=None, route_name=name)
@app.route("/load", methods=["POST"])