diff --git a/web/src/pages/planner.astro b/web/src/pages/planner.astro index 0432e4a0..87462b51 100644 --- a/web/src/pages/planner.astro +++ b/web/src/pages/planner.astro @@ -51,6 +51,26 @@ import Container from '../components/Container.astro'; const status = document.getElementById('planner-status'); const result = document.getElementById('planner-result'); + const escapeHtml = (value) => String(value ?? '') + .replaceAll('&', '&') + .replaceAll('<', '<') + .replaceAll('>', '>') + .replaceAll('"', '"') + .replaceAll("'", '''); + + const buildMapSrc = (itinerary, requestCity) => { + const placeQuery = (itinerary.stops ?? []) + .slice(0, 5) + .map((stop) => stop.address || stop.placeTitle) + .filter(Boolean) + .join(', '); + + const searchQuery = [placeQuery, itinerary.city, requestCity].filter(Boolean).join(', '); + if (!searchQuery) return ''; + + return `https://www.google.com/maps?q=${encodeURIComponent(searchQuery)}&output=embed`; + }; + form?.addEventListener('submit', async (event) => { event.preventDefault(); if (!status || !result || !form) return; @@ -72,12 +92,17 @@ import Container from '../components/Container.astro'; if (!response.ok) throw new Error('Generation failed'); const itinerary = await response.json(); status.textContent = `Generated ${itinerary.stops?.length ?? 0} stops.`; + const mapSrc = buildMapSrc(itinerary, payload.city); + const mapMarkup = mapSrc + ? `

Map preview

` + : ''; result.innerHTML = ` -

${itinerary.title}

-

${itinerary.summary}

+

${escapeHtml(itinerary.title)}

+

${escapeHtml(itinerary.summary)}

    - ${(itinerary.stops ?? []).map((stop) => `
  1. ${stop.sequence}. ${stop.placeTitle}
    ${stop.reasonIncluded}
  2. `).join('')} + ${(itinerary.stops ?? []).map((stop) => `
  3. ${escapeHtml(stop.sequence)}. ${escapeHtml(stop.placeTitle)}
    ${escapeHtml(stop.reasonIncluded)}
  4. `).join('')}
+ ${mapMarkup} `; } catch (error) { status.textContent = 'Could not generate itinerary. Try again with broader filters.';