From e2b9dae224e464be44b3a0de43b1a63de4722fb3 Mon Sep 17 00:00:00 2001 From: Developer Davo Date: Tue, 31 Oct 2017 17:48:19 +0100 Subject: [PATCH 1/2] Parmeterize number of recent posts in index.html --- exampleSite/config.toml | 1 + layouts/index.html | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/exampleSite/config.toml b/exampleSite/config.toml index d61ed0507..0b5e1648f 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -28,3 +28,4 @@ enableRobotsTXT = true # choose a background color from any on this page: http://tachyons.io/docs/themes/skins/ and preface it with "bg-" background_color_class = "bg-black" featured_image = "/images/gohugo-default-sample-hero-image.jpg" + recent_posts_number = 2 diff --git a/layouts/index.html b/layouts/index.html index dca45d496..796cbe36c 100755 --- a/layouts/index.html +++ b/layouts/index.html @@ -20,20 +20,22 @@

{{ end }} + {{ $n_posts := .Site.Params.recent_posts_number | default 3 }} +
- {{/* Range through the first three items of the section */}} - {{ range (first 3 $section) }} + {{/* Range through the first $n_posts items of the section */}} + {{ range (first $n_posts $section) }}
{{ partial "summary-with-image.html" . }}
{{ end }}
- {{ if ge $section_count 4 }} + {{ if ge $section_count (add $n_posts 1) }}

More

- {{/* Now, range through the next four after the initial 3 items. Nest the requirements, "after" then "first" on the outside */}} - {{ range (first 4 (after 3 $section)) }} + {{/* Now, range through the next four after the initial $n_posts items. Nest the requirements, "after" then "first" on the outside */}} + {{ range (first 4 (after $n_posts $section)) }}

{{ .Title }} From e4fde9e87d73f0b2fa8fa680f6e924eaddfeae33 Mon Sep 17 00:00:00 2001 From: Developer Davo Date: Wed, 1 Nov 2017 16:07:26 +0100 Subject: [PATCH 2/2] Replace .Site.Params.recent_posts_number with $.Param "recent_posts_number" in index.html --- layouts/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layouts/index.html b/layouts/index.html index 796cbe36c..3480c04f5 100755 --- a/layouts/index.html +++ b/layouts/index.html @@ -20,7 +20,7 @@

{{ end }} - {{ $n_posts := .Site.Params.recent_posts_number | default 3 }} + {{ $n_posts := $.Param "recent_posts_number" | default 3 }}
{{/* Range through the first $n_posts items of the section */}}