feat(seo): 固化 m.tkmind.cn 百度验证、推送与 sitemap 去重
Memind CI / Test, build, and release guards (pull_request) Failing after 3m21s
Memind CI / Test, build, and release guards (pull_request) Failing after 3m21s
让 Portal 首页稳定注入站长验证 meta,并提供 sitemap 批量推送脚本与 LaunchAgent 安装入口;sitemap/llms 对同页优先保留 /u/ canonical URL。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
injectOgTags,
|
||||
renderWechatSharePreviewHtml,
|
||||
} from '../mindspace-og-tags.mjs';
|
||||
import { injectBaiduSiteVerification } from '../mindspace-baidu-site-verification.mjs';
|
||||
|
||||
export function attachPortalStaticDeliveryRoutes({
|
||||
app,
|
||||
@@ -285,6 +286,37 @@ export function attachPortalStaticDeliveryRoutes({
|
||||
},
|
||||
);
|
||||
|
||||
const sendPortalIndexHtml = (res) => {
|
||||
const indexPath = pathApi.join(h5Root, 'dist', 'index.html');
|
||||
const html = fsApi.readFileSync(indexPath, 'utf8');
|
||||
res
|
||||
.type('text/html; charset=utf-8')
|
||||
.set('Cache-Control', 'public, max-age=0')
|
||||
.send(injectBaiduSiteVerification(html));
|
||||
};
|
||||
|
||||
app.get(
|
||||
/^\/baidu_verify_[A-Za-z0-9-]+\.html$/,
|
||||
(req, res) => {
|
||||
const fileName = pathApi.basename(req.path);
|
||||
const filePath = pathApi.join(
|
||||
h5Root,
|
||||
'public',
|
||||
fileName,
|
||||
);
|
||||
if (!fsApi.existsSync(filePath)) {
|
||||
return res.status(404).end();
|
||||
}
|
||||
return res
|
||||
.type('text/html; charset=utf-8')
|
||||
.sendFile(filePath);
|
||||
},
|
||||
);
|
||||
|
||||
app.get('/', (_req, res) => {
|
||||
sendPortalIndexHtml(res);
|
||||
});
|
||||
|
||||
app.use('/auth', (_req, res) => {
|
||||
res.status(404).json({
|
||||
message:
|
||||
@@ -305,12 +337,6 @@ export function attachPortalStaticDeliveryRoutes({
|
||||
),
|
||||
);
|
||||
app.get('*', (_req, res) => {
|
||||
res.sendFile(
|
||||
pathApi.join(
|
||||
h5Root,
|
||||
'dist',
|
||||
'index.html',
|
||||
),
|
||||
);
|
||||
sendPortalIndexHtml(res);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -188,6 +188,11 @@ test('registers static delivery routes and middleware in legacy order', () => {
|
||||
'get',
|
||||
'/^\\/MP_verify_[A-Za-z0-9]+\\.txt$/',
|
||||
],
|
||||
[
|
||||
'get',
|
||||
'/^\\/baidu_verify_[A-Za-z0-9-]+\\.html$/',
|
||||
],
|
||||
['get', '/'],
|
||||
['use', '/auth'],
|
||||
['use', '/admin-api'],
|
||||
['use', null],
|
||||
@@ -394,6 +399,9 @@ test('preserves verification, API fallbacks, and SPA fallback', async () => {
|
||||
existsSync() {
|
||||
return false;
|
||||
},
|
||||
readFileSync() {
|
||||
return '<!doctype html><html><head><title>TKMind</title></head><body></body></html>';
|
||||
},
|
||||
},
|
||||
});
|
||||
const verification = missingSetup.routes.find(
|
||||
@@ -432,8 +440,12 @@ test('preserves verification, API fallbacks, and SPA fallback', async () => {
|
||||
'get',
|
||||
'*',
|
||||
);
|
||||
assert.match(
|
||||
spa.response.body,
|
||||
/baidu-site-verification/,
|
||||
);
|
||||
assert.equal(
|
||||
spa.response.sentFile,
|
||||
'/project/dist/index.html',
|
||||
spa.response.contentType,
|
||||
'text/html; charset=utf-8',
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user