Add contentTypeName to config

This commit is contained in:
panr 2019-01-25 10:20:52 +01:00
parent 27a013b809
commit b0dfb769d1
2 changed files with 6 additions and 1 deletions

View File

@ -65,6 +65,8 @@ paginate = 5
[params] [params]
subtitle = "A simple theme for Hugo" subtitle = "A simple theme for Hugo"
# dir name for your list content
contentTypeName = "posts"
# "light" or "dark" # "light" or "dark"
defaultTheme = "dark" defaultTheme = "dark"

View File

@ -1,6 +1,9 @@
{{ define "main" }} {{ define "main" }}
<div class="posts"> <div class="posts">
{{ $paginator := .Paginate (where .Data.Pages "Type" "post") }} {{ $isntDefault := not (or (eq (trim .Site.Params.contentTypeName " ") "posts") (eq (trim .Site.Params.contentTypeName " ") "")) }}
{{ $contentTypeName := cond $isntDefault (string .Site.Params.contentTypeName) "posts" }}
{{ $paginator := .Paginate (where .Data.Pages "Type" $contentTypeName) }}
{{ range $paginator.Pages }} {{ range $paginator.Pages }}
<div class="post on-list"> <div class="post on-list">
<h1 class="post-title"><a href="{{ .Permalink }}">{{ .Title | markdownify }}</a></h1> <h1 class="post-title"><a href="{{ .Permalink }}">{{ .Title | markdownify }}</a></h1>