diff options
author | jeffreytse <jeffreytse.mail@gmail.com> | 2021-06-25 14:13:00 +0800 |
---|---|---|
committer | jeffreytse <jeffreytse.mail@gmail.com> | 2021-06-25 14:13:00 +0800 |
commit | 245fe2a0479819543e3f71499daada138c43377c (patch) | |
tree | fb8f70cf37277c9a7ae1652490e41964b786dd65 /_includes/functions/get_value.html | |
parent | 0a863ba18acbdc600b1f751dc9e12e032d7d8965 (diff) |
fix: get value from site config incorrectly
When the value is stored in a dictionary and the value isn't
presented in front matter, the get_value function can not get
value from the site config instead.
Diffstat (limited to '_includes/functions/get_value.html')
-rw-r--r-- | _includes/functions/get_value.html | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/_includes/functions/get_value.html b/_includes/functions/get_value.html index bbd1815..6d9ac81 100644 --- a/_includes/functions/get_value.html +++ b/_includes/functions/get_value.html @@ -2,31 +2,41 @@ {%- assign name = include.params.name -%} {%- endif -%} +{%- assign return = nil -%} + {%- assign keys = name | split:'.' -%} {%- assign name = keys.first -%} +{%- assign keys = keys | shift -%} -{%- if page[name] != nil -%} - {%- assign return = page[name] -%} -{%- elsif site[name] != nil -%} - {%- assign return = site[name] -%} -{%- elsif site.data[name] != nil -%} - {%- assign return = site.data[name] -%} -{%- elsif site.defaults[page.layout][name] != nil -%} - {%- assign return = site.defaults[page.layout][name] -%} -{%- elsif site.data.defaults[page.layout][name] != nil -%} - {%- assign return = site.data.defaults[page.layout][name] -%} -{%- elsif layout[name] != nil -%} - {%- assign return = layout[name] -%} -{%- else -%} - {%- assign return = include.params.default -%} -{%- endif -%} +{%- for step in (1..7) -%} -{%- assign keys = keys | shift -%} -{%- for key in keys -%} - {%- assign return = return[key] -%} - {%- if return == nil -%} - {%- assign return = include.params.default -%} + {%- case step -%} + {%- when 1 -%} + {%- assign return = page[name] -%} + {%- when 2 -%} + {%- assign return = site[name] -%} + {%- when 3 -%} + {%- assign return = site.data[name] -%} + {%- when 4 -%} + {%- assign return = site.defaults[page.layout][name] -%} + {%- when 5 -%} + {%- assign return = site.data.defaults[page.layout][name] -%} + {%- when 6 -%} + {%- assign return = layout[name] -%} + {%- else -%} + {%- assign return = include.params.default -%} + {%- endcase -%} + + {%- for key in keys -%} + {%- assign return = return[key] -%} + {%- if return == nil -%} + {%- break -%} + {%- endif -%} + {%- endfor -%} + + {%- if return != nil -%} {%- break -%} {%- endif -%} + {%- endfor -%} |