Merge pull request #626 from keidarcy/ci-add-auto-gen-mkdocs-yml

[ci] Auto generation add mkdocs support
This commit is contained in:
Anduin Xue
2022-03-04 13:34:14 +00:00
committed by GitHub
2 changed files with 231 additions and 98 deletions

View File

@@ -1,43 +1,56 @@
const { readdir, writeFile, stat } = require('fs/promises');
const README_PATH = './README.md';
const MKDOCS_PATH = 'mkdocs.yml';
const ignorePaths = ['.git', 'README.md', 'node_modules', 'CONTRIBUTING.md', '.github'];
const categories = {
'vegetable_dish': {
vegetable_dish: {
title: '素菜',
template: '',
readme: '',
mkdocs: '',
},
'meat_dish': {
meat_dish: {
title: '荤菜',
template: '',
readme: '',
mkdocs: '',
},
breakfast: {
title: '早餐',
template: '',
readme: '',
mkdocs: '',
},
staple: {
title: '主食',
template: '',
readme: '',
mkdocs: '',
},
'semi-finished': {
title: '半成品加工',
template: '',
readme: '',
mkdocs: '',
},
soup: {
title: '汤与粥',
template: '',
readme: '',
mkdocs: '',
},
drink: {
title: '饮料',
template: '',
readme: '',
mkdocs: '',
},
condiment: {
title: '酱料和其它材料',
template: '',
readme: '',
mkdocs: '',
},
dessert: {
title: '甜品',
template: '',
readme: '',
mkdocs: '',
},
};
@@ -72,38 +85,138 @@ let README_TEMPLATE = `# 程序员做饭指南
{{after}}`;
let MKDOCS_TEMPLATE = `site_name: How To Cook
# Repository
repo_name: Anduin2017/HowToCook
repo_url: https://github.com/Anduin2017/HowToCook
edit_uri: ""
use_directory_urls: true
docs_dir: .
theme:
name: material
language: zh
features:
- content.code.annotate
# - content.tabs.link
# - header.autohide
#- navigation.expand
#- navigation.indexes
- navigation.instant
- navigation.sections
- navigation.tabs
- navigation.tabs.sticky
- navigation.top
- navigation.tracking
- search.highlight
- search.share
- search.suggest
- toc.follow
# # - toc.integrate
search_index_only: true
palette:
- media: "(prefers-color-scheme: light)"
scheme: default
toggle:
icon: material//weather-sunny
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
toggle:
icon: material/weather-night
name: Switch to light mode
icon:
admonition:
note: octicons/tag-16
abstract: octicons/checklist-16
info: octicons/info-16
tip: octicons/squirrel-16
success: octicons/check-16
question: octicons/question-16
warning: octicons/alert-16
failure: octicons/x-circle-16
danger: octicons/zap-16
bug: octicons/bug-16
example: octicons/beaker-16
quote: octicons/quote-16
markdown_extensions:
- admonition
- pymdownx.details
- pymdownx.superfences
- abbr
- pymdownx.snippets
- def_list
- pymdownx.tasklist:
custom_checkbox: true
- attr_list
plugins:
- same-dir
- search
- minify:
minify_html: true
nav:
- README.md
- 做菜之前:
{{before}}
- 菜谱:
- 按种类: # 只有两层section以上才能出现navigation expansion https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/#navigation-sections
{{main}}
- 进阶知识学习:
{{after}}
- CONTRIBUTING.md
`;
async function main() {
try {
let BEFORE = (MAIN = AFTER = '');
let README_BEFORE = (README_MAIN = README_AFTER = '');
let MKDOCS_BEFORE = (MKDOCS_MAIN = MKDOCS_AFTER = '');
const markdownObj = await getAllMarkdown('.');
for (const markdown of markdownObj) {
if (markdown.path.includes('tips/advanced')) {
AFTER += inlineTemplate(markdown.file, markdown.path, true);
README_AFTER += inlineReadmeTemplate(markdown.file, markdown.path);
MKDOCS_AFTER += inlineMkdocsTemplate(markdown.file, markdown.path);
continue;
}
if (markdown.path.includes('tips')) {
BEFORE += inlineTemplate(markdown.file, markdown.path, true);
README_BEFORE += inlineReadmeTemplate(markdown.file, markdown.path);
MKDOCS_BEFORE += inlineMkdocsTemplate(markdown.file, markdown.path);
continue;
}
for (const category of Object.keys(categories)) {
if (markdown.path.includes(category)) {
let currentCategoryStr = categories[category].template;
currentCategoryStr += inlineTemplate(markdown.file, markdown.path);
categories[category].template = currentCategoryStr;
}
if (!markdown.path.includes(category)) continue;
categories[category].readme += inlineReadmeTemplate(markdown.file, markdown.path);
categories[category].mkdocs += inlineMkdocsTemplate(
markdown.file,
markdown.path,
true,
);
}
}
for (const category of Object.values(categories)) {
MAIN += categoryTemplate(category.title, category.template);
README_MAIN += categoryReadmeTemplate(category.title, category.readme);
MKDOCS_MAIN += categoryMkdocsTemplate(category.title, category.mkdocs);
}
await writeFile(
'./README.md',
README_TEMPLATE.replace('{{before}}', BEFORE)
.replace('{{main}}', MAIN)
.replace('{{after}}', AFTER),
README_PATH,
README_TEMPLATE.replace('{{before}}', README_BEFORE)
.replace('{{main}}', README_MAIN)
.replace('{{after}}', README_AFTER),
);
await writeFile(
MKDOCS_PATH,
MKDOCS_TEMPLATE.replace('{{before}}', MKDOCS_BEFORE)
.replace('{{main}}', MKDOCS_MAIN)
.replace('{{after}}', MKDOCS_AFTER),
);
} catch (error) {
console.error(error);
@@ -136,12 +249,20 @@ async function getAllMarkdown(path) {
return paths;
}
function inlineTemplate(file, path) {
function inlineReadmeTemplate(file, path) {
return `- [${file.replace('.md', '')}](${path}/${file})\n`;
}
function categoryTemplate(title, inlineStr) {
function categoryReadmeTemplate(title, inlineStr) {
return `\n### ${title}\n\n${inlineStr}`;
}
function inlineMkdocsTemplate(file, path, isDish = false) {
return `${' '.repeat(isDish ? 10 : 6)}- ${file.replace('.md', '')}: ${path}/${file}\n`;
}
function categoryMkdocsTemplate(title, inlineStr) {
return `\n${' '.repeat(6)}- ${title}:\n${inlineStr}`;
}
main();

View File

@@ -77,8 +77,10 @@ nav:
- 做菜之前:
- 厨房准备: ./tips/厨房准备.md
- 如何选择现在吃什么: ./tips/如何选择现在吃什么.md
- 专业术语: ./tips/专业术语.md
- 高压力锅: ./tips/learn/高压力锅.md
- 食品安全: ./tips/learn/食品安全.md
- 微波炉: ./tips/learn/微波炉.md
- 学习焯水: ./tips/learn/学习焯水.md
- 学习炒与煎: ./tips/learn/学习炒与煎.md
- 学习腌: ./tips/learn/学习腌.md
@@ -87,9 +89,80 @@ nav:
- 菜谱:
- 按种类: # 只有两层section以上才能出现navigation expansion https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/#navigation-sections
- 素菜:
- 菠菜炒鸡蛋: ./dishes/vegetable_dish/菠菜炒鸡蛋/菠菜炒鸡蛋.md
- 炒青菜: ./dishes/vegetable_dish/炒青菜.md
- 葱煎豆腐: ./dishes/vegetable_dish/葱煎豆腐.md
- 地三鲜: ./dishes/vegetable_dish/地三鲜.md
- 红烧茄子: ./dishes/vegetable_dish/红烧茄子.md
- 鸡蛋羹: ./dishes/vegetable_dish/鸡蛋羹/鸡蛋羹.md
- 微波炉鸡蛋羹: ./dishes/vegetable_dish/鸡蛋羹/微波炉鸡蛋羹.md
- 烤茄子: ./dishes/vegetable_dish/烤茄子/烤茄子.md
- 榄菜肉末四季豆: ./dishes/vegetable_dish/榄菜肉末四季豆/榄菜肉末四季豆.md
- 冷吃兔: ./dishes/vegetable_dish/冷吃兔.md
- 凉拌黄瓜: ./dishes/vegetable_dish/凉拌黄瓜.md
- 麻辣香锅: ./dishes/vegetable_dish/麻辣香锅.md
- 上汤娃娃菜: ./dishes/vegetable_dish/上汤娃娃菜/上汤娃娃菜.md
- 水油焖蔬菜: ./dishes/vegetable_dish/水油焖蔬菜.md
- 酸辣土豆丝: ./dishes/vegetable_dish/酸辣土豆丝.md
- 蒜苔炒肉末: ./dishes/vegetable_dish/蒜苔炒肉末.md
- 糖拌西红柿: ./dishes/vegetable_dish/糖拌西红柿/糖拌西红柿.md
- 西红柿炒鸡蛋: ./dishes/vegetable_dish/西红柿炒鸡蛋.md
- 荤菜:
- 白菜猪肉炖粉条: ./dishes/meat_dish/白菜猪肉炖粉条.md
- 白灼虾: ./dishes/meat_dish/白灼虾/白灼虾.md
- 鳊鱼炖豆腐: ./dishes/meat_dish/鳊鱼炖豆腐/鳊鱼炖豆腐.md
- 宫保鸡丁: ./dishes/meat_dish/宫保鸡丁/宫保鸡丁.md
- 咕噜肉: ./dishes/meat_dish/咕噜肉.md
- 红烧鲤鱼: ./dishes/meat_dish/红烧鲤鱼.md
- 简易红烧肉: ./dishes/meat_dish/红烧肉/简易红烧肉.md
- 南派红烧肉: ./dishes/meat_dish/红烧肉/南派红烧肉.md
- 红烧鱼头: ./dishes/meat_dish/红烧鱼头.md
- 红烧猪蹄: ./dishes/meat_dish/红烧猪蹄/红烧猪蹄.md
- 黄瓜炒肉: ./dishes/meat_dish/黄瓜炒肉.md
- 黄油煎虾: ./dishes/meat_dish/黄油煎虾/黄油煎虾.md
- 回锅肉: ./dishes/meat_dish/回锅肉.md
- 烤鱼: ./dishes/meat_dish/混合烤鱼/烤鱼.md
- 茄子炖土豆: ./dishes/meat_dish/茄子炖土豆.md
- 尖椒炒牛肉: ./dishes/meat_dish/尖椒炒牛肉.md
- 姜炒鸡: ./dishes/meat_dish/姜炒鸡/姜炒鸡.md
- 酱牛肉: ./dishes/meat_dish/酱牛肉/酱牛肉.md
- 咖喱炒蟹: ./dishes/meat_dish/咖喱炒蟹.md
- 可乐鸡翅: ./dishes/meat_dish/可乐鸡翅.md
- 口水鸡: ./dishes/meat_dish/口水鸡/口水鸡.md
- 辣椒炒肉: ./dishes/meat_dish/辣椒炒肉.md
- 老式锅包肉: ./dishes/meat_dish/老式锅包肉/老式锅包肉.md
- 凉拌鸡丝: ./dishes/meat_dish/凉拌鸡丝/凉拌鸡丝.md
- 萝卜炖羊排: ./dishes/meat_dish/萝卜炖羊排.md
- 清蒸鲈鱼: ./dishes/meat_dish/清蒸鲈鱼/清蒸鲈鱼.md
- 清蒸生蚝: ./dishes/meat_dish/清蒸生蚝.md
- 水煮牛肉: ./dishes/meat_dish/水煮牛肉/水煮牛肉.md
- 水煮肉片: ./dishes/meat_dish/水煮肉片.md
- 糖醋里脊: ./dishes/meat_dish/糖醋里脊.md
- 糖醋鲤鱼: ./dishes/meat_dish/糖醋鲤鱼/糖醋鲤鱼.md
- 土豆炖排骨: ./dishes/meat_dish/土豆炖排骨/土豆炖排骨.md
- 微波葱姜黑鳕鱼: ./dishes/meat_dish/微波葱姜黑鳕鱼.md
- 西红柿牛腩: ./dishes/meat_dish/西红柿牛腩/西红柿牛腩.md
- 西红柿土豆炖牛肉: ./dishes/meat_dish/西红柿土豆炖牛肉/西红柿土豆炖牛肉.md
- 香干芹菜炒肉: ./dishes/meat_dish/香干芹菜炒肉/香干芹菜炒肉.md
- 香干肉丝: ./dishes/meat_dish/香干肉丝.md
- 香菇滑鸡: ./dishes/meat_dish/香菇滑鸡/香菇滑鸡.md
- 小炒黄牛肉: ./dishes/meat_dish/小炒黄牛肉/小炒黄牛肉.md
- 小炒肉: ./dishes/meat_dish/小炒肉.md
- 新疆大盘鸡: ./dishes/meat_dish/新疆大盘鸡/新疆大盘鸡.md
- 血浆鸭: ./dishes/meat_dish/血浆鸭/血浆鸭.md
- 洋葱炒猪肉: ./dishes/meat_dish/洋葱炒猪肉.md
- 鱼香茄子: ./dishes/meat_dish/鱼香茄子/鱼香茄子.md
- 鱼香肉丝: ./dishes/meat_dish/鱼香肉丝.md
- 孜然牛肉: ./dishes/meat_dish/孜然牛肉.md
- 早餐:
- 茶叶蛋: ./dishes/breakfast/茶叶蛋.md
- 鸡蛋三明治: ./dishes/breakfast/鸡蛋三明治.md
- 煎饺: ./dishes/breakfast/煎饺.md
- 空气炸锅面包片: ./dishes/breakfast/空气炸锅面包片.md
- 美式炒蛋: ./dishes/breakfast/美式炒蛋.md
- 牛奶燕麦: ./dishes/breakfast/牛奶燕麦.md
- 水煮玉米: ./dishes/breakfast/水煮玉米.md
@@ -100,88 +173,28 @@ nav:
- 燕麦鸡蛋饼: ./dishes/breakfast/燕麦鸡蛋饼.md
- 蒸花卷: ./dishes/breakfast/蒸花卷.md
- 家常菜:
- 白菜猪肉炖粉条: ./dishes/home-cooking/白菜猪肉炖粉条.md
- 白灼虾: ./dishes/home-cooking/白灼虾/白灼虾.md
- 鳊鱼炖豆腐: ./dishes/home-cooking/鳊鱼炖豆腐/鳊鱼炖豆腐.md
- 菠菜炒鸡蛋: ./dishes/home-cooking/菠菜炒鸡蛋/菠菜炒鸡蛋.md
- 炒青菜: ./dishes/home-cooking/炒青菜.md
- 葱煎豆腐: ./dishes/home-cooking/葱煎豆腐.md
- 地三鲜: ./dishes/home-cooking/地三鲜.md
- 宫保鸡丁: ./dishes/home-cooking/宫保鸡丁/宫保鸡丁.md
- 咕噜肉: ./dishes/home-cooking/咕噜肉.md
- 韩式拌饭: ./dishes/home-cooking/韩式拌饭/韩式拌饭.md
- 红烧茄子: ./dishes/home-cooking/红烧茄子.md
- 红烧鲤鱼: ./dishes/home-cooking/红烧鲤鱼.md
- 简易红烧肉: ./dishes/home-cooking/红烧肉/简易红烧肉.md
- 南派红烧肉: ./dishes/home-cooking/红烧肉/南派红烧肉.md
- 红烧鱼头: ./dishes/home-cooking/红烧鱼头.md
- 红烧猪蹄: ./dishes/home-cooking/红烧猪蹄/红烧猪蹄.md
- 黄瓜炒肉: ./dishes/home-cooking/黄瓜炒肉.md
- 黄油煎虾: ./dishes/home-cooking/黄油煎虾/黄油煎虾.md
- 回锅肉: ./dishes/home-cooking/回锅肉.md
- 烤鱼: ./dishes/home-cooking/混合烤鱼/烤鱼.md
- 鸡蛋羹: ./dishes/home-cooking/鸡蛋羹/鸡蛋羹.md
- 微波炉鸡蛋羹: ./dishes/home-cooking/鸡蛋羹/微波炉鸡蛋羹.md
- 茄子炖土豆: ./dishes/home-cooking/茄子炖土豆.md
- 尖椒炒牛肉: ./dishes/home-cooking/尖椒炒牛肉.md
- 姜炒鸡: ./dishes/home-cooking/姜炒鸡/姜炒鸡.md
- 酱牛肉: ./dishes/home-cooking/酱牛肉/酱牛肉.md
- 咖喱炒蟹: ./dishes/home-cooking/咖喱炒蟹.md
- 烤茄子: ./dishes/home-cooking/烤茄子/烤茄子.md
- 可乐鸡翅: ./dishes/home-cooking/可乐鸡翅.md
- 口水鸡: ./dishes/home-cooking/口水鸡/口水鸡.md
- 辣椒炒肉: ./dishes/home-cooking/辣椒炒肉.md
- 榄菜肉末四季豆: ./dishes/home-cooking/榄菜肉末四季豆/榄菜肉末四季豆.md
- 老式锅包肉: ./dishes/home-cooking/老式锅包肉/老式锅包肉.md
- 冷吃兔: ./dishes/home-cooking/冷吃兔.md
- 凉拌黄瓜: ./dishes/home-cooking/凉拌黄瓜.md
- 凉粉: ./dishes/home-cooking/凉粉/凉粉.md
- 萝卜炖羊排: ./dishes/home-cooking/萝卜炖羊排.md
- 麻辣香锅: ./dishes/home-cooking/麻辣香锅.md
- 清蒸鲈鱼: ./dishes/home-cooking/清蒸鲈鱼/清蒸鲈鱼.md
- 清蒸生蚝: ./dishes/home-cooking/清蒸生蚝.md
- 上汤娃娃菜: ./dishes/home-cooking/上汤娃娃菜/上汤娃娃菜.md
- 水油焖蔬菜: ./dishes/home-cooking/水油焖蔬菜.md
- 水煮牛肉: ./dishes/home-cooking/水煮牛肉/水煮牛肉.md
- 水煮肉片: ./dishes/home-cooking/水煮肉片.md
- 酸辣土豆丝: ./dishes/home-cooking/酸辣土豆丝.md
- 蒜苔炒肉末: ./dishes/home-cooking/蒜苔炒肉末.md
- 糖拌西红柿: ./dishes/home-cooking/糖拌西红柿/糖拌西红柿.md
- 糖醋里脊: ./dishes/home-cooking/糖醋里脊.md
- 糖醋鲤鱼: ./dishes/home-cooking/糖醋鲤鱼/糖醋鲤鱼.md
- 土豆炖排骨: ./dishes/home-cooking/土豆炖排骨/土豆炖排骨.md
- 西红柿炒鸡蛋: ./dishes/home-cooking/西红柿炒鸡蛋.md
- 西红柿牛腩: ./dishes/home-cooking/西红柿牛腩/西红柿牛腩.md
- 西红柿土豆炖牛肉: ./dishes/home-cooking/西红柿土豆炖牛肉/西红柿土豆炖牛肉.md
- 香干芹菜炒肉: ./dishes/home-cooking/香干芹菜炒肉/香干芹菜炒肉.md
- 香干肉丝: ./dishes/home-cooking/香干肉丝.md
- 香菇滑鸡: ./dishes/home-cooking/香菇滑鸡/香菇滑鸡.md
- 小炒黄牛肉: ./dishes/home-cooking/小炒黄牛肉/小炒黄牛肉.md
- 小炒肉: ./dishes/home-cooking/小炒肉.md
- 血浆鸭: ./dishes/home-cooking/血浆鸭/血浆鸭.md
- 洋葱炒猪肉: ./dishes/home-cooking/洋葱炒猪肉.md
- 鱼香茄子: ./dishes/home-cooking/鱼香茄子/鱼香茄子.md
- 鱼香肉丝: ./dishes/home-cooking/鱼香肉丝.md
- 孜然牛肉: ./dishes/home-cooking/孜然牛肉.md
- 主食:
- 炒方便面: ./dishes/staple/炒方便面.md
- 炒河粉: ./dishes/staple/炒河粉.md
- 炒馍: ./dishes/staple/炒馍.md
- 蛋炒饭: ./dishes/staple/蛋炒饭.md
- 韩式拌饭: ./dishes/staple/韩式拌饭/韩式拌饭.md
- 醪糟小汤圆: ./dishes/staple/醪糟小汤圆.md
- 老干妈拌面: ./dishes/staple/老干妈拌面.md
- 老友猪肉粉: ./dishes/staple/老友猪肉粉/老友猪肉粉.md
- 烙饼: ./dishes/staple/烙饼/烙饼.md
- 凉粉: ./dishes/staple/凉粉/凉粉.md
- 麻辣减脂荞麦面: ./dishes/staple/麻辣减脂荞麦面.md
- 麻油拌面: ./dishes/staple/麻油拌面.md
- 米饭: ./dishes/staple/米饭/米饭.md
- 电饭煲蒸米饭: ./dishes/staple/米饭/电饭煲蒸米饭.md
- 煮锅蒸米饭: ./dishes/staple/米饭/煮锅蒸米饭.md
- 热干面: ./dishes/staple/热干面.md
- 日式咖喱饭: ./dishes/staple/日式咖喱饭/日式咖喱饭.md
- 手工水饺: ./dishes/staple/手工水饺.md
- 汤面: ./dishes/staple/汤面.md
- 微波炉腊肠煲仔饭: ./dishes/staple/微波炉腊肠煲仔饭/微波炉腊肠煲仔饭.md
- 炸酱面: ./dishes/staple/炸酱面.md
- 中式馅饼: ./dishes/staple/中式馅饼/中式馅饼.md
- 煮泡面加蛋: ./dishes/staple/煮泡面加蛋.md
- 披萨饼皮: ./dishes/staple/pizza/披萨饼皮.md
@@ -215,7 +228,6 @@ nav:
- 杨枝甘露: ./dishes/drink/杨枝甘露.md
- B52轰炸机: ./dishes/drink/B52轰炸机.md
- 酱料和其它材料:
- 草莓酱: ./dishes/condiment/草莓酱/草莓酱.md
- 蒜香酱油: ./dishes/condiment/蒜香酱油.md