render recipes with embedded subrecipes, print some meta information, etc
This commit is contained in:
parent
3b07cd9d5d
commit
451f6afeb4
7 changed files with 52 additions and 2 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,7 +1,7 @@
|
||||||
_site
|
_site
|
||||||
_recipes
|
_recipes
|
||||||
|
_subrecipes
|
||||||
.sass-cache
|
.sass-cache
|
||||||
.jekyll-cache
|
.jekyll-cache
|
||||||
.jekyll-metadata
|
.jekyll-metadata
|
||||||
vendor
|
vendor
|
||||||
_config.yml
|
|
||||||
|
|
6
_config.yml
Normal file
6
_config.yml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
collections:
|
||||||
|
# note: subrecipes MUST come before recipes, otherwise subrecipe.output will be empty with no error message given. thanks to https://github.com/jekyll/jekyll/issues/5371#issuecomment-247951926
|
||||||
|
subrecipes:
|
||||||
|
output: false
|
||||||
|
recipes:
|
||||||
|
output: true
|
10
_includes/ingredients.html
Normal file
10
_includes/ingredients.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{% assign tag = "h2" %}
|
||||||
|
{% if page.collection == "subrecipes" %}
|
||||||
|
{% assign tag = "h4" %}
|
||||||
|
{% endif %}
|
||||||
|
<{{tag}}>Ingredients</{{tag}}>
|
||||||
|
<ul>
|
||||||
|
{% for item in page.ingredients %}
|
||||||
|
<li>{{ item[0] }} {% if item[2] %} {{ item[2] }} of {% endif %} {{ item[1] }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
5
_includes/recipes.html
Normal file
5
_includes/recipes.html
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<ul>
|
||||||
|
{% for recipe in site.recipes -%}
|
||||||
|
<li><a href='{{ recipe.url }}'>{{ recipe.name }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
28
_layouts/recipe.html
Normal file
28
_layouts/recipe.html
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
---
|
||||||
|
layout: default
|
||||||
|
---
|
||||||
|
{%- comment -%} this is a gross method of convertin "_recipes/example.md" to "example". it does it by removing the leading "_recipes/", which is simple enough, and then the trailing ".md", which is done by converting the string to an array, reversing it, turning it back into a string, removing the leading "dm." (".md" backwards), and doing the the array -> reverse -> string shuffle again. it's ugly but hey it works right {%- endcomment -%}
|
||||||
|
{% assign id = page.path | remove_first: "_recipes/" | split: "" | reverse | join: "" | remove_first: "dm." | split: "" | reverse | join: "" %}
|
||||||
|
{%- comment -%} unfortunately we have to iterate through the entire subrecipe folder twice - once to see if there are any subrecipes that apply here, and another time to put them in. thankfully we can break out of the first loop if we find a single match. i miss jinja ;u; {%- endcomment -%}
|
||||||
|
{% assign applicable_subrecipes = false %}
|
||||||
|
{% for subrecipe in site.subrecipes %}
|
||||||
|
{% if subrecipe.parents contains id %}
|
||||||
|
{%- comment -%} we found one! {%- endcomment -%}
|
||||||
|
{% assign applicable_subrecipes = true %}
|
||||||
|
{% break %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<h1>{{ page.name }}</h1>
|
||||||
|
<p> {{ page.method.size }} steps - Estimated cooking time: {{ page.time | default: "Not provided" }}</p>
|
||||||
|
{% if applicable_subrecipes %}
|
||||||
|
<h2> Subrecipes </h2>
|
||||||
|
{% for subrecipe in site.subrecipes %}
|
||||||
|
{% if subrecipe.parents contains id %}
|
||||||
|
<h3>{{ subrecipe.name }}</h3>
|
||||||
|
{{ subrecipe.output }}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% include ingredients.html %}
|
1
_layouts/subrecipe.html
Normal file
1
_layouts/subrecipe.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{% include ingredients.html %}
|
|
@ -2,4 +2,4 @@
|
||||||
title: Home
|
title: Home
|
||||||
layout: default
|
layout: default
|
||||||
---
|
---
|
||||||
henlo
|
{% include recipes.html %}
|
||||||
|
|
Loading…
Reference in a new issue