Merge pull request #3 from cooklang/add-render-readme

Add render readme
This commit is contained in:
nιcнolaѕ wιlde 2022-05-14 08:33:20 -07:00 committed by GitHub
commit 00b194e175
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 188 additions and 16 deletions

View File

@ -12,8 +12,43 @@ project you agree to abide by its terms.
Ensure your pull request adheres to the following guidelines:
1. Fork this repository.
2. Add your awesome cooklang recipes link to the [README.md](../README.md).
3. Submit a [pull request][3].
2. Add your awesome cooklang recipes link to [data.yaml](../data.yaml).
```yaml
...
- description: "Description of your cookbook."
website:
name: "Name of your website"
url: "Url of your website"
cooklang:
name: "Name of your your cookbook site with all of your *.cook files."
url: "Url of your cookbook"
user:
name: "Your user name"
url: "Link to your website or profile."
...
```
3. Install dependencies
```shell
pip install -r ./scripts/requirements.txt
```
4. Render a new `README.md`.
```shell
python scripts/render_readme.py > README.md
```
5. Lint the repo using [awesome-lint][4] and [yamllint][5]
```shell
npx awesome-lint
yamllint .
```
6. Submit a [pull request][3].
Thank you for your suggestions!
@ -32,3 +67,5 @@ on the different ways you can update your PR so that we can merge it.
[1]: https://github.com/sindresorhus/awesome-lint
[2]: https://github.com/RichardLitt/knowledge/blob/master/github/amending-a-commit-guide.md
[3]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request
[4]: https://github.com/sindresorhus/awesome-lint
[5]: https://github.com/adrienverge/yamllint

23
.github/workflows/lint.yaml vendored Normal file
View File

@ -0,0 +1,23 @@
---
name: Lint
on: # yamllint disable-line rule:truthy
workflow_dispatch:
pull_request:
branches:
- main
jobs:
lint:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run awesome-lint
run: npx awesome-lint
- name: yamllint
uses: karancode/yamllint-github-action@master

View File

@ -1,8 +1,10 @@
<!--lint disable awesome-git-repo-age-->
# Awesome Cooklang Recipes [![Awesome](https://awesome.re/badge-flat.svg)](https://awesome.re)
<img src="https://cooklang.org/images/logo.svg" align="left" width="144px" height="144px"/>
> [cooklang][1] is a recipe markup language used to simplify your personal recipe management, streamline your shopping routine, and make cooking more fun.
> [cooklang][1] is a recipe markup language used to simplify your personal recipe management, streamline your shopping
> routine, and make cooking more fun.
This is a curated list of cookbooks and recipes involving the use of the cooklang recipe markup language.
@ -14,18 +16,10 @@ This is a curated list of cookbooks and recipes involving the use of the cooklan
## Cookbooks
| Website | Cooklang | Description |
|-------------------|---------------|-------------------------------------------------------------------|
| - | [cookbook][2] | [dubadub's][5] recipes written in Cooklang. |
| [recipes][3] | [recipes][9] | [nicholaswilde's][4] collection of recipes made with Cooklang. |
| [cooking book][8] | [remy][6] | [Net-Mist's][7] French cooking recipes. |
| Website | Cooklang | User | Description |
|---------|----------|------|-------------|
| - | [cookbook](https://github.com/dubadub/cookbook) | [dubadub](https://github.com/dubadub/) | Recipes written in Cooklang. |
| [cooking book](https://net-mist-cooking-book.netlify.app/) | [remy](https://github.com/Net-Mist/remy) | [Net-Mist](https://github.com/Net-Mist) | Contains a list of French cooking recipes. |
| [recipes](https://nicholaswilde.io/recipes/) | [recipes](https://github.com/nicholaswilde/recipes/tree/main/cook) | [nicholaswilde](https://github.com/nicholaswilde/) | A collection of recipes made with Cooklang. |
[1]: https://cooklang.org/
[2]: https://github.com/dubadub/cookbook
[3]: https://nicholaswilde.io/recipes/
[4]: https://github.com/nicholaswilde/
[5]: https://github.com/dubadub
[6]: https://github.com/Net-Mist
[7]: https://github.com/Net-Mist/remy
[8]: https://net-mist-cooking-book.netlify.app/
[9]: https://github.com/nicholaswilde/recipes/tree/main/cook

View File

@ -11,10 +11,23 @@ tasks:
desc: Lint using awesome-lint
cmds:
- "npx awesome-lint"
deps:
desc: Install dependencies
cmds:
- pip install -r ./scripts/requirements.txt
lint:
desc: Lint the repo
cmds:
- task: awesome-lint
- task: yamllint
render:
desc: Render README.md
cmds:
- "python scripts/render_readme.py > README.md"
yamllint:
desc: Lint using yamllint
cmds:
- yamllint .
default:
cmds:
- task -l

34
data.yaml Normal file
View File

@ -0,0 +1,34 @@
---
userCookbooks:
- description: "Recipes written in Cooklang."
website:
name: "-"
url: ""
cooklang:
name: "cookbook"
url: "https://github.com/dubadub/cookbook"
user:
name: "dubadub"
url: "https://github.com/dubadub/"
- description: "A collection of recipes made with Cooklang."
website:
name: "recipes"
url: "https://nicholaswilde.io/recipes/"
cooklang:
name: "recipes"
url: "https://github.com/nicholaswilde/recipes/tree/main/cook"
user:
name: "nicholaswilde"
url: "https://github.com/nicholaswilde/"
- description: "Contains a list of French cooking recipes."
website:
name: "cooking book"
url: "https://net-mist-cooking-book.netlify.app/"
cooklang:
name: "remy"
url: "https://github.com/Net-Mist/remy"
user:
name: "Net-Mist"
url: "https://github.com/Net-Mist"

44
scripts/render_readme.py Normal file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env python3
import yaml
import os
import sys
import jinja2
DATA_FILE = "data.yaml"
DATA_PATH = os.path.join(os.getcwd(), DATA_FILE)
TEMPLATE_FOLDER = os.path.join(os.getcwd(), "templates")
TEMPLATE_FILE = "README.md.j2"
TEMPLATE_PATH = os.path.join(TEMPLATE_FOLDER, TEMPLATE_FILE)
ROOT_NODE = "userCookbooks"
# TODO: Check if file exists, otherwise exit with error
if os.path.isfile(DATA_PATH):
with open(DATA_PATH, "r", encoding="utf-8") as data_file:
yaml_data = yaml.safe_load(data_file)
else:
print(f"No data file present. Please provide {DATA_PATH}")
sys.exit(1)
if not os.path.isfile(TEMPLATE_PATH):
print(f"No template file present. Please provide {TEMPLATE_PATH}")
sys.exit(1)
def massage_data():
# Sort repositories
yaml_data[ROOT_NODE] = sorted(yaml_data[ROOT_NODE], key=lambda d: d["website"]["name"].lower())
def render_readme_template():
env = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath=TEMPLATE_FOLDER))
template = env.get_template(TEMPLATE_FILE)
output = template.render(
user_cookbooks=yaml_data[ROOT_NODE],
)
return output
def main():
massage_data()
print(render_readme_template())
return 0
if __name__ == "__main__":
sys.exit(main())

2
scripts/requirements.txt Normal file
View File

@ -0,0 +1,2 @@
Jinja2
pyyaml

25
templates/README.md.j2 Normal file
View File

@ -0,0 +1,25 @@
<!--lint disable awesome-git-repo-age-->
# Awesome Cooklang Recipes [![Awesome](https://awesome.re/badge-flat.svg)](https://awesome.re)
<img src="https://cooklang.org/images/logo.svg" align="left" width="144px" height="144px"/>
> [cooklang][1] is a recipe markup language used to simplify your personal recipe management, streamline your shopping
> routine, and make cooking more fun.
This is a curated list of cookbooks and recipes involving the use of the cooklang recipe markup language.
<br />
## Contents
- [Cookbooks](#cookbooks)
## Cookbooks
| Website | Cooklang | User | Description |
|---------|----------|------|-------------|
{%- for cookbook in user_cookbooks %}
| {% if cookbook['website']['name']=="-" or cookbook['website']['name']=="" %}-{% else %}[{{ cookbook['website']['name'] }}]({{ cookbook['website']['url'] }}){%- endif %} | {%- if cookbook['cooklang']['name']=="-" or cookbook['cooklang']['name']=="" %}-{% else %} [{{ cookbook['cooklang']['name'] }}]({{ cookbook['cooklang']['url'] }}){%- endif %} | {% if cookbook['user']['url']=="" %}{{ cookbook['user']['name'] }}{% else %}[{{ cookbook['user']['name'] }}]({{ cookbook['user']['url'] }}){% endif %} | {{ cookbook['description'] }} |
{%- endfor %}
[1]: https://cooklang.org/