Improved code by using UseRelativeCover flag to post rather than having cover and relcover to avoid code duplication

This commit is contained in:
Marc Päpper 2019-03-19 17:47:05 +01:00
parent 7bf862d9d3
commit e9aae285a6
3 changed files with 13 additions and 15 deletions

View File

@ -130,7 +130,7 @@ Adding a cover image to your post is simple and there are two options when you e
* Use `cover: "/path/to/absolute/img.jpg"` to link an absolute image
* Resulting in `https://www.yourpage.com/path/to/absolute/img.jpg`
* Use `relcover: "img.jpg"` to link the image relative to the blog post folder
* Use `cover: "img.jpg"` and `useRelativeCover: true` to link the image relative to the blog post folder
* Resulting in `https://www.yourpage.com/posts/blog-entry-xy/img.jpg`
## Add-ons

View File

@ -26,13 +26,12 @@
</span>
{{ end }}
{{ $permalink := .Permalink }}
{{ with .Params.RelCover }}
<img src="{{ (printf "%s%s" $permalink . ) }}" class="post-cover" />
{{ end }}
{{ with .Params.Cover }}
<img src="{{ . | absURL }}" class="post-cover" />
{{ if .Params.Cover }}
{{ if .Params.UseRelativeCover }}
<img src="{{ (printf "%s%s" .Permalink .Params.Cover ) }}" class="post-cover" />
{{ else }}
<img src="{{ (urlize .Params.Cover | absURL) }}" class="post-cover" />
{{ end }}
{{ end }}
<div class="post-content">

View File

@ -20,14 +20,13 @@
{{ end }}
</span>
{{ end }}
{{ $permalink := .Permalink }}
{{ with .Params.RelCover }}
<img src="{{ (printf "%s%s" $permalink . ) }}" class="post-cover" />
{{ end }}
{{ with .Params.Cover }}
<img src="{{ . | absURL }}" class="post-cover" />
{{ if .Params.Cover }}
{{ if .Params.UseRelativeCover }}
<img src="{{ (printf "%s%s" .Permalink .Params.Cover ) }}" class="post-cover" />
{{ else }}
<img src="{{ (urlize .Params.Cover | absURL) }}" class="post-cover" />
{{ end }}
{{ end }}
<div class="post-content">