diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index c801c33f..224daa4f 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -406,7 +406,7 @@ {item?.text?.slice(0, 48) + "..."} ({ const website = "https://stocknear.com"; -// Helper function to create an XML URL element with optional SEO tags. +// Helper to ensure lastmod is in "YYYY-MM-DD" format +function formatLastmod(dateString) { + // Make sure dateString is valid and parseable + const date = new Date(dateString); + if (isNaN(date.getTime())) { + return ""; // or handle invalid date gracefully + } + // Return "YYYY-MM-DD" portion only (common for sitemaps) + return date.toISOString().split("T")[0]; +} + const createUrlElement = (loc, { lastmod, changefreq, priority } = {}) => { + let lastmodTag = ""; + if (lastmod) { + // Reformat the date to YYYY-MM-DD + const formattedDate = formatLastmod(lastmod); + if (formattedDate) { + lastmodTag = `${formattedDate}`; + } + } return ` ${loc} - ${lastmod ? `${lastmod}` : ""} + ${lastmodTag} ${changefreq ? `${changefreq}` : ""} ${priority ? `${priority}` : ""}