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
author: Jane Crocker
difficulty: 2
ingredients:
- [1, egg, null]
@ -47,6 +48,7 @@ time: 240
```
- `name` (string) - The displayed name of the recipe. Does not appear in the URL.
- `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:
- 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".
@ -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.
## 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/).
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 %}
{%- 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 %}
<h2> Subrecipes </h2>
{% 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;
}
.stars {
font-family: 'stars';
}
.ingredients li.optional::before {
content: "(Optional) ";
font-style: italic;
@ -169,3 +173,8 @@ footer, .subtle {
color: grey;
font-style: italic;
}
@font-face {
font-family: 'stars';
src: url("/assets/fonts/stars.woff") format("woff"), url("/assets/fonts/stars.woff2") format("woff2");
}