Skip to content

Commit

Permalink
ci: 自动推送百度收录
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfred-Skyblue committed May 2, 2024
1 parent 69687ca commit 87c2644
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/baidu-listing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Baidu URL Submission

on:
push:
branches:
- main
schedule:
- cron: '0 0 */2 * *' # Every two days at 00:00

jobs:
submit-urls:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8.x
- name: Set node version to LTS
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: https://registry.npmjs.org/
cache: pnpm
- name: Install and Build
run: |
pnpm install
pnpm docs:build
pnpm build:urls
- name: Submit urls.txt to Baidu
run: |
curl -H 'Content-Type:text/plain' --data-binary @urls.txt "http://data.zz.baidu.com/urls?site=https://vueuse-cn.netlify.app&token=5F5NfSLbPlGmP16k"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"license": "MIT",
"scripts": {
"build": "nr update && esno scripts/build-run.ts",
"build:urls": "esno scripts/build-urls.ts",
"build:redirects": "esno scripts/redirects.ts",
"build:rollup": "NODE_OPTIONS=\"--max-old-space-size=6144\" rollup --config=rollup.config.ts --configPlugin=rollup-plugin-esbuild",
"build:types": "tsc --emitDeclarationOnly && nr types:fix",
Expand Down
22 changes: 22 additions & 0 deletions scripts/build-urls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import fs from 'fs-extra'

// 站点地图文件路径
const sitemapFilePath = 'packages/.vitepress/dist/sitemap.xml'
// 要写入的文件路径
const outputFilePath = 'urls.txt'
// 收录
// 读取站点地图文件内容
fs.readFile(sitemapFilePath, 'utf8')
.then((data) => {
// 使用正则表达式匹配 URL
const urls = data.match(/<loc>(.*?)<\/loc>/g).map(url => url.replace('<loc>', '').replace('</loc>', ''))

// 将提取的 URL 写入文件
return fs.writeFile(outputFilePath, urls.join('\n'))
})
.then(() => {
console.log('URLs have been successfully written to', outputFilePath)
})
.catch((err) => {
console.error('Failed to read or write files:', err)
})

0 comments on commit 87c2644

Please sign in to comment.