From 86b59b6cfc569ea4f9d844712ded3f8304250da7 Mon Sep 17 00:00:00 2001 From: LooseLi <1329307562@qq.com> Date: Thu, 20 Mar 2025 11:50:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(sitemap=E5=A4=9A=E4=BA=86=E4=B8=AA=E6=96=9C?= =?UTF-8?q?=E6=9D=A0=E5=AF=BC=E8=87=B4Google=20Search=20Console=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=87=AA=E5=8A=A8=E7=BC=96=E5=85=A5=E7=B4=A2=E5=BC=95?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/sitemap.xml.js | 6 +++++- pages/sitemap.xml.js | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/sitemap.xml.js b/lib/sitemap.xml.js index c847e57d..1ff513f7 100644 --- a/lib/sitemap.xml.js +++ b/lib/sitemap.xml.js @@ -6,7 +6,11 @@ import { siteConfig } from './config' * @param {*} param0 */ export async function generateSitemapXml({ allPages, NOTION_CONFIG }) { - const link = siteConfig('LINK', BLOG.LINK, NOTION_CONFIG) + let link = siteConfig('LINK', BLOG.LINK, NOTION_CONFIG) + // 确保链接不以斜杠结尾 + if (link && link.endsWith('/')) { + link = link.slice(0, -1) + } const urls = [ { loc: `${link}`, diff --git a/pages/sitemap.xml.js b/pages/sitemap.xml.js index e6b33bb2..06c21f42 100644 --- a/pages/sitemap.xml.js +++ b/pages/sitemap.xml.js @@ -38,6 +38,11 @@ export const getServerSideProps = async ctx => { } function generateLocalesSitemap(link, allPages, locale) { + // 确保链接不以斜杠结尾 + if (link && link.endsWith('/')) { + link = link.slice(0, -1) + } + if (locale && locale.length > 0 && locale.indexOf('/') !== 0) { locale = '/' + locale }