From 451f6afeb412ecbbd507cb8cc034728ff3e8d2c5 Mon Sep 17 00:00:00 2001 From: Lynne Date: Sun, 1 Mar 2020 04:05:06 +1000 Subject: [PATCH] render recipes with embedded subrecipes, print some meta information, etc --- .gitignore | 2 +- _config.yml | 6 ++++++ _includes/ingredients.html | 10 ++++++++++ _includes/recipes.html | 5 +++++ _layouts/recipe.html | 28 ++++++++++++++++++++++++++++ _layouts/subrecipe.html | 1 + index.html | 2 +- 7 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 _config.yml create mode 100644 _includes/ingredients.html create mode 100644 _includes/recipes.html create mode 100644 _layouts/recipe.html create mode 100644 _layouts/subrecipe.html diff --git a/.gitignore b/.gitignore index e11d599..274b281 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ _site _recipes +_subrecipes .sass-cache .jekyll-cache .jekyll-metadata vendor -_config.yml diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..2497de7 --- /dev/null +++ b/_config.yml @@ -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 diff --git a/_includes/ingredients.html b/_includes/ingredients.html new file mode 100644 index 0000000..16d1c67 --- /dev/null +++ b/_includes/ingredients.html @@ -0,0 +1,10 @@ +{% assign tag = "h2" %} +{% if page.collection == "subrecipes" %} + {% assign tag = "h4" %} +{% endif %} +<{{tag}}>Ingredients + diff --git a/_includes/recipes.html b/_includes/recipes.html new file mode 100644 index 0000000..048d715 --- /dev/null +++ b/_includes/recipes.html @@ -0,0 +1,5 @@ + diff --git a/_layouts/recipe.html b/_layouts/recipe.html new file mode 100644 index 0000000..9534880 --- /dev/null +++ b/_layouts/recipe.html @@ -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 %} + +

{{ page.name }}

+

{{ page.method.size }} steps - Estimated cooking time: {{ page.time | default: "Not provided" }}

+{% if applicable_subrecipes %} +

Subrecipes

+ {% for subrecipe in site.subrecipes %} + {% if subrecipe.parents contains id %} +

{{ subrecipe.name }}

+ {{ subrecipe.output }} + {% endif %} + {% endfor %} +{% endif %} + +{% include ingredients.html %} diff --git a/_layouts/subrecipe.html b/_layouts/subrecipe.html new file mode 100644 index 0000000..15c3c52 --- /dev/null +++ b/_layouts/subrecipe.html @@ -0,0 +1 @@ +{% include ingredients.html %} diff --git a/index.html b/index.html index 3ed15d0..649c795 100644 --- a/index.html +++ b/index.html @@ -2,4 +2,4 @@ title: Home layout: default --- -henlo +{% include recipes.html %}