mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-14 12:04:57 -04:00
theme: Use content adapter for news section
This commit is contained in:
parent
03938c600c
commit
8c059cbe14
30
content/en/news/_content.gotmpl
Normal file
30
content/en/news/_content.gotmpl
Normal 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 }}
|
@ -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:
|
||||
|
15
hugo.toml
15
hugo.toml
@ -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"
|
||||
|
@ -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 }}
|
||||
|
@ -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 }}
|
||||
|
@ -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 }}
|
||||
|
5
layouts/partials/layouts/date.html
Normal file
5
layouts/partials/layouts/date.html
Normal 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>
|
@ -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>
|
||||
|
@ -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 }}
|
||||
|
@ -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 }}
|
Loading…
x
Reference in New Issue
Block a user