recipe-site/_includes/difficulty_stars.html

31 lines
1.2 KiB
HTML
Raw Normal View History

{%- if page.difficulty or recipe.difficulty -%}
{%- if page.difficulty -%}
{%- assign difficulty = page.difficulty -%}
{%- else -%}
{%- assign difficulty = recipe.difficulty -%}
{%- endif -%}
{%- if difficulty < 6 and 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 = "" -%}
2020-03-03 14:14:16 +00:00
{%- comment -%} build a string of empty stars {%- endcomment -%}
{%- assign stars = "" -%}
{%- for i in (1..5) -%}
{%- assign stars = stars | append: empty_star -%}
{%- endfor -%}
{%- comment -%} replace the first difficulty stars will filled stars {%- endcomment -%}
{%- assign page_stars_rounded = difficulty | floor -%}
{%- for i in (1..page_stars_rounded) -%}
{%- assign stars = stars | replace_first: empty_star, full_star -%}
{%- endfor -%}
{%- if difficulty != page_stars_rounded -%}
{%- comment -%} stars ends in .5 (or .1, or .9, or whatever) {%- endcomment -%}
{%- assign stars = stars | replace_first: empty_star, half_star -%}
{%- endif -%}
<span class='stars'>{{ stars }}</span>
2020-03-03 14:14:16 +00:00
{%- endif -%}
{%- endif -%}