adds related articles to single article view
This commit is contained in:
parent
ed3fc0545c
commit
8d4b1bb7f0
3 changed files with 107 additions and 0 deletions
|
@ -107,3 +107,24 @@ page = [ "HTML" ]
|
||||||
taxonomy = [ "HTML" ]
|
taxonomy = [ "HTML" ]
|
||||||
#taxonomyTerm = [ "HTML" ]
|
#taxonomyTerm = [ "HTML" ]
|
||||||
|
|
||||||
|
[related]
|
||||||
|
includeNewer = true
|
||||||
|
threshold = 80
|
||||||
|
toLower = false
|
||||||
|
|
||||||
|
[[related.indices]]
|
||||||
|
name = "title"
|
||||||
|
weight = 30
|
||||||
|
|
||||||
|
[[related.indices]]
|
||||||
|
name = "summary"
|
||||||
|
weight = 30
|
||||||
|
|
||||||
|
[[related.indices]]
|
||||||
|
name = "tags"
|
||||||
|
weight = 30
|
||||||
|
|
||||||
|
[[related.indices]]
|
||||||
|
name = "date"
|
||||||
|
weight = 10
|
||||||
|
|
||||||
|
|
75
layouts/_default/single.html
Normal file
75
layouts/_default/single.html
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
{{ define "main" }}
|
||||||
|
{{- $images := .Resources.ByType "image" }}
|
||||||
|
{{- $cover := $images.GetMatch (.Params.cover | default "*cover*") }}
|
||||||
|
{{- $feature := $images.GetMatch (.Params.feature | default "*feature*") | default $cover }}
|
||||||
|
<article>
|
||||||
|
<header class="max-w-prose">
|
||||||
|
{{ if .Params.showBreadcrumbs | default (.Site.Params.article.showBreadcrumbs | default false) }}
|
||||||
|
{{ partial "breadcrumbs.html" . }}
|
||||||
|
{{ end }}
|
||||||
|
<h1 class="mb-8 mt-0 text-4xl font-extrabold text-neutral-900 dark:text-neutral">
|
||||||
|
{{ .Title | emojify }}
|
||||||
|
</h1>
|
||||||
|
{{ if or
|
||||||
|
(.Params.showDate | default (.Site.Params.article.showDate | default true))
|
||||||
|
(and (.Params.showDateUpdated | default (.Site.Params.article.showDateUpdated | default false)) (ne (partial "functions/date.html" .Date) (partial "functions/date.html" .Lastmod)))
|
||||||
|
(and (.Params.showWordCount | default (.Site.Params.article.showWordCount | default false)) (ne .WordCount 0))
|
||||||
|
(and (.Params.showReadingTime | default (.Site.Params.article.showReadingTime | default true)) (ne .ReadingTime 0))
|
||||||
|
(.Params.showEdit | default (.Site.Params.article.showEdit | default false))
|
||||||
|
}}
|
||||||
|
<div class="mb-10 text-base text-neutral-500 dark:text-neutral-400 print:hidden">
|
||||||
|
{{ partial "article-meta.html" (dict "context" . "scope" "single") }}
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
|
{{ with $feature }}
|
||||||
|
<div class="prose">
|
||||||
|
{{ $altText := $.Params.featureAlt | default $.Params.coverAlt | default "" }}
|
||||||
|
{{ $class := "mb-6 rounded-md" }}
|
||||||
|
{{ $webp := $.Page.Site.Params.enableImageWebp | default true }}
|
||||||
|
{{ partial "picture.html" (dict "img" . "alt" $altText "class" $class "lazy" false "webp" $webp) }}
|
||||||
|
{{ with $.Params.coverCaption }}
|
||||||
|
<figcaption class="-mt-3 mb-6 text-center">{{ . | markdownify }}</figcaption>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
|
</header>
|
||||||
|
<section class="prose mt-0 flex max-w-full flex-col dark:prose-invert lg:flex-row">
|
||||||
|
{{ if and (.Params.showTableOfContents | default (.Site.Params.article.showTableOfContents | default false)) (in .TableOfContents "<ul") }}
|
||||||
|
<div class="order-first px-0 lg:order-last lg:max-w-xs lg:ps-8">
|
||||||
|
<div class="toc pe-5 lg:sticky lg:top-10 print:hidden">
|
||||||
|
{{ partial "toc.html" . }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
|
<div class="min-h-0 min-w-0 max-w-prose grow">
|
||||||
|
{{ .Content | emojify }}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<footer class="max-w-prose pt-8 print:hidden">
|
||||||
|
{{ partial "author.html" . }}
|
||||||
|
<!-- Related -->
|
||||||
|
<section class="prose mt-0 flex max-w-full flex-col dark:prose-invert lg:flex-row">
|
||||||
|
<div class="pt-3">
|
||||||
|
{{ partial "related.html" . }}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<!-- /Related -->
|
||||||
|
{{ partial "sharing-links.html" . }}
|
||||||
|
{{ partial "article-pagination.html" . }}
|
||||||
|
|
||||||
|
{{ if .Params.showComments | default (.Site.Params.article.showComments | default false) }}
|
||||||
|
{{ if templates.Exists "partials/comments.html" }}
|
||||||
|
<div class="pt-3">
|
||||||
|
<hr class="border-dotted border-neutral-300 dark:border-neutral-600" />
|
||||||
|
<div class="pt-3">
|
||||||
|
{{ partial "comments.html" . }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{ else }}
|
||||||
|
{{ warnf "[CONGO] Comments are enabled for %s but no comments partial exists." .File.Path }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
</footer>
|
||||||
|
</article>
|
||||||
|
{{ end }}
|
||||||
|
|
11
layouts/partials/related.html
Normal file
11
layouts/partials/related.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{{ $related := .Site.RegularPages.Related . | first 5 }} {{ with $related }}
|
||||||
|
<h3>Related Posts</h3>
|
||||||
|
<ul>
|
||||||
|
{{ range . }}
|
||||||
|
<li>
|
||||||
|
<a href="{{ .RelPermalink }}">{{ .Title }}</a> // <strong>{{ .Date | time.Format "2006" }}</strong>, {{ .Date | time.Format "January 2" }}<br />
|
||||||
|
<small>{{ .Summary }}</small>
|
||||||
|
</li>
|
||||||
|
{{ end }}
|
||||||
|
</ul>
|
||||||
|
{{ end }}
|
Loading…
Reference in a new issue