feat: dimension SEO/GEO——robots/sitemap/llms.txt/about 站长验证文件 + 体验优化
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
import express from 'express'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
const router = express.Router()
|
||||
|
||||
const SITE = process.env.SITE_URL || ''
|
||||
const origin = (req) => (SITE ? SITE.replace(/\/$/, '') : `${req.protocol}://${req.get('host')}`)
|
||||
|
||||
const DESC =
|
||||
'宇之然AI维度:从五个维度(AI起源、发展、当前格局、学习工具、趋势跟踪)系统理解人工智能的知识探索社区。每日更新AI行业趋势与热点,支持问答、收藏与学习进度跟踪。'
|
||||
|
||||
const FAQ = [
|
||||
['宇之然AI维度是什么?', '一个AI知识探索社区:从五个维度系统梳理人工智能的起源、发展、当前格局、学习工具与行业趋势,并每日更新AI热点。'],
|
||||
['适合谁使用?', 'AI 零基础入门者、关注AI行业动态的从业者、需要结构化AI知识体系的学生与内容创作者。'],
|
||||
['内容如何保持新鲜?', '内置AI趋势定时采集,每天两次更新行业热点;支持问答与知识扩展。'],
|
||||
['免费使用吗?', '基础浏览与问答免费,注册登录后可使用收藏与学习进度等完整功能。'],
|
||||
['有微信小程序吗?', '有。微信搜索"AI维度"即可使用,数据与网页端同步。'],
|
||||
]
|
||||
|
||||
router.get('/robots.txt', (req, res) => {
|
||||
const o = origin(req)
|
||||
res.type('text/plain').send(
|
||||
[
|
||||
'User-agent: *',
|
||||
'Allow: /',
|
||||
'Disallow: /api/',
|
||||
'',
|
||||
'User-agent: GPTBot',
|
||||
'Allow: /',
|
||||
'User-agent: ClaudeBot',
|
||||
'Allow: /',
|
||||
'User-agent: PerplexityBot',
|
||||
'Allow: /',
|
||||
'',
|
||||
`Sitemap: ${o}/sitemap.xml`,
|
||||
'',
|
||||
].join('\n')
|
||||
)
|
||||
})
|
||||
|
||||
router.get('/sitemap.xml', (req, res) => {
|
||||
const o = origin(req)
|
||||
const today = new Date().toISOString().slice(0, 10)
|
||||
const urls = ['/', '/pages/trend/trend', '/pages/chat/chat', '/pages/dimension/dimension']
|
||||
res.type('application/xml').send(
|
||||
`<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n` +
|
||||
urls.map((u) => ` <url><loc>${o}${u}</loc><lastmod>${today}</lastmod></url>`).join('\n') +
|
||||
`\n</urlset>`
|
||||
)
|
||||
})
|
||||
|
||||
router.get('/llms.txt', (req, res) => {
|
||||
const o = origin(req)
|
||||
res.type('text/markdown').send(
|
||||
`# 宇之然AI维度
|
||||
|
||||
> ${DESC}
|
||||
|
||||
## 核心内容
|
||||
- 五维度知识体系:AI起源、发展脉络、当前格局、学习工具、趋势跟踪
|
||||
- 每日AI趋势:定时采集行业热点(融资、产品发布、论文)
|
||||
- AI问答:基于知识库的智能问答
|
||||
|
||||
## 免费与付费
|
||||
- 浏览与基础问答免费;注册登录解锁收藏与学习进度
|
||||
|
||||
## 链接
|
||||
- [常见问题与产品说明](${o}/about)
|
||||
- [在线使用](${o}/)
|
||||
`
|
||||
)
|
||||
})
|
||||
|
||||
router.get('/about', (req, res) => {
|
||||
const o = origin(req)
|
||||
const faqHtml = FAQ.map(([q, a]) => `<div class="faq"><h3>${q}</h3><p>${a}</p></div>`).join('')
|
||||
const faqLd = JSON.stringify({
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'FAQPage',
|
||||
mainEntity: FAQ.map(([q, a]) => ({ '@type': 'Question', name: q, acceptedAnswer: { '@type': 'Answer', text: a } })),
|
||||
})
|
||||
res.type('html').send(`<!doctype html>
|
||||
<html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>宇之然AI维度 - 产品介绍与常见问题 | AI知识探索社区</title>
|
||||
<meta name="description" content="${DESC} 产品介绍与常见问题。">
|
||||
<link rel="canonical" href="${o}/about">
|
||||
<script type="application/ld+json">${faqLd}</script>
|
||||
<style>body{font-family:-apple-system,'PingFang SC',sans-serif;color:#1f2333;max-width:720px;margin:0 auto;padding:32px 20px;line-height:1.8}h1{font-size:24px}h2{margin-top:28px}h3{font-size:16px;margin:12px 0 4px}.badge{display:inline-block;background:#6366f1;color:#fff;border-radius:999px;padding:4px 14px;font-size:13px}</style>
|
||||
</head><body>
|
||||
<span class="badge">AI 知识探索社区</span>
|
||||
<h1>宇之然AI维度</h1>
|
||||
<p>${DESC}</p>
|
||||
<h2>五个维度</h2><ol><li>AI 起源与历史</li><li>技术发展脉络</li><li>当前行业格局</li><li>学习工具与资源</li><li>趋势跟踪</li></ol>
|
||||
<h2>常见问题</h2>${faqHtml}
|
||||
<p style="color:#999;font-size:12px;margin-top:24px">© ${new Date().getFullYear()} 宇之然 · 微信小程序搜索"AI维度"</p>
|
||||
</body></html>`)
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user