inline_links partial

finally find a way to determine whether a section/term page has archives or not
by conquering hugo's faultiness of .RelPermalink
This commit is contained in:
Reorx 2022-09-08 23:17:43 +08:00
parent ae58c91ac4
commit 886aafac1f
5 changed files with 31 additions and 17 deletions

View File

@ -100,6 +100,12 @@ mark {
box-shadow: var(--link-hover-underline-shadow);
}
.inline-links span:not(:last-of-type):after {
content: "·";
margin-inline-start: .5em;
margin-inline-end: .5em;
}
/* for post page */
.main.post {
@ -108,6 +114,8 @@ mark {
.page-header h1 {
font-size: 40px;
margin-bottom: var(--content-gap);
text-transform: capitalize;
}
.pagination {

View File

@ -0,0 +1,5 @@
---
title: "Docs Archives"
layout: archives
hidden: true
---

View File

@ -7,20 +7,17 @@
{{- if not .IsHome | and .Title }}
<header class="page-header">
{{- partial "breadcrumbs.html" . }}
<h1>{{ .Title }}</h1>
<h1>
{{/* see: https://gohugo.io/variables/taxonomy/#taxonomy-terms-page-variables */}}
{{- if eq .Kind "term" -}}{{- .Data.Singular }}: {{ end -}}
{{ .Title -}}
</h1>
{{- if .Description }}
<div class="post-description">
{{ .Description | markdownify }}
</div>
{{- end }}
<div class="inline-links">
{{- with .Param "archivesSlug" }}
<a href="{{ $.RelPermalink }}{{ . }}/">Archives</a>
{{- end }}
{{ with .OutputFormats.Get "rss" -}}
<a href="{{ .Permalink }}" target="_blank">RSS</a>
{{ end -}}
</div>
{{- partial "inline_links.html" . -}}
</header>
{{- end }}

View File

@ -37,14 +37,7 @@
{{ end }}
<h2>相关链接</h2>
<div class="inline-links">
{{- with .Param "archivesSlug" }}
<a href="{{ $.RelPermalink }}{{ . }}/">Archives</a>
{{- end }}
{{ with .OutputFormats.Get "rss" -}}
<a href="{{ .Permalink }}" target="_blank">RSS</a>
{{ end -}}
</div>
{{- partial "inline_links.html" . -}}
</div>
{{ end }}

View File

@ -0,0 +1,11 @@
<div class="inline-links">
{{/* use `.GetPage "archives"` causes term page to get the root archives */}}
{{/* trim relURL prefix because .RelPermalink includes the path of base url */}}
{{ $archivesPath := printf "/%sarchives" (strings.TrimPrefix (relURL "") .RelPermalink) }}
{{- with .GetPage $archivesPath -}}
<span><a href="{{ .RelPermalink }}">Archives</a></span>
{{- end -}}
{{- with .OutputFormats.Get "rss" -}}
<span><a href="{{ .Permalink }}" target="_blank">RSS</a></span>
{{- end -}}
</div>