hulai-website/scripts/baidu-push.mjs
Mimingguang b82712deed feat: 添加百度主动推送脚本,加速 SEO 收录
- 新建 scripts/baidu-push.mjs,推送 32 个页面 URL 到百度
- package.json 添加 pnpm baidu-push 命令

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 11:14:50 +08:00

79 行
1.8 KiB
JavaScript

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

#!/usr/bin/env node
/**
* 百度主动推送脚本
* 用法node scripts/baidu-push.mjs
*
* 将站点所有页面 URL 推送给百度,加速收录。
* 建议每次部署后或内容更新后执行一次。
*/
const SITE = 'https://www.1814.love'
const TOKEN = process.env.BAIDU_PUSH_TOKEN || 'xpS22S0bG8VkQ97m'
const API = `http://data.zz.baidu.com/urls?site=${SITE}&token=${TOKEN}`
// 所有需要推送的页面
const urls = [
'/',
'/products',
'/products/v9-5d4n-forest',
'/products/v9-5d4n-prairie',
'/products/v9-6d5n-family',
'/products/v9-6d5n-explore',
'/products/v9-7d6n-family',
'/products/v9-7d6n-wild',
'/products/autumn',
'/products/winter',
'/summer-camp',
'/winter-camp',
'/courses',
'/pricing',
'/selector',
'/faq',
'/reviews',
'/blog',
'/news',
'/stories',
'/gallery',
'/destinations',
'/calendar',
'/guides',
'/guide-custom',
'/about',
'/contact',
'/customize',
'/qualifications',
'/partners',
'/xiaohongshu',
'/youji',
]
const body = urls.map(u => `${SITE}${u}`).join('\n')
console.log(`推送 ${urls.length} 个 URL 到百度...`)
try {
const res = await fetch(API, {
method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body,
})
const data = await res.json()
if (data.success) {
console.log(`✅ 成功推送 ${data.success} 个,今日剩余配额 ${data.remain}`)
} else if (data.error) {
console.error(`❌ 推送失败: ${data.message} (${data.error})`)
} else {
console.log('响应:', JSON.stringify(data, null, 2))
}
if (data.not_same_site?.length) {
console.log('⚠️ 以下 URL 不属于该站点:', data.not_same_site)
}
if (data.not_valid?.length) {
console.log('⚠️ 以下 URL 格式不合法:', data.not_valid)
}
} catch (err) {
console.error('❌ 请求失败:', err.message)
}