mirror of
https://github.com/KazooTTT/kazoottt-blog.git
synced 2025-06-20 01:11:20 +08:00
fix: error sitemap path
This commit is contained in:
@ -32,7 +32,10 @@
|
||||
"astro": "^4.4.15",
|
||||
"astro-expressive-code": "^0.33.5",
|
||||
"astro-icon": "^1.1.0",
|
||||
"axios": "^1.7.7",
|
||||
"clsx": "^2.1.0",
|
||||
"fast-xml-parser": "^4.5.0",
|
||||
"googleapis": "^144.0.0",
|
||||
"gray-matter": "^4.0.3",
|
||||
"mdast-util-to-string": "^4.0.0",
|
||||
"react": "^18.3.1",
|
||||
|
10713
pnpm-lock.yaml
generated
10713
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -8,7 +8,7 @@ const QUOTA = 100
|
||||
|
||||
async function parseSitemap(site) {
|
||||
try {
|
||||
const sitemapUrl = `${site}/sitemap.xml`
|
||||
const sitemapUrl = `${site}/sitemap-index.xml`
|
||||
const response = await axios.get(sitemapUrl, {
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
})
|
||||
@ -18,7 +18,28 @@ async function parseSitemap(site) {
|
||||
|
||||
// Handle different sitemap formats
|
||||
let urls = []
|
||||
if (result.urlset && result.urlset.url) {
|
||||
if (result.sitemapindex && result.sitemapindex.sitemap) {
|
||||
// Handle sitemap index format
|
||||
const sitemaps = Array.isArray(result.sitemapindex.sitemap)
|
||||
? result.sitemapindex.sitemap
|
||||
: [result.sitemapindex.sitemap]
|
||||
|
||||
// Get URLs from each sitemap
|
||||
for (const sitemap of sitemaps) {
|
||||
const sitemapResponse = await axios.get(sitemap.loc, {
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
})
|
||||
const sitemapResult = parser.parse(sitemapResponse.data)
|
||||
|
||||
if (sitemapResult.urlset && sitemapResult.urlset.url) {
|
||||
const sitemapUrls = Array.isArray(sitemapResult.urlset.url)
|
||||
? sitemapResult.urlset.url.map((u) => u.loc)
|
||||
: [sitemapResult.urlset.url.loc]
|
||||
urls.push(...sitemapUrls)
|
||||
}
|
||||
}
|
||||
} else if (result.urlset && result.urlset.url) {
|
||||
// Handle direct urlset format
|
||||
urls = Array.isArray(result.urlset.url)
|
||||
? result.urlset.url.map((u) => u.loc)
|
||||
: [result.urlset.url.loc]
|
||||
|
@ -82,7 +82,7 @@ const socialImageURL = new URL(ogImage ? ogImage : '/social-card.png', Astro.url
|
||||
<meta content={socialImageURL} property='twitter:image' />
|
||||
|
||||
{/* Sitemap */}
|
||||
<link href='/sitemap.xml' rel='sitemap' />
|
||||
<link href='/sitemap-index.xml' rel='sitemap' />
|
||||
|
||||
{/* RSS auto-discovery */}
|
||||
<link href='/rss.xml' rel='alternate' title={siteConfig.title} type='application/rss+xml' />
|
||||
|
@ -8,7 +8,7 @@ Allow: /
|
||||
HOST: ${siteConfig.site}
|
||||
|
||||
# Sitemaps
|
||||
Sitemap: ${siteConfig.site}/sitemap.xml
|
||||
Sitemap: ${siteConfig.site}/sitemap-index.xml
|
||||
|
||||
# Disallow system and error pages
|
||||
Disallow: /api/
|
||||
|
@ -1,70 +0,0 @@
|
||||
import rss from '@astrojs/rss'
|
||||
import { siteConfig } from '@/site-config'
|
||||
import { getAllSortedPosts } from '@/utils'
|
||||
|
||||
export const GET = async () => {
|
||||
const posts = await getAllSortedPosts()
|
||||
|
||||
const items = await Promise.all(
|
||||
posts.map(async (post) => {
|
||||
const entry = post
|
||||
const body = entry.body
|
||||
|
||||
return {
|
||||
title: post.data.title ?? '',
|
||||
description: JSON.stringify(body),
|
||||
pubDate: post.data.date,
|
||||
link: `/blog/${post.slug}`
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
const link = import.meta.env.SITE
|
||||
const locale = ''
|
||||
|
||||
const defaultFields = [
|
||||
{
|
||||
loc: `${link}${locale}`,
|
||||
lastmod: new Date().toISOString().split('T')[0],
|
||||
changefreq: 'daily',
|
||||
priority: '1.0'
|
||||
},
|
||||
{
|
||||
loc: `${link}${locale}/blog`,
|
||||
lastmod: new Date().toISOString().split('T')[0],
|
||||
changefreq: 'daily',
|
||||
priority: '0.8'
|
||||
},
|
||||
{
|
||||
loc: `${link}${locale}/categories`,
|
||||
lastmod: new Date().toISOString().split('T')[0],
|
||||
changefreq: 'daily',
|
||||
priority: '0.7'
|
||||
},
|
||||
{
|
||||
loc: `${link}${locale}/tags`,
|
||||
lastmod: new Date().toISOString().split('T')[0],
|
||||
changefreq: 'daily',
|
||||
priority: '0.7'
|
||||
},
|
||||
{
|
||||
loc: `${link}${locale}/tools`,
|
||||
lastmod: new Date().toISOString().split('T')[0],
|
||||
changefreq: 'weekly',
|
||||
priority: '0.6'
|
||||
},
|
||||
{
|
||||
loc: `${link}${locale}/rss.xml`,
|
||||
lastmod: new Date().toISOString().split('T')[0],
|
||||
changefreq: 'daily',
|
||||
priority: '0.4'
|
||||
}
|
||||
]
|
||||
|
||||
return rss({
|
||||
title: siteConfig.title,
|
||||
description: siteConfig.description + '\nfeedId:76245438397618182+userId:62156866798228480',
|
||||
site: import.meta.env.SITE,
|
||||
items: [...defaultFields, ...items]
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user