feat: add sitemap.xml (#33)

Co-authored-by: saica.go <zephyird@gmail.com>
This commit is contained in:
CorrectRoad 2024-04-22 23:48:31 +08:00 committed by GitHub
parent e80999669a
commit 91773fc520
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 49 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import remarkMath from "remark-math"
import { remarkReadingTime } from "./src/plugins/remark-reading-time.mjs" import { remarkReadingTime } from "./src/plugins/remark-reading-time.mjs"
import svelte from "@astrojs/svelte" import svelte from "@astrojs/svelte"
import swup from '@swup/astro'; import swup from '@swup/astro';
import sitemap from '@astrojs/sitemap';
const oklchToHex = (str) => { const oklchToHex = (str) => {
const DEFAULT_HUE = 250 const DEFAULT_HUE = 250
@ -49,6 +50,7 @@ export default defineConfig({
Image: false, Image: false,
}), }),
svelte(), svelte(),
sitemap(),
], ],
markdown: { markdown: {
remarkPlugins: [remarkMath, remarkReadingTime], remarkPlugins: [remarkMath, remarkReadingTime],

View File

@ -14,6 +14,7 @@
}, },
"dependencies": { "dependencies": {
"@astrojs/check": "^0.5.9", "@astrojs/check": "^0.5.9",
"@astrojs/sitemap": "^3.1.2",
"@astrojs/rss": "^4.0.5", "@astrojs/rss": "^4.0.5",
"@astrojs/svelte": "^5.2.0", "@astrojs/svelte": "^5.2.0",
"@astrojs/tailwind": "^5.1.0", "@astrojs/tailwind": "^5.1.0",

View File

@ -8,6 +8,9 @@ dependencies:
'@astrojs/check': '@astrojs/check':
specifier: ^0.5.9 specifier: ^0.5.9
version: 0.5.9(typescript@5.4.2) version: 0.5.9(typescript@5.4.2)
'@astrojs/sitemap':
specifier: ^3.1.2
version: 3.1.2
'@astrojs/rss': '@astrojs/rss':
specifier: ^4.0.5 specifier: ^4.0.5
version: 4.0.5 version: 4.0.5
@ -228,6 +231,12 @@ packages:
prismjs: 1.29.0 prismjs: 1.29.0
dev: false dev: false
/@astrojs/sitemap@3.1.2:
resolution: {integrity: sha512-FxOJldIl5ltZ5CNjocQxHkAO9orwHBjqtaU28o4smobp9vowS0nbGp+I9CrPxkzWdl1crSDm9vjL9tnvG1DSug==}
dependencies:
sitemap: 7.1.1
zod: 3.22.4
/@astrojs/rss@4.0.5: /@astrojs/rss@4.0.5:
resolution: {integrity: sha512-IyJVL6z09AQtxbgLaAwebT3T5YKe4oTHDesqydJv1KLHw+zEzzMCFuuNsEyxjiqu7df9+DDCpDXLj/WRiEUXvw==} resolution: {integrity: sha512-IyJVL6z09AQtxbgLaAwebT3T5YKe4oTHDesqydJv1KLHw+zEzzMCFuuNsEyxjiqu7df9+DDCpDXLj/WRiEUXvw==}
dependencies: dependencies:
@ -2876,6 +2885,10 @@ packages:
'@types/unist': 2.0.10 '@types/unist': 2.0.10
dev: false dev: false
/@types/node@17.0.45:
resolution: {integrity: sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==}
dev: false
/@types/node@20.11.28: /@types/node@20.11.28:
resolution: {integrity: sha512-M/GPWVS2wLkSkNHVeLkrF2fD5Lx5UC4PxA0uZcKc6QqbIQUJyW1jVjueJYi1z8n0I5PxYrtpnPnWglE+y9A0KA==} resolution: {integrity: sha512-M/GPWVS2wLkSkNHVeLkrF2fD5Lx5UC4PxA0uZcKc6QqbIQUJyW1jVjueJYi1z8n0I5PxYrtpnPnWglE+y9A0KA==}
dependencies: dependencies:
@ -2892,6 +2905,12 @@ packages:
'@types/node': 20.11.28 '@types/node': 20.11.28
dev: false dev: false
/@types/sax@1.2.7:
resolution: {integrity: sha512-rO73L89PJxeYM3s3pPPjiPgVVcymqU490g0YO5n5By0k2Erzj6tay/4lr1CHAAU4JyOWd1rpQ8bCf6cZfHU96A==}
dependencies:
'@types/node': 20.11.28
dev: false
/@types/sanitize-html@2.11.0: /@types/sanitize-html@2.11.0:
resolution: {integrity: sha512-7oxPGNQHXLHE48r/r/qjn7q0hlrs3kL7oZnGj0Wf/h9tj/6ibFyRkNbsDxaBBZ4XUZ0Dx5LGCyDJ04ytSofacQ==} resolution: {integrity: sha512-7oxPGNQHXLHE48r/r/qjn7q0hlrs3kL7oZnGj0Wf/h9tj/6ibFyRkNbsDxaBBZ4XUZ0Dx5LGCyDJ04ytSofacQ==}
dependencies: dependencies:
@ -7840,6 +7859,17 @@ packages:
resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==}
dev: false dev: false
/sitemap@7.1.1:
resolution: {integrity: sha512-mK3aFtjz4VdJN0igpIJrinf3EO8U8mxOPsTBzSsy06UtjZQJ3YY3o3Xa7zSc5nMqcMrRwlChHZ18Kxg0caiPBg==}
engines: {node: '>=12.0.0', npm: '>=5.6.0'}
hasBin: true
dependencies:
'@types/node': 17.0.45
'@types/sax': 1.2.7
arg: 5.0.2
sax: 1.3.0
dev: false
/slash@3.0.0: /slash@3.0.0:
resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==}
engines: {node: '>=8'} engines: {node: '>=8'}

16
src/pages/robots.txt.ts Normal file
View File

@ -0,0 +1,16 @@
import type { APIRoute } from 'astro';
const robotsTxt = `
User-agent: *
Allow: /
Sitemap: ${new URL('sitemap-index.xml', import.meta.env.SITE).href}
`.trim();
export const GET: APIRoute = () => {
return new Response(robotsTxt, {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
},
});
};