31 lines
1.2 KiB
HTML
31 lines
1.2 KiB
HTML
{%- 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 = "" -%}
|
|
|
|
{%- 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>
|
|
{%- endif -%}
|
|
{%- endif -%}
|