diff --git a/layouts/articles/single.html b/layouts/articles/single.html index 1d651ce..9bfd825 100644 --- a/layouts/articles/single.html +++ b/layouts/articles/single.html @@ -15,9 +15,13 @@

Tags: {{ partial "tags.html" . }}

-

{{ .Params.narrator }}: {{ .Params.subject }}

+

{{ partial "article-title" . }}

{{ .Content }}
+ +
Go Home
{{ end }} \ No newline at end of file diff --git a/layouts/partials/article-list.html b/layouts/partials/article-list.html index 483b930..b93a0d2 100644 --- a/layouts/partials/article-list.html +++ b/layouts/partials/article-list.html @@ -1,16 +1,20 @@ {{ $pages := .Pages }} {{ range $pages }} +{{- $page := . -}} +{{- if reflect.IsMap . -}} + {{- $page = .page -}} +{{- end -}}
  • - {{ partial "article-wompum.html" . }} -
  • {{ end }} diff --git a/layouts/partials/article-title.html b/layouts/partials/article-title.html new file mode 100644 index 0000000..b64bf8c --- /dev/null +++ b/layouts/partials/article-title.html @@ -0,0 +1,3 @@ +{{- if and .Params.narrator .Params.subject -}} + {{- .Params.narrator }}: {{ .Params.subject -}} +{{- end -}} diff --git a/layouts/partials/related-articles.html b/layouts/partials/related-articles.html new file mode 100644 index 0000000..bba358d --- /dev/null +++ b/layouts/partials/related-articles.html @@ -0,0 +1,37 @@ +{{- $tags := .tags -}} +{{- $limit := default 3 .limit -}} +{{- $currentPath := .page.RelPermalink -}} + +{{- $related := where (where site.RegularPages "Type" "articles") "RelPermalink" "!=" $currentPath -}} +{{- $matchingArticles := slice -}} + +{{/* First try to find articles with matching tags */}} +{{- range $related -}} + {{- $matches := 0 -}} + {{- range .Params.tags -}} + {{- if in $tags . -}} + {{- $matches = add $matches 1 -}} + {{- end -}} + {{- end -}} + {{- if gt $matches 0 -}} + {{- $matchingArticles = $matchingArticles | append (dict "page" . "matches" $matches) -}} + {{- end -}} +{{- end -}} + +{{/* If we found matching articles, sort by number of matching tags */}} +{{- $finalArticles := slice -}} +{{- if gt (len $matchingArticles) 0 -}} + {{- $finalArticles = first $limit (sort $matchingArticles "matches" "desc") -}} +{{- else -}} + {{/* Fallback to showing other articles sorted by date */}} + {{- $finalArticles = first $limit (sort $related "Date" "desc") -}} +{{- end -}} + +{{- if gt (len $finalArticles) 0 -}} + +{{- end -}}