recipe-site/_includes/difficulty_stars.html

23 lines
1.1 KiB
HTML
Raw Normal View History

2020-03-03 14:14:16 +00:00
{%- 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 -%}