diff options
author | Derek Severin <severinderek@gmail.com> | 2021-08-28 14:59:44 +0300 |
---|---|---|
committer | Derek Severin <severinderek@gmail.com> | 2021-08-28 14:59:44 +0300 |
commit | b097f85fe06269217af1d5cdac26f81bd2fbcf0e (patch) | |
tree | f7af272b0fc56dbaeae0eb5a78cf4f29f8fa7a70 | |
parent | b2f501df6e9a4998420354a12a0911b226cbee18 (diff) |
Time duration as partial
-rw-r--r-- | layouts/_default/limage.html | 26 | ||||
-rw-r--r-- | layouts/partials/pages/title.html | 26 | ||||
-rw-r--r-- | layouts/partials/time-period.html | 30 |
3 files changed, 32 insertions, 50 deletions
diff --git a/layouts/_default/limage.html b/layouts/_default/limage.html index daded4a..d60acc1 100644 --- a/layouts/_default/limage.html +++ b/layouts/_default/limage.html @@ -40,31 +40,7 @@ {{ end }} {{ if .Params.startDate }} <div class="project-date"> - {{/* TODO: rewrite shorter/cleaner */}} - {{ $start := dateFormat .Site.Params.projects.date_format .Params.startDate }} - {{ $period := "" }} - {{ if .Site.Params.projects.period_format }} - {{ if .Params.endDate }} - {{ $end := dateFormat .Site.Params.projects.date_format .Params.endDate }} - {{ $period = replace .Site.Params.projects.period_format "{start}" $start }} - {{ $period = replace $period "{end}" $end }} - {{ else }} - {{ if .Site.Params.projects.period_format_startonly }} - {{ $period = replace .Site.Params.projects.period_format_startonly "{start}" $start }} - {{ else }} - {{ $period = replace .Site.Params.projects.period_format "{start}" $start }} - {{ $period = replace $period "{end}" "..." }} - {{ end }} - {{ end }} - {{ else }} - {{ if .Params.endDate }} - {{ $end := dateFormat .Site.Params.projects.date_format .Params.endDate }} - {{ $period = print "From " $start " to " $end }} - {{ else }} - {{ $period = print "From " $start }} - {{ end }} - {{ end }} - {{ $period }} + {{ partial "time-period.html" (dict "startDate" .Params.startDate "endDate" .Params.endDate) }} </div> {{ end }} </div> diff --git a/layouts/partials/pages/title.html b/layouts/partials/pages/title.html index 16ff432..d2b96e5 100644 --- a/layouts/partials/pages/title.html +++ b/layouts/partials/pages/title.html @@ -10,31 +10,7 @@ {{/* Period */}} {{ if .Params.startDate }} <h3> - {{/* TODO: make partial + rewrite shorter/cleaner */}} - {{ $start := dateFormat .Site.Params.projects.date_format .Params.startDate }} - {{ $period := "" }} - {{ if .Site.Params.projects.period_format }} - {{ if .Params.endDate }} - {{ $end := dateFormat .Site.Params.projects.date_format .Params.endDate }} - {{ $period = replace .Site.Params.projects.period_format "{start}" $start }} - {{ $period = replace $period "{end}" $end }} - {{ else }} - {{ if .Site.Params.projects.period_format_startonly }} - {{ $period = replace .Site.Params.projects.period_format_startonly "{start}" $start }} - {{ else }} - {{ $period = replace .Site.Params.projects.period_format "{start}" $start }} - {{ $period = replace $period "{end}" "..." }} - {{ end }} - {{ end }} - {{ else }} - {{ if .Params.endDate }} - {{ $end := dateFormat .Site.Params.projects.date_format .Params.endDate }} - {{ $period = print "From " $start " to " $end }} - {{ else }} - {{ $period = print "From " $start }} - {{ end }} - {{ end }} - {{ $period }} + {{ partial "time-period.html" (dict "startDate" .Params.startDate "endDate" .Params.endDate) }} {{/* Duration */}} {{ $end := now }} diff --git a/layouts/partials/time-period.html b/layouts/partials/time-period.html new file mode 100644 index 0000000..bcbb165 --- /dev/null +++ b/layouts/partials/time-period.html @@ -0,0 +1,30 @@ +{{/* + Parameters: + - startDate: Start date of period + - endDate: End date of period +*/}} +{{/* TODO: rewrite shorter/cleaner */}} +{{ $start := dateFormat site.Params.projects.date_format .startDate }} +{{ $period := "" }} +{{ if site.Params.projects.period_format }} + {{ if .endDate }} + {{ $end := dateFormat site.Params.projects.date_format .endDate }} + {{ $period = replace site.Params.projects.period_format "{start}" $start }} + {{ $period = replace $period "{end}" $end }} + {{ else }} + {{ if site.Params.projects.period_format_startonly }} + {{ $period = replace site.Params.projects.period_format_startonly "{start}" $start }} + {{ else }} + {{ $period = replace site.Params.projects.period_format "{start}" $start }} + {{ $period = replace $period "{end}" "..." }} + {{ end }} + {{ end }} +{{ else }} + {{ if .endDate }} + {{ $end := dateFormat site.Params.projects.date_format .endDate }} + {{ $period = print "From " $start " to " $end }} + {{ else }} + {{ $period = print "From " $start }} + {{ end }} +{{ end }} +{{ $period }}
\ No newline at end of file |