Skip to content

Commit

Permalink
Merge branch 'master' into kiwijuice
Browse files Browse the repository at this point in the history
  • Loading branch information
Anduin2017 authored Mar 4, 2022
2 parents 8424217 + 8c98ada commit e233f41
Show file tree
Hide file tree
Showing 247 changed files with 4,660 additions and 916 deletions.
3 changes: 2 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
- [ ] 菜谱包含`必备原料和工具`, `计算`, `操作`三部分内容。
- [ ] 菜品的`原材料用量`是无歧义且准确的。对于可以自行发挥的量给出了建议的范围。
- [ ] 菜品的`制作步骤`是无歧义,准确且完整的。对于每一个步骤的开始和结束都有明确的标准。
- [ ] 我已更新 Readme 对本次修改的菜谱的引用链接。
- [ ] 我没有破坏模板的一二级标题格式。
- [ ] 我没有删除模板中必需的内容。
- [ ] 我已删除干净所有的复制出来的模板的注释。
- [ ] 我确保我没有签入任何和版权方相关的内容、图片。

请审核人员按照 [审核检查单](https://github.com/Anduin2017/HowToCook/blob/master/CONTRIBUTING.md#%E5%AE%A1%E6%A0%B8%E5%91%98%E9%A1%BB%E7%9F%A5) 对照审核检查。

## 警告

**HowToCook 仓库采用了 [The Unlicense](https://unlicense.org/) 协议!**
Expand Down
273 changes: 273 additions & 0 deletions .github/readme-generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
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: {
title: '素菜',
readme: '',
mkdocs: '',
},
meat_dish: {
title: '荤菜',
readme: '',
mkdocs: '',
},
aquatic: {
title: '水产',
readme: '',
mkdocs: '',
},
breakfast: {
title: '早餐',
readme: '',
mkdocs: '',
},
staple: {
title: '主食',
readme: '',
mkdocs: '',
},
'semi-finished': {
title: '半成品加工',
readme: '',
mkdocs: '',
},
soup: {
title: '汤与粥',
readme: '',
mkdocs: '',
},
drink: {
title: '饮料',
readme: '',
mkdocs: '',
},
condiment: {
title: '酱料和其它材料',
readme: '',
mkdocs: '',
},
dessert: {
title: '甜品',
readme: '',
mkdocs: '',
},
};

let README_TEMPLATE = `# 程序员做饭指南
[![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/Anduin2017/HowToCook/Continuous%20Integration/master)](https://github.com/Anduin2017/HowToCook/actions/workflows/ci.yml)
[![License](https://img.shields.io/github/license/Anduin2017/HowToCook)](./LICENSE)
[![GitHub contributors](https://img.shields.io/github/contributors/Anduin2017/HowToCook)](https://github.com/Anduin2017/HowToCook/graphs/contributors)
最近在家隔离,出不了门。只能宅在家做饭了。作为程序员,我偶尔在网上找找菜谱和做法。但是这些菜谱往往写法千奇百怪,经常中间莫名出来一些材料。对于习惯了形式语言的程序员来说极其不友好。
所以,我计划自己搜寻菜谱和并结合实际做菜的经验,准备用更清晰精准的描述来整理常见菜的做法,以方便程序员在家做饭。
同样,我希望它是一个由社区驱动和维护的开源项目,使更多人能够一起做一个有趣的仓库。所以非常欢迎大家贡献它~
## 如何贡献
针对发现的问题,直接修改并提交 Pull request 即可。
在写新菜谱时,请复制并修改已有的菜谱模板: [示例菜](https://github.com/Anduin2017/HowToCook/blob/master/dishes/template/%E7%A4%BA%E4%BE%8B%E8%8F%9C/%E7%A4%BA%E4%BE%8B%E8%8F%9C.md?plain=1)。
## 做菜之前
{{before}}
## 菜谱
### 家常菜
{{main}}
## 进阶知识学习
如果你已经做了许多上面的菜,对于厨艺已经入门,并且想学习更加高深的烹饪技巧,请继续阅读下面的内容:
{{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 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')) {
README_AFTER += inlineReadmeTemplate(markdown.file, markdown.path);
MKDOCS_AFTER += inlineMkdocsTemplate(markdown.file, markdown.path);
continue;
}

if (markdown.path.includes('tips')) {
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)) 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)) {
README_MAIN += categoryReadmeTemplate(category.title, category.readme);
MKDOCS_MAIN += categoryMkdocsTemplate(category.title, category.mkdocs);
}

await writeFile(
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);
}
}

async function getAllMarkdown(path) {
const paths = [];
const files = await readdir(path);
// chinese alphabetic order
files.sort((a, b) => a.localeCompare(b, 'zh-CN'));

// mtime order
// files.sort(async (a, b) => {
// const aStat = await stat(`${path}/${a}`);
// const bStat = await stat(`${path}/${b}`);
// return aStat.mtime - bStat.mtime;
// });
for (const file of files) {
const filePath = `${path}/${file}`;
if (ignorePaths.includes(file)) continue;
const fileStat = await stat(filePath);
if (fileStat.isFile() && file.endsWith('.md')) {
paths.push({ path, file });
} else if (fileStat.isDirectory()) {
const subFiles = await getAllMarkdown(filePath);
paths.push(...subFiles);
}
}
return paths;
}

function inlineReadmeTemplate(file, path) {
return `- [${file.replace('.md', '')}](${path}/${file})\n`;
}

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();
28 changes: 28 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Configuration for probot-stale - https://github.com/probot/stale
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 30
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- "Type: Bug"
# Label to use when marking an issue as stale
staleLabel: "Resolution: Stale"
issues:
# Comment to post when marking an issue as stale.
markComment: >
This issue has been automatically marked as stale.
**If this issue is still affecting you, please leave any comment** (for example, "bump"), and we'll keep it open.
We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!
# Comment to post when closing a stale issue.
closeComment: >
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!
pulls:
# Comment to post when marking a pull request as stale.
markComment: >
This pull request has been automatically marked as stale.
**If this pull request is still relevant, please leave any comment** (for example, "bump"), and we'll keep it open.
We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.
# Comment to post when closing a stale pull request.
closeComment: >
Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you!
41 changes: 41 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: build

on:
push:
branches: [ master ]
workflow_dispatch:

jobs:
Rebuild-everything:
runs-on: ubuntu-latest
steps:
# Preparation.
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
cache: 'npm'
- run: npm install
# Generate Readme.
- run: node ./.github/readme-generate.js
# Do textlint fix.
- run: ./node_modules/.bin/textlint . --fix
# Save files.
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: '[ci skip] Automatic file changes/fix'
branch: 'master'
file_pattern: ':/*.md'
commit_user_name: github-actions[bot]
commit_user_email: github-actions[bot]@users.noreply.github.com
commit_author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
# Build docs
- run: rm ./node_modules -rvf
- run: echo cook.aiurs.co > CNAME
- run: mkdir docs && echo cook.aiurs.co > docs/CNAME
- uses: mhausenblas/mkdocs-deploy-gh-pages@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CUSTOM_DOMAIN: cook.aiurs.co
CONFIG_FILE: mkdocs.yml
REQUIREMENTS: requirements.txt
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: Continuous Integration

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
markdown:
markdown-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install packages
run: sudo gem install mdl
- name: Lint markdown files
run: mdl *.md -r ~MD009,~MD029,~MD036,~MD024
run: mdl . -r ~MD036,~MD024,~MD004,~MD029
# Suppress 036 Emphasis used instead of a header
# Suppress 024 Multiple headers with the same content
Loading

0 comments on commit e233f41

Please sign in to comment.