mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-04 19:59:54 +08:00
chore: commit docs to docs repo
This commit is contained in:
@@ -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<string, string[]> = {};
|
||||
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 ? `<Site url="${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] += `<Route namespace="${namespace}" data={${JSON.stringify(data)}} />\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 ? `<Site url="${data.url || docs[category][namespace].url}" size="sm" />` : ''}\n\n`;
|
||||
md[category] += `<Route namespace="${namespace}" :data='${JSON.stringify(data).replaceAll(`'`, ''')}' />\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');
|
||||
|
||||
140
scripts/workflow/data.ts
Normal file
140
scripts/workflow/data.ts
Normal file
@@ -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: '其他',
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user