From 939a77ecab36f2f51d2c4220c142d2bb84bddccb Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 18 Mar 2024 19:36:56 +0800 Subject: [PATCH] chore: commit docs to docs repo --- .github/workflows/build-assets.yml | 23 +++++ lib/routes/1point3acres/offer.ts | 2 +- lib/routes/bilibili/dynamic.ts | 2 +- lib/routes/bilibili/video.ts | 2 +- lib/routes/dnaindia/category.ts | 2 +- lib/routes/finology/tag.ts | 2 +- lib/routes/javbus/namespace.ts | 2 +- lib/routes/notion/namespace.ts | 2 +- lib/routes/vimeo/usr-videos.ts | 2 +- lib/routes/xsijishe/forum.ts | 2 +- scripts/workflow/build-routes.ts | 77 ++++++++-------- scripts/workflow/data.ts | 140 +++++++++++++++++++++++++++++ 12 files changed, 213 insertions(+), 45 deletions(-) create mode 100644 scripts/workflow/data.ts diff --git a/.github/workflows/build-assets.yml b/.github/workflows/build-assets.yml index af1be6004..aa720b4c7 100644 --- a/.github/workflows/build-assets.yml +++ b/.github/workflows/build-assets.yml @@ -1,6 +1,7 @@ name: Build assets on: + workflow_dispatch: push: branches: - master @@ -46,3 +47,25 @@ jobs: publish_dir: ./assets user_name: 'github-actions[bot]' user_email: '41898282+github-actions[bot]@users.noreply.github.com' + - name: Pushes to docs repository - en + uses: cpina/github-action-push-to-another-repository@main + env: + SSH_DEPLOY_KEY: ${{ secrets.DOCS_SSH_DEPLOY_KEY }} + with: + source-directory: './assets/build/docs/en' + target-directory: './src/routes' + destination-github-username: 'RSSNext' + destination-repository-name: 'rsshub-docs' + user-email: '41898282+github-actions[bot]@users.noreply.github.com' + target-branch: 'github-actions[bot]' + - name: Pushes to docs repository - zh + uses: cpina/github-action-push-to-another-repository@main + env: + SSH_DEPLOY_KEY: ${{ secrets.DOCS_SSH_DEPLOY_KEY }} + with: + source-directory: './assets/build/docs/zh' + target-directory: './src/zh/routes' + destination-github-username: 'RSSNext' + destination-repository-name: 'rsshub-docs' + user-email: '41898282+github-actions[bot]@users.noreply.github.com' + target-branch: 'github-actions[bot]' diff --git a/lib/routes/1point3acres/offer.ts b/lib/routes/1point3acres/offer.ts index 82fd86a03..5f634093a 100644 --- a/lib/routes/1point3acres/offer.ts +++ b/lib/routes/1point3acres/offer.ts @@ -30,7 +30,7 @@ export const route: Route = { maintainers: ['EthanWng97'], handler, url: 'offer.1point3acres.com/', - description: `:::tip[三个 id 获取方式] + description: `:::tip 三个 id 获取方式 1. 打开 [https://offer.1point3acres.com](https://offer.1point3acres.com) 2. 打开控制台 3. 切换到 Network 面板 diff --git a/lib/routes/bilibili/dynamic.ts b/lib/routes/bilibili/dynamic.ts index 949ba45ee..0420620a6 100644 --- a/lib/routes/bilibili/dynamic.ts +++ b/lib/routes/bilibili/dynamic.ts @@ -99,7 +99,7 @@ export const route: Route = { 用例:\`/bilibili/user/dynamic/2267573/showEmoji=1&disableEmbed=1&useAvid=1\` - :::tip[动态的专栏显示全文] + :::tip 动态的专栏显示全文 动态的专栏显示全文请使用通用参数里的 \`mode=fulltext\` 举例: bilibili 专栏全文输出 /bilibili/user/dynamic/2267573/?mode=fulltext diff --git a/lib/routes/bilibili/video.ts b/lib/routes/bilibili/video.ts index 188a2cd5d..8c8a7d5ed 100644 --- a/lib/routes/bilibili/video.ts +++ b/lib/routes/bilibili/video.ts @@ -26,7 +26,7 @@ export const route: Route = { name: 'UP 主投稿', maintainers: ['DIYgod'], handler, - description: `:::tip[动态的专栏显示全文] + description: `:::tip 动态的专栏显示全文 可以使用 [UP 主动态](#bilibili-up-zhu-dong-tai)路由作为代替绕过反爬限制 :::`, }; diff --git a/lib/routes/dnaindia/category.ts b/lib/routes/dnaindia/category.ts index c7f76612e..facad0317 100644 --- a/lib/routes/dnaindia/category.ts +++ b/lib/routes/dnaindia/category.ts @@ -33,7 +33,7 @@ export const route: Route = { | ------------ | | dna-verified | - :::tip[Topic] + :::tip Topic The URL of the form \`https://www.dnaindia.com/topic/dna-verified\` demonstrates the utilization of the subdomain \`topic\` :::`, description: `Categories: diff --git a/lib/routes/finology/tag.ts b/lib/routes/finology/tag.ts index 2bf356fa4..688c0d4ac 100644 --- a/lib/routes/finology/tag.ts +++ b/lib/routes/finology/tag.ts @@ -23,7 +23,7 @@ export const route: Route = { name: 'Category', maintainers: ['Rjnishant530'], handler, - description: `:::note[Category] + description: `:::note Category | Category | Link | | --------------------- | ------------------ | | **Business** | business | diff --git a/lib/routes/javbus/namespace.ts b/lib/routes/javbus/namespace.ts index 94df656dc..1badfdc7f 100644 --- a/lib/routes/javbus/namespace.ts +++ b/lib/routes/javbus/namespace.ts @@ -7,7 +7,7 @@ export const namespace: Namespace = { Requests from non-Asia areas will be redirected to login page. ::: -:::tip[Language] +:::tip Language You can change the language of each route to the languages listed below. | English | 日本语 | 한국의 | 中文 | diff --git a/lib/routes/notion/namespace.ts b/lib/routes/notion/namespace.ts index 8ff221865..c07c16baf 100644 --- a/lib/routes/notion/namespace.ts +++ b/lib/routes/notion/namespace.ts @@ -7,7 +7,7 @@ export const namespace: Namespace = { Need to set up Notion integration, please refer to [Route-specific Configurations](https://docs.rsshub.app/install/#Deployment) for details. ::: -:::tip[Recommendation] +:::tip Recommendation It is recommended to use with clipping tools such as Notion Web Clipper. :::`, }; diff --git a/lib/routes/vimeo/usr-videos.ts b/lib/routes/vimeo/usr-videos.ts index 8de876dab..eb1faf9a9 100644 --- a/lib/routes/vimeo/usr-videos.ts +++ b/lib/routes/vimeo/usr-videos.ts @@ -26,7 +26,7 @@ export const route: Route = { name: 'User Profile', maintainers: ['MisteryMonster'], handler, - description: `:::tip[Special category name attention] + description: `:::tip Special category name attention Some of the categories contain slash like \`3D/CG\` , must change the slash \`/\` to the vertical bar\`|\`. :::`, }; diff --git a/lib/routes/xsijishe/forum.ts b/lib/routes/xsijishe/forum.ts index 4ed5323dc..fe332093c 100644 --- a/lib/routes/xsijishe/forum.ts +++ b/lib/routes/xsijishe/forum.ts @@ -21,7 +21,7 @@ export const route: Route = { name: '论坛', maintainers: ['akynazh'], handler, - description: `:::tip[关于子论坛 id 的获取方法] + description: `:::tip 关于子论坛 id 的获取方法 \`/xsijishe/forum/51\` 对应于论坛 \`https://xsijishe.com/forum-51-1.html\`,这个论坛的 fid 为 51,也就是 \`forum-{fid}-1\` 中的 fid。 :::`, }; diff --git a/scripts/workflow/build-routes.ts b/scripts/workflow/build-routes.ts index 8fc152d4e..58d76754d 100644 --- a/scripts/workflow/build-routes.ts +++ b/scripts/workflow/build-routes.ts @@ -4,6 +4,7 @@ import { parse } from 'tldts'; import fs from 'node:fs'; import * as path from 'node:path'; import toSource from 'tosource'; +import { categories } from './data'; const maintainers: Record = {}; const radar: { @@ -61,6 +62,7 @@ for (const namespace in namespaces) { }; } docs[category][namespace].name = namespaces[namespace].name; + docs[category][namespace].url = namespaces[namespace].url; docs[category][namespace].description = namespaces[namespace].description; docs[category][namespace].routes[realPath] = data; } @@ -72,35 +74,19 @@ fs.writeFileSync(path.join(__dirname, '../../assets/build/radar-rules.js'), `(${ fs.writeFileSync(path.join(__dirname, '../../assets/build/maintainers.json'), JSON.stringify(maintainers, null, 2)); fs.writeFileSync(path.join(__dirname, '../../assets/build/routes.json'), JSON.stringify(namespaces, null, 2)); +// Generate markdown const pinyinCompare = new Intl.Collator('zh-Hans-CN-u-co-pinyin').compare; const isASCII = (str) => /^[\u0000-\u007F]*$/.test(str); -const md = {}; -for (const category in docs) { - md[category] = `# ${category}\n\n`; +function generateMd(lang) { + const md = {}; + for (const category in docs) { + const nameObj = categories.find((c) => c.link.includes(category)); + md[category] = `# ${`${nameObj!.icon} ${nameObj![lang]}`}\n\n`; - const namespaces = Object.keys(docs[category]).sort((a, b) => { - const aname = docs[category][a].name[0]; - const bname = docs[category][b].name[0]; - const ia = isASCII(aname); - const ib = isASCII(bname); - if (ia && ib) { - return aname.toLowerCase() < bname.toLowerCase() ? -1 : 1; - } else if (ia || ib) { - return ia > ib ? -1 : 1; - } else { - return pinyinCompare(aname, bname); - } - }); - for (const namespace of namespaces) { - md[category] += `## ${docs[category][namespace].name}\n\n`; - if (docs[category][namespace].description) { - md[category] += `${docs[category][namespace].description}\n\n`; - } - - const realPaths = Object.keys(docs[category][namespace].routes).sort((a, b) => { - const aname = docs[category][namespace].routes[a].name[0]; - const bname = docs[category][namespace].routes[b].name[0]; + const namespaces = Object.keys(docs[category]).sort((a, b) => { + const aname = docs[category][a].name[0]; + const bname = docs[category][b].name[0]; const ia = isASCII(aname); const ib = isASCII(bname); if (ia && ib) { @@ -111,21 +97,40 @@ for (const category in docs) { return pinyinCompare(aname, bname); } }); + for (const namespace of namespaces) { + md[category] += `## ${docs[category][namespace].name} ${docs[category][namespace].url ? `` : ''}\n\n`; + if (docs[category][namespace].description) { + md[category] += `${docs[category][namespace].description}\n\n`; + } - for (const realPath of realPaths) { - const data = docs[category][namespace].routes[realPath]; - md[category] += `### ${data.name}\n\n`; - md[category] += `\n\n`; - if (data.description) { - md[category] += `${data.description}\n\n`; + const realPaths = Object.keys(docs[category][namespace].routes).sort((a, b) => { + const aname = docs[category][namespace].routes[a].name[0]; + const bname = docs[category][namespace].routes[b].name[0]; + const ia = isASCII(aname); + const ib = isASCII(bname); + if (ia && ib) { + return aname.toLowerCase() < bname.toLowerCase() ? -1 : 1; + } else if (ia || ib) { + return ia > ib ? -1 : 1; + } else { + return pinyinCompare(aname, bname); + } + }); + + for (const realPath of realPaths) { + const data = docs[category][namespace].routes[realPath]; + md[category] += `### ${data.name} ${data.url || docs[category][namespace].url ? `` : ''}\n\n`; + md[category] += `\n\n`; + if (data.description) { + md[category] += `${data.description}\n\n`; + } } } } -} - -fs.writeFileSync(path.join(__dirname, '../../assets/build/docs.json'), JSON.stringify(docs, null, 2)); -if (fs.existsSync(path.join(__dirname, '../../website'))) { + fs.mkdirSync(path.join(__dirname, `../../assets/build/docs/${lang}`), { recursive: true }); for (const category in md) { - fs.writeFileSync(path.join(__dirname, `../../website/docs/routes/${category}.mdx`), md[category]); + fs.writeFileSync(path.join(__dirname, `../../assets/build/docs/${lang}/${category}.md`), md[category]); } } +generateMd('en'); +generateMd('zh'); diff --git a/scripts/workflow/data.ts b/scripts/workflow/data.ts new file mode 100644 index 000000000..dcf4cf8ff --- /dev/null +++ b/scripts/workflow/data.ts @@ -0,0 +1,140 @@ +export const categories = [ + { + icon: '💬', + link: '/routes/social-media', + en: 'Social Media', + zh: '社交媒体', + }, + { + icon: '📱', + link: '/routes/new-media', + en: 'New media', + zh: '新媒体', + }, + { + icon: '📰', + link: '/routes/traditional-media', + en: 'Traditional media', + zh: '传统媒体', + }, + { + icon: '💬️', + link: '/routes/bbs', + en: 'BBS', + zh: '论坛', + }, + { + icon: '🖊️️', + link: '/routes/blog', + en: 'Blog', + zh: '博客', + }, + { + icon: '💻', + link: '/routes/programming', + en: 'Programming', + zh: '编程', + }, + { + icon: '🎨️', + link: '/routes/design', + en: 'Design', + zh: '设计', + }, + { + icon: '🎥', + link: '/routes/live', + en: 'Live', + zh: '直播', + }, + { + icon: '🔊', + link: '/routes/multimedia', + en: 'Multimedia', + zh: '音视频', + }, + { + icon: '🖼️', + link: '/routes/picture', + en: 'Picture', + zh: '图片', + }, + { + icon: '🎨️', + link: '/routes/anime', + en: 'ACG', + zh: '二次元', + }, + { + icon: '🔄', + link: '/routes/program-update', + en: 'Application Updates', + zh: '程序更新', + }, + { + icon: '🎓', + link: '/routes/university', + en: 'University', + zh: '大学通知', + }, + { + icon: '❗️', + link: '/routes/forecast', + en: 'Forecast and Alerts', + zh: '预报预警', + }, + { + icon: '🛫', + link: '/routes/travel', + en: 'Travel', + zh: '出行旅游', + }, + { + icon: '🛍️', + link: '/routes/shopping', + en: 'Shopping', + zh: '购物', + }, + { + icon: '🎮', + link: '/routes/game', + en: 'Gaming', + zh: '游戏', + }, + { + icon: '📚', + link: '/routes/reading', + en: 'Reading', + zh: '阅读', + }, + { + icon: '📢', + link: '/routes/government', + en: 'Government', + zh: '政务消息', + }, + { + icon: '📖', + link: '/routes/study', + en: 'Study', + zh: '学习', + }, + { + icon: '🔬', + link: '/routes/journal', + en: 'Scientific Journal', + zh: '科学期刊', + }, + { + icon: '💰', + link: '/routes/finance', + en: 'Finance', + zh: '金融', + }, + { + icon: '🔍', + link: '/routes/other', + en: 'Uncategorized', + zh: '其他', + }, +];