diff --git a/README.md b/README.md index dad0915..fce10ec 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/_includes/difficulty_stars.html b/_includes/difficulty_stars.html new file mode 100644 index 0000000..6de745f --- /dev/null +++ b/_includes/difficulty_stars.html @@ -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 -%} + {{ difficulty }} +{%- endif -%} diff --git a/_layouts/recipe.html b/_layouts/recipe.html index dab63da..485530a 100644 --- a/_layouts/recipe.html +++ b/_layouts/recipe.html @@ -29,7 +29,8 @@ layout: default {%- assign time = page.time %} {%- endif -%} {%- endif -%} -

{{ page.method.size }} steps - Estimated cooking time: {{ time | default: "Not provided" }} {% if page.author %} - By {{ page.author }} {% endif %}

+ +

{% 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 %}

{%- if applicable_subrecipes %}

Subrecipes

{% for subrecipe in site.subrecipes -%} diff --git a/assets/fonts/stars.woff b/assets/fonts/stars.woff new file mode 100644 index 0000000..c79c54a Binary files /dev/null and b/assets/fonts/stars.woff differ diff --git a/assets/fonts/stars.woff2 b/assets/fonts/stars.woff2 new file mode 100644 index 0000000..84bc224 Binary files /dev/null and b/assets/fonts/stars.woff2 differ diff --git a/assets/style.css b/assets/style.css index f0464c6..4d32097 100644 --- a/assets/style.css +++ b/assets/style.css @@ -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"); +}