- 新建 scripts/baidu-push.mjs,推送 32 个页面 URL 到百度 - package.json 添加 pnpm baidu-push 命令 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
79 行
1.8 KiB
JavaScript
79 行
1.8 KiB
JavaScript
#!/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)
|
||
}
|