post-cover: add support for relative path for cover image

* checks whether path mentioned in `cover` page-variable exists OR is an external url,
  else sets the relative path for image w.r.t the post the cover is of.
This commit is contained in:
Aditya Telange 2020-10-04 09:23:27 +05:30
parent f4df89dbf6
commit d8199140e5
No known key found for this signature in database
GPG Key ID: 82E844EF3DA99E77
2 changed files with 9 additions and 1 deletions

View File

@ -33,7 +33,11 @@
<article class="{{ $class }}"> <article class="{{ $class }}">
{{- if .Params.cover }} {{- if .Params.cover }}
<figure class="entry-cover"> <figure class="entry-cover">
<img src="{{ .Params.cover | absURL }}" alt="cover image for {{ .Title }}"> {{ if (or (fileExists (path.Join "static" .Params.cover)) (hasPrefix .Params.cover "http://") (hasPrefix .Params.cover "https://")) }}
<img src="{{ .Params.cover | absURL }}" alt="cover image for {{ .Title | plainify }}">
{{else}}
<img src="{{ .Permalink -}} {{- .Params.cover }}" alt="cover image for {{ .Title | plainify }}">
{{end}}
</figure> </figure>
{{- end }} {{- end }}
<header class="entry-header"> <header class="entry-header">

View File

@ -28,7 +28,11 @@
</header> </header>
{{- if .Params.cover }} {{- if .Params.cover }}
<figure class="entry-cover"> <figure class="entry-cover">
{{ if (or (fileExists (path.Join "static" .Params.cover)) (hasPrefix .Params.cover "http://") (hasPrefix .Params.cover "https://")) }}
<img src="{{ .Params.cover | absURL }}" alt="cover image for {{ .Title | plainify }}"> <img src="{{ .Params.cover | absURL }}" alt="cover image for {{ .Title | plainify }}">
{{else}}
<img src="{{ .Permalink -}} {{- .Params.cover }}" alt="cover image for {{ .Title | plainify }}">
{{end}}
</figure> </figure>
{{- end }} {{- end }}
{{- if .Params.ShowToc }} {{- if .Params.ShowToc }}