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 7, 2022
2 parents e233f41 + caa5383 commit 347e21b
Show file tree
Hide file tree
Showing 50 changed files with 575 additions and 182 deletions.
132 changes: 11 additions & 121 deletions .github/readme-generate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { readdir, writeFile, stat } = require('fs/promises');
const fs = require('fs').promises;

const README_PATH = './README.md';

Expand Down Expand Up @@ -59,123 +60,6 @@ const categories = {
},
};

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 = '');
Expand Down Expand Up @@ -210,16 +94,22 @@ async function main() {
MKDOCS_MAIN += categoryMkdocsTemplate(category.title, category.mkdocs);
}

const MKDOCS_TEMPLATE = await fs.readFile("./.github/templates/mkdocs_template.yml", "utf-8");
const README_TEMPLATE = await fs.readFile("./.github/templates/readme_template.md", "utf-8");

await writeFile(
README_PATH,
README_TEMPLATE.replace('{{before}}', README_BEFORE)
.replace('{{main}}', README_MAIN)
.replace('{{after}}', README_AFTER),
README_TEMPLATE
.replace('{{before}}', README_BEFORE.trim())
.replace('{{main}}', README_MAIN.trim())
.replace('{{after}}', README_AFTER.trim()),
);


await writeFile(
MKDOCS_PATH,
MKDOCS_TEMPLATE.replace('{{before}}', MKDOCS_BEFORE)
MKDOCS_TEMPLATE
.replace('{{before}}', MKDOCS_BEFORE)
.replace('{{main}}', MKDOCS_MAIN)
.replace('{{after}}', MKDOCS_AFTER),
);
Expand Down
85 changes: 85 additions & 0 deletions .github/templates/mkdocs_template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
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
- CODE_OF_CONDUCT.md
34 changes: 34 additions & 0 deletions .github/templates/readme_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 程序员做饭指南

[![build](https://github.com/Anduin2017/HowToCook/actions/workflows/build.yml/badge.svg)](https://github.com/Anduin2017/HowToCook/actions/workflows/build.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)
[![npm](https://img.shields.io/npm/v/how-to-cook)](https://www.npmjs.com/package/how-to-cook)

最近在家隔离,出不了门。只能宅在家做饭了。作为程序员,我偶尔在网上找找菜谱和做法。但是这些菜谱往往写法千奇百怪,经常中间莫名出来一些材料。对于习惯了形式语言的程序员来说极其不友好。

所以,我计划自己搜寻菜谱和并结合实际做菜的经验,准备用更清晰精准的描述来整理常见菜的做法,以方便程序员在家做饭。

同样,我希望它是一个由社区驱动和维护的开源项目,使更多人能够一起做一个有趣的仓库。所以非常欢迎大家贡献它~

## 如何贡献

针对发现的问题,直接修改并提交 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}}
19 changes: 14 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,37 @@ jobs:
Rebuild-everything:
runs-on: ubuntu-latest
steps:
# Preparation.
# Checkout, install tools..
- uses: actions/checkout@v2
with:
token: ${{ secrets.PAT }}
- uses: actions/setup-node@v2
with:
node-version: '16'
cache: 'npm'
- run: npm install
# Generate Readme.
- name: Install packages
run: sudo gem install mdl
# Generate Readme, mkdocs.
- run: node ./.github/readme-generate.js
# Lint issues first. (Without node_modules)
- name: Lint markdown files
run: mdl . -r ~MD036,~MD024,~MD004,~MD029
- run: pip install -r requirements.txt
- run: mkdocs build --strict
# Do textlint fix.
- run: npm install
- run: ./node_modules/.bin/textlint . --fix
- run: rm ./node_modules -rvf
# Save files.
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: '[ci skip] Automatic file changes/fix'
branch: 'master'
file_pattern: ':/*.md'
file_pattern: ':/*.*'
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
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ jobs:
run: sudo gem install mdl
- name: Lint markdown files
run: mdl . -r ~MD036,~MD024,~MD004,~MD029
- run: pip install -r requirements.txt
- run: mkdocs build --strict
# Suppress 036 Emphasis used instead of a header
# Suppress 024 Multiple headers with the same content
4 changes: 2 additions & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Code Of Counduct
# 行为准则

## 这个仓库可以做什么?
## 我们为什么坚持维护这个仓库

有很多朋友问我,为什么要维护这个仓库?为什么坚持精准的菜谱?未来这个仓库打算怎么发展?有没有想流量变现?我想在这里给出我自己的答案,并明确贡献的价值观吧。

Expand Down
45 changes: 44 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ mkdocs serve
### 编译

```bash
mkdocs build
mkdocs build --strict
```

生成静态 HTML 网页, 存在于在`site/`文件夹下。Hosting 的时候指向到`site/index.html`即可。
Expand All @@ -123,3 +123,46 @@ mkdocs build
> 由于`mkdocs`不原生支持`*.md`存在于根目录下,只能添加了`mkdocs-same-dir`这个插件来做workaround。
> 通常来说mkdoc会自动检查文件夹里的各种文件 (eg *.jpg)然后生成相对应的链接。由于这个
> workaround,根目录下现在只能检测到`.md`文件。这个限制并不影响剩下的文件夹(比方说`tips``dishes`)。
## 手工 lint

如果需要检查文档中的不规范,可以手工运行 lint 操作。

需求:Ruby

### 安装 markdownlint

```bash
sudo gem install mdl # Linux
```

```powershell
gem install mdl # Windows, with administrators permission.
```

### 运行 lint

```bash
mdl . -r ~MD036,~MD024,~MD004,~MD029
```

## 生成 Readme 和 mkdocs

一般的,每次 master 分支发生变更后,会自动生成 Readme 和 mkdocs 文件。但是,在某些情况下可能需要开发者手工生成这些文件。

需求:node,npm

```bash
node ./.github/readme-generate.js
```

## 自动 markdown 修复

框架支持一些自动 markdown 错误修正功能。一般的,每次 master 分支发生变更后,会自动修正。但是,在某些情况下可能需要开发者手工修正。

需求:node,npm

```bash
npm install
./node_modules/.bin/textlint . --fix
```
Loading

0 comments on commit 347e21b

Please sign in to comment.