diff --git a/config.yaml b/config.yaml index c672579b2241f770e7f8c851e3fd770be52efcec..fc15d7d82dc1a1b9bbed213638a9d4eeaaae13a0 100644 --- a/config.yaml +++ b/config.yaml @@ -7,4 +7,7 @@ params: posts: list: show_categories: false - truncate_description: false \ No newline at end of file + truncate_description: 0 # Set to 0 to disable truncate + pages: + list: + truncate_description: 0 # Set to 0 to disable truncate \ No newline at end of file diff --git a/layouts/partials/GetTruncateContent b/layouts/partials/GetTruncateContent index 8459b9504c9ffd168ed82e87610bbf430e52dce4..d1eaa91db824dbcba4b4eb5399b9f66871531558 100644 --- a/layouts/partials/GetTruncateContent +++ b/layouts/partials/GetTruncateContent @@ -1,3 +1,5 @@ -{{ $text := replace . "<" " <" }} -{{ $text = chomp (truncate 120 "…" (safeHTML (plainify $text))) }} +{{ $length := .length | default 150 }} + +{{ $text := replace .text "<" " <" }} +{{ $text = chomp (truncate $length "…" (safeHTML (plainify $text))) }} {{ return $text }} diff --git a/layouts/partials/blocks/templates/organization_chart.html b/layouts/partials/blocks/templates/organization_chart.html index 9bd0ccd4029437170a533b584c9e9cc64d1a24bd..1d3a03d0ff2ee5ee28e246460105fb030dcdb2b0 100644 --- a/layouts/partials/blocks/templates/organization_chart.html +++ b/layouts/partials/blocks/templates/organization_chart.html @@ -40,7 +40,7 @@ {{- else if partial "GetTextFromHTML" $person.Params.description_short }} {{- partial "PrepareHTML" $person.Params.description_short -}} {{ else if (partial "GetTextFromHTML" $person.Content) }} - {{- partial "GetTruncateContent" $person.Content -}} + {{- partial "GetTruncateContent" ( dict "text" $person.Content ) -}} {{ end -}} </p> </div> diff --git a/layouts/partials/blocks/templates/pages.html b/layouts/partials/blocks/templates/pages.html index 1a17492757ad26af65597fee91f7df735be714fa..3c0e421eab5527b52c4e8e6d6d7153521c9de061 100644 --- a/layouts/partials/blocks/templates/pages.html +++ b/layouts/partials/blocks/templates/pages.html @@ -10,6 +10,7 @@ {{- $show_main_description := .show_main_description -}} {{- $show_descriptions := .show_descriptions -}} {{- $show_images := .show_images -}} + {{- $main_description := "" -}} {{- $page_link := false -}} {{/* LEGACY */}} @@ -39,6 +40,14 @@ {{- $page_class = partial "GetBodyclass" . }} {{- $page_class = printf "block-%s" $page_class }} {{ end }} + {{ if site.Params.pages.list.truncate_description }} + {{- $main_description = partial "GetTruncateContent" ( dict + "text" .Params.description_short + "length" site.Params.pages.list.truncate_description + ) -}} + {{ else }} + {{- $main_description = partial "PrepareHTML" .Params.description_short -}} + {{ end }} {{ end -}} <section class="block block-pages{{ if $title }} block-with-title{{ end }} {{ $layout_class }} {{ $page_class }}" id="block-{{ $position }}"> @@ -55,7 +64,7 @@ {{ if and $show_main_description (ne $layout "list")}} {{- with $page }} - <p class="description">{{ partial "PrepareHTML" .Params.description_short }}</p> + <p class="description">{{- $main_description -}}</p> {{ end }} {{ end }} </div> @@ -63,7 +72,7 @@ {{ if and $show_main_description (eq $layout "list")}} {{- with $page }} - <p class="description">{{ partial "PrepareHTML" .Params.description_short }}</p> + <p class="description">{{- $main_description -}}</p> {{ end }} {{ end }} diff --git a/layouts/partials/blocks/templates/pages/cards.html b/layouts/partials/blocks/templates/pages/cards.html index 5c3ea061cab3bba4e9a83ca50427d00be984b4be..79a9e1cb26ffadcba22ecb7d55bbe19721b8f786 100644 --- a/layouts/partials/blocks/templates/pages/cards.html +++ b/layouts/partials/blocks/templates/pages/cards.html @@ -16,7 +16,14 @@ </h1> {{ if and $show_descriptions .Params.description_short }} - <p>{{ partial "PrepareHTML" .Params.description_short }}</p> + {{ if site.Params.pages.list.truncate_description }} + <p>{{ partial "GetTruncateContent" ( dict + "text" .Params.description_short + "length" site.Params.pages.list.truncate_description + ) }}</p> + {{ else }} + <p>{{ partial "PrepareHTML" .Params.description_short }}</p> + {{ end }} {{ end }} <p class="more meta">{{- i18n "commons.more" -}}</p> diff --git a/layouts/partials/blocks/templates/pages/grid.html b/layouts/partials/blocks/templates/pages/grid.html index 49d6100300524ad20e6c6e54d967f6ce17f0d84f..9ea52a3290074e64c219f1ec1882e60833127785 100644 --- a/layouts/partials/blocks/templates/pages/grid.html +++ b/layouts/partials/blocks/templates/pages/grid.html @@ -24,7 +24,14 @@ </a> </h1> {{ if and $show_descriptions .Params.description_short }} - <p>{{ partial "PrepareHTML" .Params.description_short }}</p> + {{ if site.Params.pages.list.truncate_description }} + <p>{{ partial "GetTruncateContent" ( dict + "text" .Params.description_short + "length" site.Params.pages.list.truncate_description + ) }}</p> + {{ else }} + <p>{{ partial "PrepareHTML" .Params.description_short }}</p> + {{ end }} {{ end }} {{ if $show_images }} {{- partial "pages/page-media.html" . -}} diff --git a/layouts/partials/blocks/templates/posts/highlight.html b/layouts/partials/blocks/templates/posts/highlight.html index a7853ac3230f2986ae2df5733d22c50115833001..8dddd8449c51adb02f08d635e6a43abbecfdd605 100644 --- a/layouts/partials/blocks/templates/posts/highlight.html +++ b/layouts/partials/blocks/templates/posts/highlight.html @@ -22,7 +22,14 @@ {{- partial "posts/categories" . -}} {{ end }} {{- if (partial "GetTextFromHTML" .Params.description_short) -}} - <p itemprop="articleBody">{{ partial "PrepareHTML" .Params.description_short }}</p> + {{ if site.Params.posts.list.truncate_description }} + <p itemprop="articleBody">{{ partial "GetTruncateContent" ( dict + "text" .Params.description_short + "length" site.Params.posts.list.truncate_description + ) }}</p> + {{ else }} + <p itemprop="articleBody">{{ partial "PrepareHTML" .Params.description_short }}</p> + {{ end }} {{- end -}} <time itemprop="datePublished" datetime="{{ .Date.Format "2006-01-02T15:04" }}">{{ .Date | time.Format ":date_long" }}</time> </article> diff --git a/layouts/partials/head/seo.html b/layouts/partials/head/seo.html index d02403e666966a875b8e92b6ecaf0f1e9da23088..e7c07467748edc62fe25fbadaad435e0335ef84c 100644 --- a/layouts/partials/head/seo.html +++ b/layouts/partials/head/seo.html @@ -8,13 +8,13 @@ {{- else if .Params.description_short -}} {{- $seoDescription = partial "PrepareHTML" .Params.description_short -}} {{- else if .Content -}} - {{- $seoDescription = partial "GetTruncateContent" .Content -}} + {{- $seoDescription = partial "GetTruncateContent" ( dict "text" .Content ) -}} {{- else if .Params.legacy_text -}} - {{- $seoDescription = partial "GetTruncateContent" .Params.legacy_text -}} + {{- $seoDescription = partial "GetTruncateContent" ( dict "text" .Params.legacy_text ) -}} {{- else if .Params.blocks -}} {{- range first 1 .Params.blocks -}} {{- if .title -}} - {{- $seoDescription = partial "GetTruncateContent" .title -}} + {{- $seoDescription = partial "GetTruncateContent" ( dict "text" .title ) -}} {{- end -}} {{- end -}} {{- end -}} diff --git a/layouts/partials/persons/person.html b/layouts/partials/persons/person.html index b14d5fcf0cf2dc3866e7a568cd9e9583ae64371e..0047e2e5e49e65772f5424dd8b76a060bb31ecab 100644 --- a/layouts/partials/persons/person.html +++ b/layouts/partials/persons/person.html @@ -5,7 +5,7 @@ {{- if partial "GetTextFromHTML" .Params.description_short }} <p>{{- partial "PrepareHTML" .Params.description_short -}}</p> {{ else if (partial "GetTextFromHTML" .Content) }} - <p>{{- partial "GetTruncateContent" .Content -}}</p> + <p>{{- partial "GetTruncateContent" ( dict "text" .Content ) -}}</p> {{ end -}} </div> <div class="avatar"> diff --git a/layouts/partials/posts/post.html b/layouts/partials/posts/post.html index 5dd5eaec0058a013500861d87f38c3a4c2a1320b..1168ce5d86f502d865058496d3d6d55ee32168ca 100644 --- a/layouts/partials/posts/post.html +++ b/layouts/partials/posts/post.html @@ -6,7 +6,14 @@ {{- partial "posts/categories" . -}} {{ end }} {{- if (partial "GetTextFromHTML" .Params.description_short) -}} - <p itemprop="articleBody">{{ partial "PrepareHTML" .Params.description_short }}</p> + {{ if $.Site.Params.posts.list.truncate_description }} + <p itemprop="articleBody">{{ partial "GetTruncateContent" ( dict + "text" .Params.description_short + "length" $.Site.Params.posts.list.truncate_description + ) }}</p> + {{ else }} + <p itemprop="articleBody">{{ partial "PrepareHTML" .Params.description_short }}</p> + {{ end }} {{- end -}} <time itemprop="datePublished" datetime="{{ .Date.Format "2006-01-02T15:04" }}">{{ .Date | time.Format ":date_long" }}</time>