feat: SEO/GEO升级——SSR趋势列表/详情页、sitemap动态化(每日趋势URL)、llms.txt趋势说明;小程序sitemap.json搜索收录+趋势分享动态标题;看板移动端溢出修复
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
const express = require('express')
|
||||
const router = express.Router()
|
||||
const { Trend } = require('../models')
|
||||
|
||||
const esc = (x) => String(x == null ? '' : x).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
||||
|
||||
// 反代场景下优先取 x-forwarded 头,保证 sitemap/robots 里的站点地址正确
|
||||
function origin(req) {
|
||||
@@ -42,14 +45,22 @@ router.get('/robots.txt', (req, res) => {
|
||||
)
|
||||
})
|
||||
|
||||
router.get('/sitemap.xml', (req, res) => {
|
||||
router.get('/sitemap.xml', async (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']
|
||||
let trendUrls = ''
|
||||
try {
|
||||
const items = await Trend.find({}).sort({ newsDate: -1 }).limit(20).lean()
|
||||
trendUrls = items.map((t) => ` <url><loc>${o}/trends/${t._id}</loc><lastmod>${(t.newsDate || t.createdAt || new Date()).toISOString().slice(0, 10)}</lastmod><changefreq>daily</changefreq></url>`).join('\n')
|
||||
} catch (e) { /* 数据库不可用时仅输出基础页 */ }
|
||||
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>`
|
||||
[` <url><loc>${o}/</loc><lastmod>${today}</lastmod><changefreq>daily</changefreq></url>`,
|
||||
` <url><loc>${o}/trends</loc><lastmod>${today}</lastmod><changefreq>daily</changefreq></url>`,
|
||||
` <url><loc>${o}/about</loc><changefreq>monthly</changefreq></url>`,
|
||||
` <url><loc>${o}/llms.txt</loc><changefreq>weekly</changefreq></url>`].join('\n') +
|
||||
(trendUrls ? '\n' + trendUrls : '') +
|
||||
`\n</urlset>`
|
||||
)
|
||||
})
|
||||
|
||||
@@ -62,7 +73,7 @@ router.get('/llms.txt', (req, res) => {
|
||||
|
||||
## 核心内容
|
||||
- 五维度知识体系:AI起源、发展脉络、当前格局、学习工具、趋势跟踪
|
||||
- 每日AI趋势:定时采集行业热点(融资、产品发布、论文)
|
||||
- 每日AI趋势:每天 8:00/20:00 自动采集 Hacker News / arXiv 热点并中文归类(产品/论文/工具/公司/政策)
|
||||
- AI问答:基于知识库的智能问答
|
||||
|
||||
## 免费与付费
|
||||
@@ -70,7 +81,7 @@ router.get('/llms.txt', (req, res) => {
|
||||
|
||||
## 链接
|
||||
- [常见问题与产品说明](${o}/about)
|
||||
- [在线使用](${o}/)
|
||||
- [在线使用](${o}/)\n- [每日AI趋势速递](${o}/trends)
|
||||
`
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user