mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-14 07:34:44 -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,7 +3,8 @@ title: Glossary
|
|||||||
description: Terms commonly used throughout the documentation.
|
description: Terms commonly used throughout the documentation.
|
||||||
categories: [quick-reference]
|
categories: [quick-reference]
|
||||||
keywords: [glossary]
|
keywords: [glossary]
|
||||||
hide_in_this_section: true
|
params:
|
||||||
|
hide_in_this_section: true
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: quick-reference
|
parent: quick-reference
|
||||||
|
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).
|
# We do redirects via Netlify's _redirects file, generated by Hugo (see "outputs" below).
|
||||||
disableAliases = true
|
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]
|
[caches.images]
|
||||||
dir = ":cacheDir/images"
|
dir = ":cacheDir/images"
|
||||||
maxAge = "1440h"
|
maxAge = "1440h"
|
||||||
|
@ -1,15 +1,12 @@
|
|||||||
{{ define "main" }}
|
{{ define "main" }}
|
||||||
{{ $pages := "" }}
|
{{ $pages := "" }}
|
||||||
{{ $showDate := false }}
|
|
||||||
{{ if .IsPage }}
|
{{ if .IsPage }}
|
||||||
{{/* We currently have a slightly odd content structure with no top level /docs section. */}}
|
{{/* We currently have a slightly odd content structure with no top level /docs section. */}}
|
||||||
{{ $pages = .CurrentSection.Pages }}
|
{{ $pages = .CurrentSection.Pages }}
|
||||||
{{ else }}
|
{{ else }}
|
||||||
|
{{ $pages = .Pages }}
|
||||||
{{ if eq .Section "news" }}
|
{{ if eq .Section "news" }}
|
||||||
{{ $pages = partial "news/get-news-items.html" . }}
|
{{ $pages = $pages.ByPublishDate.Reverse }}
|
||||||
{{ $showDate = true }}
|
|
||||||
{{ else }}
|
|
||||||
{{ $pages = .Pages }}
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
@ -23,12 +20,14 @@
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
<a
|
<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"
|
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 }}">
|
href="{{ or .Params.permalink .RelPermalink }}">
|
||||||
{{ if $showDate }}
|
{{ if .Params.show_publish_date }}
|
||||||
<p
|
{{ with .PublishDate }}
|
||||||
class="text-gray-500 dark:text-gray-400 text-sm/5 md:text-base/2 mb-2 sm:mb-4">
|
<p
|
||||||
{{ .Date.Format "January 2, 2006" }}
|
class="text-gray-500 dark:text-gray-400 text-sm/5 md:text-base/2 mb-2 sm:mb-4">
|
||||||
</p>
|
{{ partial "layouts/date.html" . }}
|
||||||
|
</p>
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<h3
|
<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">
|
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">
|
||||||
|
@ -12,22 +12,20 @@
|
|||||||
{{- with .OutputFormats.Get "rss" }}
|
{{- with .OutputFormats.Get "rss" }}
|
||||||
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
|
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- $limit := cond (gt site.Config.Services.RSS.Limit 0) site.Config.Services.RSS.Limit 999 }}
|
||||||
|
{{- $pages := "" }}
|
||||||
{{ $news_items := partial "news/get-news-items.html" . }}
|
{{- with site.GetPage "/news" }}
|
||||||
|
{{- $pages = .Pages.ByPublishDate.Reverse | first $limit }}
|
||||||
{{- /* Sort, limit, and render lastBuildDate. */}}
|
{{- else }}
|
||||||
{{- $limit := cond (gt site.Config.Services.RSS.Limit 1) site.Config.Services.RSS.Limit 999 }}
|
{{- errorf "The list.rss.xml layout was unable to find the 'news' page." }}
|
||||||
{{- $news_items = sort $news_items "PublishDate" "desc" | first $limit }}
|
{{- end }}
|
||||||
<lastBuildDate>{{ (index $news_items 0).PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>
|
<lastBuildDate>{{ (index $pages 0).PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>
|
||||||
|
{{- range $pages }}
|
||||||
{{- /* Render items. */}}
|
|
||||||
{{- range $news_items }}
|
|
||||||
<item>
|
<item>
|
||||||
<title>{{ .Title }}</title>
|
<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>
|
<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>
|
<description>{{ .Summary | transform.XMLEscape | safeHTML }}</description>
|
||||||
</item>
|
</item>
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
@ -8,7 +8,14 @@
|
|||||||
{{ . | markdownify }}
|
{{ . | markdownify }}
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ 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" }}
|
{{ $t := debug.Timer "single.categories" }}
|
||||||
{{ $categories := .GetTerms "categories" }}
|
{{ $categories := .GetTerms "categories" }}
|
||||||
{{ with $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,11 +14,13 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ with .File }}
|
{{ with .File }}
|
||||||
{{ $href := printf "%sedit/master/content/%s/%s" site.Params.ghrepo $.Lang .Path }}
|
{{ if not .IsContentAdapter }}
|
||||||
<a
|
{{ $href := printf "%sedit/master/content/%s/%s" site.Params.ghrepo $.Lang .Path }}
|
||||||
href="{{ $href }}"
|
<a
|
||||||
class="mt-4 inline-block not-prose bg-blue-600 hover:bg-blue-800 text-white hover:text-white font-bold py-2 px-4 rounded">
|
href="{{ $href }}"
|
||||||
Improve this page
|
class="mt-4 inline-block not-prose bg-blue-600 hover:bg-blue-800 text-white hover:text-white font-bold py-2 px-4 rounded">
|
||||||
</a>
|
Improve this page
|
||||||
|
</a>
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
{{ with .Fragments.Headings }}
|
{{ with .Fragments }}
|
||||||
<div
|
{{ with .Headings }}
|
||||||
x-data="toc"
|
<div
|
||||||
class="sticky top-[8rem] h-screen overflow-y-auto overflow-x-hidden">
|
x-data="toc"
|
||||||
<h2
|
class="sticky top-[8rem] h-screen overflow-y-auto overflow-x-hidden">
|
||||||
class="text-base font-semibold tracking-tight text-gray-600 dark:text-gray-400">
|
<h2
|
||||||
On this page
|
class="text-base font-semibold tracking-tight text-gray-600 dark:text-gray-400">
|
||||||
</h2>
|
On this page
|
||||||
<nav class="w-56 mt-2">
|
</h2>
|
||||||
<ul>
|
<nav class="w-56 mt-2">
|
||||||
{{ template "render-toc-level" (dict "h" . "p" $) }}
|
<ul>
|
||||||
</ul>
|
{{ template "render-toc-level" (dict "h" . "p" $) }}
|
||||||
</nav>
|
</ul>
|
||||||
</div>
|
</nav>
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ define "render-toc-level" }}
|
{{ define "render-toc-level" }}
|
||||||
|
@ -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