added recipe difficulty tag

This commit is contained in:
Lynne Megido 2020-03-04 00:14:16 +10:00
parent b2007bfc66
commit 0d2af3e218
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
6 changed files with 37 additions and 1 deletions

View file

@ -32,6 +32,7 @@ Here's an example recipe, which could be saved to `_recipes/chocolate_cake.md`:
--- ---
name: Chocolate cake name: Chocolate cake
author: Jane Crocker author: Jane Crocker
difficulty: 2
ingredients: ingredients:
- [1, egg, null] - [1, egg, null]
@ -47,6 +48,7 @@ time: 240
``` ```
- `name` (string) - The displayed name of the recipe. Does not appear in the URL. - `name` (string) - The displayed name of the recipe. Does not appear in the URL.
- `author` (string, optional) - The author of the recipe. - `author` (string, optional) - The author of the recipe.
- `difficulty` (float, optional) - The difficulty of the recipe on a scale of 1 to 5. Will be displayed as a star rating. Half stars (e.g. "2.5") are allowed.
- `ingredients` (list) - Each entry in `ingredients` is an array consisting of up to four items: - `ingredients` (list) - Each entry in `ingredients` is an array consisting of up to four items:
- amount (number or array) - The amount of this item to add, e.g. `2` for 2 cups of flour. - amount (number or array) - The amount of this item to add, e.g. `2` for 2 cups of flour.
- If this is `0`, the output will be e.g. "jalepeño chillis to taste" rather than "0 jalepeño chillis". - If this is `0`, the output will be e.g. "jalepeño chillis to taste" rather than "0 jalepeño chillis".
@ -94,6 +96,8 @@ The entries in `parents` refer to the filenames of the parent recipes - `chocola
If a subrecipe does not have at least one valid `parents` entry, it will not appear anywhere on the website. If a subrecipe does not have at least one valid `parents` entry, it will not appear anywhere on the website.
## Licensing ## Licensing
This software makes use of a subset of Font Awesome v4.7.0, which is licensed under the [SIL](https://scripts.sil.org/OFL_web).
This software is licensed under the [Apache 2.0 license](https://choosealicense.com/licenses/apache-2.0/). This software is licensed under the [Apache 2.0 license](https://choosealicense.com/licenses/apache-2.0/).
Copyright 2020 Lynnesbian Copyright 2020 Lynnesbian

View file

@ -0,0 +1,22 @@
{%- if page.difficulty < 6 and page.difficulty > 0 -%}
{%- comment -%} note: these characters are invalid unicode. they will only render properly on the webpage using the bundled "stars" font. {%- endcomment -%}
{%- assign empty_star ="" -%}
{%- assign full_star = "" -%}
{%- assign half_star = "" -%}
{%- comment -%} build a string of empty stars {%- endcomment -%}
{%- assign difficulty = "" -%}
{%- for i in (1..5) -%}
{%- assign difficulty = difficulty | append: empty_star -%}
{%- endfor -%}
{%- comment -%} replace the first page.difficulty stars will filled stars {%- endcomment -%}
{%- assign page_difficulty_rounded = page.difficulty | floor -%}
{%- for i in (1..page_difficulty_rounded) -%}
{%- assign difficulty = difficulty | replace_first: empty_star, full_star -%}
{%- endfor -%}
{%- if page.difficulty != page_difficulty_rounded -%}
{%- comment -%} difficulty ends in .5 (or .1, or .9, or whatever) {%- endcomment -%}
{%- assign difficulty = difficulty | replace_first: empty_star, half_star -%}
{%- endif -%}
<span class='stars'>{{ difficulty }}</span>
{%- endif -%}

View file

@ -29,7 +29,8 @@ layout: default
{%- assign time = page.time %} {%- assign time = page.time %}
{%- endif -%} {%- endif -%}
{%- endif -%} {%- endif -%}
<p class='subtle'> {{ page.method.size }} steps - Estimated cooking time: {{ time | default: "Not provided" }} {% if page.author %} - By {{ page.author }} {% endif %}</p>
<p class='subtle'>{% if page.difficulty %}Difficulty: {% include difficulty_stars.html %} - {% endif %}{{ page.method.size }} steps - Estimated cooking time: {{ time | default: "Not provided" }} {% if page.author %} - By {{ page.author }} {% endif %}</p>
{%- if applicable_subrecipes %} {%- if applicable_subrecipes %}
<h2> Subrecipes </h2> <h2> Subrecipes </h2>
{% for subrecipe in site.subrecipes -%} {% for subrecipe in site.subrecipes -%}

BIN
assets/fonts/stars.woff Normal file

Binary file not shown.

BIN
assets/fonts/stars.woff2 Normal file

Binary file not shown.

View file

@ -46,6 +46,10 @@ h4 {
margin: 0.75em 0; margin: 0.75em 0;
} }
.stars {
font-family: 'stars';
}
.ingredients li.optional::before { .ingredients li.optional::before {
content: "(Optional) "; content: "(Optional) ";
font-style: italic; font-style: italic;
@ -169,3 +173,8 @@ footer, .subtle {
color: grey; color: grey;
font-style: italic; font-style: italic;
} }
@font-face {
font-family: 'stars';
src: url("/assets/fonts/stars.woff") format("woff"), url("/assets/fonts/stars.woff2") format("woff2");
}