replace common decimals (.2, .3, etc) with fraction equivalents

This commit is contained in:
Lynne Megido 2020-03-05 23:30:17 +10:00
parent e36d23cb96
commit 1a3d058afc
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
4 changed files with 40 additions and 2 deletions

View file

@ -17,3 +17,15 @@ collections:
permalink: "/:collection/:name" permalink: "/:collection/:name"
recipes_per_page: 15 recipes_per_page: 15
fractions:
"1": "⅒"
"125": "⅛"
"2": "⅕"
"25": "¼"
"3": "⅓"
"4": "⅖"
"5": "½"
"6": "⅗"
"75": "¾"
"8": "⅘"

View file

@ -0,0 +1,14 @@
{%- assign decimal = input | split: "." | last -%}
{%- assign output = input -%}
{%- assign item_split = input | split: "" -%}
{%- if item_split contains "." -%}
{%- if site.fractions contains decimal -%}
{%- assign prefix = input | split: "." | first -%}
{%- if prefix == "0" -%}
{%- assign output = site.fractions[decimal] -%}
{%- else -%}
{%- assign output = prefix | append: site.fractions[decimal] -%}
{%- endif -%}
{%- endif -%}
{%- endif -%}

View file

@ -10,10 +10,21 @@
{%- assign tag = tag | append: " class='optional'" -%} {%- assign tag = tag | append: " class='optional'" -%}
{%- endif -%} {%- endif -%}
{%- assign amount = item[0] | append: " " -%} {%- assign input = item[0] -%}
{%- include fractionalise.html -%}
{%- assign amount = output | append: " " -%}
{%- assign end = "" -%} {%- assign end = "" -%}
{%- if item[0][0] -%} {%- if item[0][0] -%}
{%- assign amount = item[0][0] | append: " to " | append: item[0][1] | append: " " -%} {%- assign input = item[0][0] -%}
{%- include fractionalise.html -%}
{%- assign from = output -%}
{%- assign input = item[0][1] -%}
{%- include fractionalise.html -%}
{%- assign to = output -%}
{%- assign amount = from | append: " to " | append: to | append: " " -%}
{%- elsif item[0] == 0 -%} {%- elsif item[0] == 0 -%}
{%- assign amount = "" -%} {%- assign amount = "" -%}
{%- assign end = " to taste" -%} {%- assign end = " to taste" -%}

View file

@ -11,6 +11,7 @@ body {
margin: 0; margin: 0;
} }
#main { #main {
width: 80%;
max-width: 1500px; max-width: 1500px;
flex-grow: 1; flex-grow: 1;
margin: 0 auto; margin: 0 auto;