feat: add canonical spot URLs
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { APIRoute } from "astro";
|
||||
import { api, type Activity, type DictionaryItem } from "../lib/api";
|
||||
import { api, spotPath, type Activity, type DictionaryItem } from "../lib/api";
|
||||
|
||||
const escapeXml = (value: string) => value.replace(/[<>&'\"]/g, character => ({ "<": "<", ">": ">", "&": "&", "'": "'", '"': """ })[character] ?? character);
|
||||
|
||||
@@ -11,7 +11,7 @@ export const GET: APIRoute = async ({ site }) => {
|
||||
paths.add("/fish"); paths.add("/waterbodies");
|
||||
fishes.forEach(item => paths.add(`/fish/${item.slug}`));
|
||||
waters.forEach(item => paths.add(`/waterbodies/${item.slug}`));
|
||||
activity.forEach(item => paths.add(`/spots/${item.spot_id}`));
|
||||
activity.forEach(item => paths.add(spotPath(item)));
|
||||
activity.forEach(item => paths.add(`/waterbodies/${item.waterbody_slug}/${item.fish_slug}`));
|
||||
} catch {
|
||||
// A temporary API outage must not make the static part of the sitemap unavailable.
|
||||
|
||||
@@ -5,14 +5,19 @@ import { activityLevel, api, kg, plural, type Activity, type Catch, type Spot }
|
||||
const { id } = Astro.params;
|
||||
let spot: Spot | null = null, catches: Catch[] = [], activity: Activity | null = null, unavailable = false;
|
||||
try {
|
||||
const [spotResult, catchResult, activityRows] = await Promise.all([api<Spot>(`/api/v1/spots/${id}`), api<Catch[]>(`/api/v1/spots/${id}/catches`), api<Activity[]>("/api/v1/activity?hours=24&limit=100")]);
|
||||
spot = spotResult; catches = catchResult; activity = activityRows.find(item => item.spot_id === id) ?? null;
|
||||
const readable = id?.match(/^(.+)-(-?\d+)x(-?\d+)$/);
|
||||
const spotResult = readable
|
||||
? await api<Spot>(`/api/v1/spots/resolve?waterbody=${encodeURIComponent(readable[1])}&x=${readable[2]}&y=${readable[3]}`)
|
||||
: await api<Spot>(`/api/v1/spots/${id}`);
|
||||
if (!readable) return Astro.redirect(`/spots/${spotResult.waterbody_slug}-${spotResult.x}x${spotResult.y}`, 301);
|
||||
const [catchResult, activityRows] = await Promise.all([api<Catch[]>(`/api/v1/spots/${spotResult.id}/catches`), api<Activity[]>("/api/v1/activity?hours=24&limit=100")]);
|
||||
spot = spotResult; catches = catchResult; activity = activityRows.find(item => item.spot_id === spotResult.id) ?? null;
|
||||
} catch { unavailable = true; }
|
||||
const level = activity ? activityLevel(activity.activity_score) : null;
|
||||
const spotDescription = spot ? `Свежие уловы и активность на точке ${spot.x}:${spot.y}, ${spot.waterbody}: рыба, вес, приманки и источники данных.` : "Данные точки ловли Russian Fishing 4.";
|
||||
const breadcrumbs = spot ? { "@context": "https://schema.org", "@type": "BreadcrumbList", itemListElement: [
|
||||
{ "@type": "ListItem", position: 1, name: "Сейчас клюёт", item: "https://rf4spotter.ru/" },
|
||||
{ "@type": "ListItem", position: 2, name: `${spot.waterbody} ${spot.x}:${spot.y}`, item: `https://rf4spotter.ru/spots/${id}` },
|
||||
{ "@type": "ListItem", position: 2, name: `${spot.waterbody} ${spot.x}:${spot.y}`, item: `https://rf4spotter.ru/spots/${spot.waterbody_slug}-${spot.x}x${spot.y}` },
|
||||
] } : null;
|
||||
---
|
||||
<Layout title={spot ? `Точка ${spot.x}:${spot.y}, ${spot.waterbody} — RF4 Spotter` : "Точка не найдена — RF4 Spotter"} description={spotDescription} noindex={!spot} structuredData={breadcrumbs}>
|
||||
|
||||
Reference in New Issue
Block a user