theme: Use content adapter for news section

This commit is contained in:
Joe Mooring 2025-02-28 14:15:31 -08:00 committed by GitHub
parent 03938c600c
commit 8c059cbe14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 105 additions and 94 deletions

View File

@ -0,0 +1,30 @@
{{/* Get releases from GitHub. */}}
{{ $u := "https://api.github.com/repos/gohugoio/hugo/releases" }}
{{ $releases := partial "helpers/funcs/get-remote-data.html" $u }}
{{ $releases = where $releases "draft" false }}
{{ $releases = where $releases "prerelease" false }}
{{/* Add pages. */}}
{{ range $releases | first 20 }}
{{ $publishDate := .published_at | time.AsTime }}
{{/* Correct the v0.138.0 release date. See https://github.com/gohugoio/hugo/issues/13066. */}}
{{ if eq .name "v0.138.0" }}
{{ $publishDate = "2024-11-06T11:22:34Z" }}
{{ end }}
{{ $content := dict "mediaType" "text/markdown" "value" "" }}
{{ $dates := dict "publishDate" (time.AsTime $publishDate) }}
{{ $params := dict "permalink" .html_url }}
{{ $build := dict "render" "never" "list" "local" }}
{{ $page := dict
"build" $build
"content" $content
"dates" $dates
"kind" "page"
"params" $params
"path" .name
"title" (printf "Release %s" .name)
}}
{{ $.AddPage $page }}
{{ end }}

View File

@ -3,6 +3,7 @@ title: Glossary
description: Terms commonly used throughout the documentation.
categories: [quick-reference]
keywords: [glossary]
params:
hide_in_this_section: true
menu:
docs:

View File

@ -9,6 +9,21 @@ title = "Hugo"
# We do redirects via Netlify's _redirects file, generated by Hugo (see "outputs" below).
disableAliases = true
[cascade]
[cascade.params]
hide_in_this_section = true
show_publish_date = true
[cascade.target]
path = '{/news/**}'
kind = 'page'
[frontmatter]
date = ['date']
expiryDate = ['expirydate']
lastmod = [':git', 'lastmod', 'publishdate', 'date']
publishDate = ['publishdate', 'date']
[caches.images]
dir = ":cacheDir/images"
maxAge = "1440h"

View File

@ -1,15 +1,12 @@
{{ define "main" }}
{{ $pages := "" }}
{{ $showDate := false }}
{{ if .IsPage }}
{{/* We currently have a slightly odd content structure with no top level /docs section. */}}
{{ $pages = .CurrentSection.Pages }}
{{ else }}
{{ if eq .Section "news" }}
{{ $pages = partial "news/get-news-items.html" . }}
{{ $showDate = true }}
{{ else }}
{{ $pages = .Pages }}
{{ if eq .Section "news" }}
{{ $pages = $pages.ByPublishDate.Reverse }}
{{ end }}
{{ end }}
@ -23,13 +20,15 @@
{{ end }}
<a
class="flex col-span-1 a--block cursor-pointer flex-col group border p-3 sm:p-4 hover:shadow-md dark:shadow-slate-800 border-gray-300 dark:border-gray-800 m-0"
href="{{ .RelPermalink }}">
{{ if $showDate }}
href="{{ or .Params.permalink .RelPermalink }}">
{{ if .Params.show_publish_date }}
{{ with .PublishDate }}
<p
class="text-gray-500 dark:text-gray-400 text-sm/5 md:text-base/2 mb-2 sm:mb-4">
{{ .Date.Format "January 2, 2006" }}
{{ partial "layouts/date.html" . }}
</p>
{{ end }}
{{ end }}
<h3
class="text-lg/6 md:text-2xl tracking-tight p-0 -mt-1 sm:mt-0 mb-1 sm:mb-2 text-primary group-hover:text-primary/70 overflow-hidden">
{{ .LinkTitle }}

View File

@ -12,22 +12,20 @@
{{- with .OutputFormats.Get "rss" }}
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
{{- end }}
{{ $news_items := partial "news/get-news-items.html" . }}
{{- /* Sort, limit, and render lastBuildDate. */}}
{{- $limit := cond (gt site.Config.Services.RSS.Limit 1) site.Config.Services.RSS.Limit 999 }}
{{- $news_items = sort $news_items "PublishDate" "desc" | first $limit }}
<lastBuildDate>{{ (index $news_items 0).PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>
{{- /* Render items. */}}
{{- range $news_items }}
{{- $limit := cond (gt site.Config.Services.RSS.Limit 0) site.Config.Services.RSS.Limit 999 }}
{{- $pages := "" }}
{{- with site.GetPage "/news" }}
{{- $pages = .Pages.ByPublishDate.Reverse | first $limit }}
{{- else }}
{{- errorf "The list.rss.xml layout was unable to find the 'news' page." }}
{{- end }}
<lastBuildDate>{{ (index $pages 0).PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>
{{- range $pages }}
<item>
<title>{{ .Title }}</title>
<link>{{ .Permalink }}</link>
<link>{{ or .Params.permalink .Permalink }}</link>
<pubDate>{{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
<guid>{{ .Permalink }}</guid>
<guid>{{ or .Params.permalink .Permalink }}</guid>
<description>{{ .Summary | transform.XMLEscape | safeHTML }}</description>
</item>
{{- end }}

View File

@ -8,7 +8,14 @@
{{ . | markdownify }}
</div>
{{ end }}
{{ if .Params.show_publish_date }}
{{ with .PublishDate }}
<p
class="text-gray-500 dark:text-gray-400 text-sm/5 md:text-base/2 mb-2 sm:mb-4">
{{ partial "layouts/date.html" . }}
</p>
{{ end }}
{{ end }}
{{ $t := debug.Timer "single.categories" }}
{{ $categories := .GetTerms "categories" }}
{{ with $categories }}

View File

@ -0,0 +1,5 @@
{{ $humanDate := time.Format "January 2, 2006" . }}
{{ $machineDate := time.Format "2006-01-02T15:04:05-07:00" . }}
<time {{ printf "datetime=%q" $machineDate | safeHTMLAttr }}>
{{ $humanDate }}
</time>

View File

@ -14,6 +14,7 @@
</div>
{{ with .File }}
{{ if not .IsContentAdapter }}
{{ $href := printf "%sedit/master/content/%s/%s" site.Params.ghrepo $.Lang .Path }}
<a
href="{{ $href }}"
@ -21,4 +22,5 @@
Improve this page
</a>
{{ end }}
{{ end }}
</div>

View File

@ -1,4 +1,5 @@
{{ with .Fragments.Headings }}
{{ with .Fragments }}
{{ with .Headings }}
<div
x-data="toc"
class="sticky top-[8rem] h-screen overflow-y-auto overflow-x-hidden">
@ -13,6 +14,7 @@
</nav>
</div>
{{ end }}
{{ end }}
{{ define "render-toc-level" }}
{{ range .h }}

View File

@ -1,48 +0,0 @@
{{ $news_items := slice }}
{{/* Get releases from GitHub. */}}
{{ $u := "https://api.github.com/repos/gohugoio/hugo/releases" }}
{{ $releases := partial "helpers/funcs/get-remote-data.html" $u }}
{{ $releases = where $releases "draft" false }}
{{ $releases = where $releases "prerelease" false }}
{{ range $releases | first 20 }}
{{ $publishDate := .published_at | time.AsTime }}
{{/* Correct the v0.138.0 release date. See https://github.com/gohugoio/hugo/issues/13066. */}}
{{ if eq .name "v0.138.0" }}
{{ $publishDate = "2024-11-06T11:22:34Z" | time.AsTime }}
{{ end }}
{{ $ctx := dict
"Date" $publishDate
"LinkTitle" (printf "Release %s" .name)
"Permalink" .html_url
"PublishDate" $publishDate
"RelPermalink" .html_url
"Section" "news"
"Summary" ""
"Title" (printf "Release %s" .name)
}}
{{ $news_items = $news_items | append $ctx }}
{{ end }}
{{/* Get content pages from news section. */}}
{{ range where site.RegularPages "Section" "news" }}
{{ $ctx := dict
"Date" .Date
"LinkTitle" .Title
"Params" (dict "description" .Description)
"Permalink" .Permalink
"PublishDate" .PublishDate
"RelPermalink" .RelPermalink
"Section" "news"
"Summary" .Summary
"Title" .Title
}}
{{ $news_items = $news_items | append $ctx }}
{{ end }}
{{/* Sort by date in descending order. */}}
{{ $news_items = sort $news_items "Date" "desc" }}
{{ return $news_items }}