feat(seo): dynamic sitemap with all companies, events, forum topics, B2B — ~150+ URLs instead of 5
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-03-27 17:55:46 +01:00
parent a199f50d74
commit 2b82ad52d9

View File

@ -2311,39 +2311,74 @@ Sitemap: https://nordabiznes.pl/sitemap.xml
@bp.route('/sitemap.xml')
def sitemap_xml():
"""Sitemap XML for search engines."""
"""Dynamic sitemap XML with all public pages, companies, events, forum topics."""
from database import SessionLocal, Company, NordaEvent, ForumTopic
today = date.today().isoformat()
xml = f"""<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://nordabiznes.pl/</loc>
<lastmod>{today}</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://nordabiznes.pl/release-notes</loc>
<lastmod>{today}</lastmod>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://nordabiznes.pl/zainstaluj-aplikacje</loc>
<lastmod>{today}</lastmod>
<changefreq>monthly</changefreq>
<priority>0.4</priority>
</url>
<url>
<loc>https://nordabiznes.pl/polityka-prywatnosci</loc>
<lastmod>{today}</lastmod>
<changefreq>monthly</changefreq>
<priority>0.3</priority>
</url>
<url>
<loc>https://nordabiznes.pl/regulamin</loc>
<lastmod>{today}</lastmod>
<changefreq>monthly</changefreq>
<priority>0.3</priority>
</url>
</urlset>"""
return Response(xml, mimetype='application/xml')
base = 'https://nordabiznes.pl'
urls = []
# Static pages
urls.append(('/', today, 'daily', '1.0'))
urls.append(('/szukaj', today, 'daily', '0.8'))
urls.append(('/release-notes', today, 'weekly', '0.5'))
urls.append(('/zainstaluj-aplikacje', today, 'monthly', '0.4'))
urls.append(('/polityka-prywatnosci', today, 'monthly', '0.3'))
urls.append(('/regulamin', today, 'monthly', '0.3'))
db = SessionLocal()
try:
# Company pages — highest SEO value
companies = db.query(Company).filter(
Company.status == 'active'
).all()
for c in companies:
lastmod = today
urls.append((f'/company/{c.slug}', lastmod, 'weekly', '0.9'))
# Company list / catalog
urls.append(('/', today, 'daily', '1.0'))
# Calendar events (public, future + recent past)
events = db.query(NordaEvent).filter(
NordaEvent.event_date >= date.today() - timedelta(days=90)
).all()
for e in events:
lastmod = e.event_date.isoformat() if e.event_date else today
urls.append((f'/kalendarz/{e.id}', lastmod, 'weekly', '0.6'))
# Calendar index
urls.append(('/kalendarz/', today, 'weekly', '0.7'))
# Forum topics (public)
try:
topics = db.query(ForumTopic).filter(
ForumTopic.is_deleted == False # noqa: E712
).order_by(ForumTopic.created_at.desc()).limit(100).all()
for t in topics:
lastmod = t.last_reply_at.date().isoformat() if t.last_reply_at else (t.created_at.date().isoformat() if t.created_at else today)
urls.append((f'/forum/temat/{t.id}', lastmod, 'weekly', '0.6'))
urls.append(('/forum/', today, 'daily', '0.7'))
except Exception:
pass # Forum might not have topics
# B2B classifieds
urls.append(('/b2b', today, 'daily', '0.7'))
except Exception:
pass
finally:
db.close()
# Build XML
xml_parts = ['<?xml version="1.0" encoding="UTF-8"?>',
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">']
seen = set()
for loc, lastmod, freq, prio in urls:
if loc in seen:
continue
seen.add(loc)
xml_parts.append(f' <url><loc>{base}{loc}</loc><lastmod>{lastmod}</lastmod><changefreq>{freq}</changefreq><priority>{prio}</priority></url>')
xml_parts.append('</urlset>')
return Response('\n'.join(xml_parts), mimetype='application/xml')