feat: vendor pages /vendor/<slug> with SEO, sitemap updated, links from main

This commit is contained in:
2026-05-15 15:54:39 +03:00
parent 1a8dd74be6
commit 7c0c2ea14a
5 changed files with 264 additions and 5 deletions
+1 -1
View File
@@ -411,7 +411,7 @@ def fetch_scope_data(scope: str) -> dict:
conn = get_db()
vendors = [dict(r) for r in conn.execute(
f"SELECT id, name, COALESCE(logo,'') as logo, COALESCE(description,'') as description, "
f"COALESCE(website,'') as website, COALESCE(mont_page,'') as mont_page "
f"COALESCE(website,'') as website, COALESCE(mont_page,'') as mont_page, COALESCE(slug,'') as slug "
f"FROM {tables['vendors']} ORDER BY lower(name)"
)]
categories = [dict(r) for r in conn.execute(f"SELECT id, name FROM {tables['categories']} ORDER BY lower(name)")]
+56 -2
View File
@@ -582,15 +582,69 @@ def sitemap_xml():
from flask import Response
proto = request.headers.get("X-Forwarded-Proto", "https")
base = f"{proto}://{request.host}"
conn = get_db()
slugs = [r[0] for r in conn.execute(
"SELECT slug FROM vendors WHERE slug IS NOT NULL "
"UNION SELECT slug FROM ib_vendors WHERE slug IS NOT NULL"
)]
conn.close()
urls = [f' <url><loc>{base}/</loc><changefreq>weekly</changefreq><priority>1.0</priority></url>']
for slug in slugs:
urls.append(f' <url><loc>{base}/vendor/{slug}</loc><changefreq>monthly</changefreq><priority>0.7</priority></url>')
body = (
'<?xml version="1.0" encoding="UTF-8"?>\n'
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n'
f' <url><loc>{base}/</loc><changefreq>weekly</changefreq><priority>1.0</priority></url>\n'
'</urlset>'
+ '\n'.join(urls) + '\n</urlset>'
)
return Response(body, mimetype="application/xml")
@bp.get("/vendor/<slug>")
def vendor_page(slug: str):
from flask import abort
conn = get_db()
# Search in both tables, prefer infra
vendor = conn.execute(
"SELECT id, name, COALESCE(logo,'') as logo, COALESCE(description,'') as description, "
"COALESCE(website,'') as website, COALESCE(mont_page,'') as mont_page, 'infra' as scope "
"FROM vendors WHERE slug = ?", (slug,)
).fetchone()
if not vendor:
vendor = conn.execute(
"SELECT id, name, COALESCE(logo,'') as logo, COALESCE(description,'') as description, "
"COALESCE(website,'') as website, COALESCE(mont_page,'') as mont_page, 'ib' as scope "
"FROM ib_vendors WHERE slug = ?", (slug,)
).fetchone()
if not vendor:
conn.close()
abort(404)
vendor = dict(vendor)
tables = scope_tables(vendor['scope'])
products = [dict(r) for r in conn.execute(
f"SELECT name, COALESCE(url,'') as url FROM {tables['products']} "
f"WHERE vendor_id = ? ORDER BY lower(name)", (vendor['id'],)
)]
categories = [r[0] for r in conn.execute(
f"SELECT c.name FROM {tables['categories']} c "
f"JOIN {tables['vendor_categories']} vc ON vc.category_id = c.id "
f"WHERE vc.vendor_id = ? ORDER BY lower(c.name)", (vendor['id'],)
)]
conn.close()
proto = request.headers.get("X-Forwarded-Proto", "https")
base_url = f"{proto}://{request.host}"
canonical_url = f"{base_url}/vendor/{slug}"
return render_template("vendor.html",
vendor=vendor,
products=products,
categories=categories,
canonical_url=canonical_url,
base_url=base_url,
)
@bp.get("/api/data")
def api_data():
scope = (request.args.get("scope") or "infra").strip().lower()