From 18a213cf3133455151aaa0a553203b30cba56a62 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Sat, 12 Jun 2021 15:07:39 +0200 Subject: [PATCH] added extra content option for more home page like post views --- README.md | 3 +++ layouts/_default/list.html | 19 ++++++------------- layouts/index.html | 25 ++----------------------- layouts/partials/header.html | 3 +++ layouts/partials/home_post_list.html | 23 +++++++++++++++++++++++ layouts/partials/simple_posts_list.html | 13 +++++++++++++ 6 files changed, 50 insertions(+), 36 deletions(-) create mode 100644 layouts/partials/home_post_list.html create mode 100644 layouts/partials/simple_posts_list.html diff --git a/README.md b/README.md index ceb66b4..321214e 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,9 @@ summaryLength = 70 # number of words for article summaries author = "Gabriele Musco" description = "A description for my website" # this will be added as metadata + posts = "posts" # content directory where to find home page posts; default searches in "posts" and "post" + extraContentDirs = [] # other content directories to render similarly to the home page + # It's best to put these icons in the "static" folder of your site logo = "/logo.svg" favicon = "/favicon.png" # 32x32 diff --git a/layouts/_default/list.html b/layouts/_default/list.html index cac9f9d..4415c13 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,15 +1,8 @@ {{ define "main" }} -

- {{ $title := .Title }} - {{ $section := .Section | humanize }} - {{ if and (ne $section $title) (ne $section "Tags") (ne $title (printf "%ss" $section)) }} - {{ $section }}: - {{ end }} - {{ if and (eq $section "Tags") (ne $section $title) }}Tag: #{{ end }}{{ $title }} -

- + {{ if in (site.Params.extraContentDirs | default (slice)) .Section }} +

{{ .Section | humanize }}

+ {{- partial "home_post_list.html" (dict "Ctx" . "AllPostsList" .Pages) -}} + {{ else }} + {{- partial "simple_posts_list.html" . -}} + {{ end }} {{ end }} diff --git a/layouts/index.html b/layouts/index.html index 4aecdd4..6fc1b2b 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -2,28 +2,7 @@ {{/* get all the pages that are regular posts and not pages */}} {{ $postsDir := .Site.Params.Posts | default (slice "posts" "post") }} - {{ $allPostsList := where .Site.RegularPages "Section" "in" $postsDir }} - {{ $featuredPostsList := slice }} - {{ $postsList := $allPostsList }} - {{ $pagination := slice }} - {{ if .Site.Params.enableFeatured | default false }} - {{ $featuredPostsList = where $allPostsList "Params.featured" true }} - {{ $postsList = union (where $allPostsList "Params.featured" false) (where $allPostsList "Params.featured" nil) }} - {{ $pagination = (.Paginate $postsList).Pages }} - {{ if eq .Paginator.PageNumber 1 }} - {{- partial "featured_articles.html" $featuredPostsList -}} - {{ end }} - {{ else }} - {{ $pagination = (.Paginate $postsList).Pages }} - {{ end }} - - {{/* pagination */}} -
- {{ range $pagination }} - {{- partial "article_card.html" . -}} - {{ end }} -
-
- {{- partial "paginator.html" . -}} + {{ $allPostsList := where site.RegularPages "Section" "in" $postsDir }} + {{- partial "home_post_list.html" (dict "Ctx" . "AllPostsList" $allPostsList) -}} {{ end }} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index fc15cf6..ab06b2c 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -19,6 +19,9 @@