Skip to content

Instantly share code, notes, and snippets.

@bacor
Created August 20, 2021 08:05
Show Gist options
  • Save bacor/ac6a6c92ed5204a13ed3fe452d1a611d to your computer and use it in GitHub Desktop.
Save bacor/ac6a6c92ed5204a13ed3fe452d1a611d to your computer and use it in GitHub Desktop.
Jekyll/Liquid output a period/range
{%- assign start = include.start %}
{%- assign end = include.end %}
{%- assign startMonth = start | date: '%b' %}
{%- assign endMonth = end | date: '%b' %}
{%- assign sameMonthStartFmt = include.same_month_start_fmt | default: '%d' -%}
{%- assign sameMonthEndFmt = include.same_month_end_fmt | default: "%d %b '%y" -%}
{%- if startMonth == endMonth -%}
<time datetime="{{ start | date: '%Y-%m-%d' }}">
{{- start | date: sameMonthStartFmt -}}
</time>&ndash;<time datetime="{{ end | date: '%Y-%m-%d' }}">
{{- end | date: sameMonthEndFmt -}}
</time>
{%- else -%}
<time datetime="{{ start | date: '%Y-%m-%d' }}">
{{- start | date: '%d %b' -}}
</time>&ndash;{{--}}
<time datetime="{{ end | date: '%Y-%m-%d' }}">
{{- end | date: '%d %b %Y' -}}
</time>
{%- endif -%}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment