Masputrawae

Hugo • Partial Date Time

  1. Buat partials layouts/_partials/date-time.html
  2. Isi seperti berikut
    1{{- $getDate := .getDate }}
    2{{- $hummanDate := $getDate | time.Format "2006 Jan 02" }}
    3{{- $machineDate := $getDate | time.Format "2006-01-02T15:04:05-07:00" }}
    4
    5<time datetime="{{ $machineDate }}">{{ $hummanDate }}</time>
    
  3. Tinggal panggil jika dibutuhkan, Misa di page.html
    1{{ define "main" }}
    2<article>
    3	<h1>{{ .Title }}</h1>
    4	<p>PUBLISHED: {{ partial "date-time.html" (dict "getDate" .Date) }}</p>
    5	<p>UPDATED: {{ partial "date-time.html" (dict "getDate" .Lastmod) }}</p>
    6	{{ .Content }}
    7</article>
    8{{ end }}
    

Manfaat: