diff --git a/layouts/index.json b/layouts/index.json index 3938177a8603..1ab851ac82e2 100644 --- a/layouts/index.json +++ b/layouts/index.json @@ -7,6 +7,10 @@ {{- end -}} {{- if ne $page.File nil -}} + {{- $date := "" -}} + {{- if and (eq $page.Section "blog") (not $page.Date.IsZero) -}} + {{- $date = $page.Date.Format "Jan 2, 2006" -}} + {{- end -}} {{- $index = $index | append ( dict @@ -16,6 +20,7 @@ "href" $page.RelPermalink "params" $page.Params "kind" $page.Kind + "date" $date "ancestors" (after 1 $ancestors) ) -}} diff --git a/scripts/search/page.js b/scripts/search/page.js index 28e39fa74b30..b6303d450d1e 100644 --- a/scripts/search/page.js +++ b/scripts/search/page.js @@ -122,6 +122,7 @@ module.exports = { description: item.params.meta_desc, href: item.href, authors: item.params.authors, + date: item.date || undefined, tags: item.params.tags, rank: this.getRank(item), boosted: this.isBoosted(item), diff --git a/theme/src/scss/_algolia.scss b/theme/src/scss/_algolia.scss index 31312beb4bcc..718a568a11a5 100644 --- a/theme/src/scss/_algolia.scss +++ b/theme/src/scss/_algolia.scss @@ -158,6 +158,11 @@ .description { @apply text-xs text-gray-800 leading-relaxed; } + + .date { + @apply text-gray-600 -mt-1 mb-3; + font-size: 0.6875rem; + } } } diff --git a/theme/src/ts/algolia/autocomplete.ts b/theme/src/ts/algolia/autocomplete.ts index 6cbe2670935d..5b50b9c63445 100644 --- a/theme/src/ts/algolia/autocomplete.ts +++ b/theme/src/ts/algolia/autocomplete.ts @@ -9,6 +9,7 @@ interface SearchResultHit { ancestors?: string[]; h1?: string; title: string; + date?: string; } // CSS selector of the element to convert into an autocomplete control. @@ -242,6 +243,9 @@ function initAutocomplete(el: HTMLElement) { ${ labelForTag(item.section) } + ${ item.date + ? html`