Skip to content

Commit

Permalink
Merge pull request #58 from noesya/feature/list-options
Browse files Browse the repository at this point in the history
Feature/list options
  • Loading branch information
alexisben authored Dec 29, 2022
2 parents bd55419 + e25e683 commit ab1c8d8
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 14 deletions.
5 changes: 4 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ params:
posts:
list:
show_categories: false
truncate_description: false
truncate_description: 0 # Set to 0 to disable truncate
pages:
list:
truncate_description: 0 # Set to 0 to disable truncate
6 changes: 4 additions & 2 deletions layouts/partials/GetTruncateContent
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion layouts/partials/blocks/templates/organization_chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h1 class="name" itemprop="name">
{{- 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>
Expand Down
13 changes: 11 additions & 2 deletions layouts/partials/blocks/templates/pages.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{{- $show_main_description := .show_main_description -}}
{{- $show_descriptions := .show_descriptions -}}
{{- $show_images := .show_images -}}
{{- $main_description := "" -}}
{{- $page_link := false -}}

{{/* LEGACY */}}
Expand Down Expand Up @@ -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 }}">
Expand All @@ -55,15 +64,15 @@

{{ 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>
{{ end -}}

{{ 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 }}

Expand Down
9 changes: 8 additions & 1 deletion layouts/partials/blocks/templates/pages/cards.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ <h1>
</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>
Expand Down
9 changes: 8 additions & 1 deletion layouts/partials/blocks/templates/pages/grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ <h1>
</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" . -}}
Expand Down
9 changes: 8 additions & 1 deletion layouts/partials/blocks/templates/posts/highlight.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ <h1 itemprop="headline"><a href="{{ .Permalink }}" title="{{ safeHTML (i18n "com
{{- 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>
Expand Down
6 changes: 3 additions & 3 deletions layouts/partials/head/seo.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/persons/person.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
9 changes: 8 additions & 1 deletion layouts/partials/posts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ <h1 itemprop="headline"><a href="{{ .Permalink }}" title="{{ safeHTML (i18n "com
{{- 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>
Expand Down

0 comments on commit ab1c8d8

Please sign in to comment.