-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69687ca
commit 87c2644
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |