fix(sitemap多了个斜杠导致Google Search Console无法自动编入索引)

This commit is contained in:
LooseLi
2025-03-20 11:50:12 +08:00
parent 61bdfef701
commit 86b59b6cfc
2 changed files with 10 additions and 1 deletions

View File

@@ -6,7 +6,11 @@ import { siteConfig } from './config'
* @param {*} param0 * @param {*} param0
*/ */
export async function generateSitemapXml({ allPages, NOTION_CONFIG }) { 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 = [ const urls = [
{ {
loc: `${link}`, loc: `${link}`,

View File

@@ -38,6 +38,11 @@ export const getServerSideProps = async ctx => {
} }
function generateLocalesSitemap(link, allPages, locale) { function generateLocalesSitemap(link, allPages, locale) {
// 确保链接不以斜杠结尾
if (link && link.endsWith('/')) {
link = link.slice(0, -1)
}
if (locale && locale.length > 0 && locale.indexOf('/') !== 0) { if (locale && locale.length > 0 && locale.indexOf('/') !== 0) {
locale = '/' + locale locale = '/' + locale
} }