Files
NotionNext/lib/robots.txt.js
2025-05-27 10:06:47 +08:00

26 lines
556 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import fs from 'fs'
export function generateRobotsTxt(props) {
const { siteInfo } = props
const LINK = siteInfo?.link
const content = `
# *
User-agent: *
Allow: /
# Host
Host: ${LINK}
# Sitemaps
Sitemap: ${LINK}/sitemap.xml
`
try {
fs.mkdirSync('./public', { recursive: true })
fs.writeFileSync('./public/robots.txt', content)
} catch (error) {
// 在vercel运行环境是只读的这里会报错
// 但在vercel编译阶段、或VPS等其他平台这行代码会成功执行
}
}