diff options
author | Vimux <Vimux@users.noreply.github.com> | 2021-09-09 22:06:49 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-09 22:06:49 +0300 |
commit | 3bc075e3ee0ae208bbd2fe1bbcc4584fec39d64d (patch) | |
tree | 17a06f1c7f661d437cc573a2760e81c22046a95c | |
parent | e2b0286e0a41eed862bccc6dc6da808c61c8f474 (diff) | |
parent | c428434c6c571c6f6dfc010117791a29f3d3e294 (diff) |
Merge pull request #274 from Vimux/add-thumbnail-visibility-param
Add thumbnail visibility param
-rw-r--r-- | README.md | 25 | ||||
-rw-r--r-- | layouts/partials/post_thumbnail.html | 20 |
2 files changed, 41 insertions, 4 deletions
@@ -101,6 +101,9 @@ googleAnalytics = "" # Enable Google Analytics by entering your tracking id title = "Mainroad" # Logo title, otherwise will use site title subtitle = "Just another site" # Logo subtitle +[Params.thumbnail] + visibility = ["list", "post"] # Control thumbnail visibility + [Params.sidebar] home = "right" # Configure layout for home page list = "left" # Configure layout for list pages @@ -195,6 +198,28 @@ Please be noted that the logo image will display at a maximum width of 128 pixel when you use text and image simultaneously. When the only logo image is active, it will display at a maximum height of 256 pixels. Ideally, your image should be SVG. +### Thumbnail visibility + +By default, a thumbnail image has shown for a list and single pages simultaneously. In some cases, you may want to show +a thumbnail for list-like pages only and hide it on single pages (or vice versa). Control global thumbnail visibility +via config. + +```toml +[Params.thumbnail] + visibility = ["list"] +``` + +Besides global configuration, you can change thumbnail visibility individually with extended thumbnail notation via +front matter. + +```yaml +thumbnail: + src: "img/placeholder.jpg" + visibility: + - list + - post +``` + ### Sidebar **Mainroad** comes with a configurable sidebar that can be on the left, on the right, or disabled. The default layout diff --git a/layouts/partials/post_thumbnail.html b/layouts/partials/post_thumbnail.html index c9f4b42..e1d44a5 100644 --- a/layouts/partials/post_thumbnail.html +++ b/layouts/partials/post_thumbnail.html @@ -1,7 +1,19 @@ {{- if $thumbnail := .page.Params.thumbnail }} -<figure class="{{ with .class }}{{ . }}__thumbnail {{ end }}thumbnail"> - {{ if eq .class "list" }}<a class="thumbnail__link" href="{{ .page.RelPermalink }}">{{ end }} + {{- $class := .class }} + {{- $visibility := .page.Site.Params.thumbnail.visibility | default (slice "list" "post") }} + + {{- $valueType := printf "%T" $thumbnail -}} + {{- $isMap := in $valueType "map" -}} + {{- if $isMap }} + {{ $visibility = default (slice "list" "post") (default .page.Site.Params.thumbnail.visibility $thumbnail.visibility) }} + {{ $thumbnail = $thumbnail.src }} + {{- end }} + + {{- if in $visibility $class }} + <figure class="{{ with $class }}{{ . }}__thumbnail {{ end }}thumbnail"> + {{ if eq $class "list" }}<a class="thumbnail__link" href="{{ .page.RelPermalink }}">{{ end }} <img class="thumbnail__image" src="{{ $thumbnail | relURL }}" alt="{{ .page.Title }}"> - {{ if eq .class "list" }}</a>{{ end }} -</figure> + {{ if eq $class "list" }}</a>{{ end }} + </figure> + {{- end }} {{- end }}
\ No newline at end of file |