summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAditya Telange <21258296+adityatelange@users.noreply.github.com>2020-10-04 09:23:27 +0530
committerAditya Telange <21258296+adityatelange@users.noreply.github.com>2020-10-04 09:50:40 +0530
commitd8199140e5940f02960196d1220c9a0ce8a23de1 (patch)
treee21206c024c643884168e618ec0921fb29a25a3d
parentf4df89dbf66d893f48913353760650d4d90d5129 (diff)
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.
-rw-r--r--layouts/_default/list.html6
-rw-r--r--layouts/_default/single.html4
2 files changed, 9 insertions, 1 deletions
diff --git a/layouts/_default/list.html b/layouts/_default/list.html
index 2d728e0..ef3ef29 100644
--- a/layouts/_default/list.html
+++ b/layouts/_default/list.html
@@ -33,7 +33,11 @@
<article class="{{ $class }}">
{{- if .Params.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>
{{- end }}
<header class="entry-header">
diff --git a/layouts/_default/single.html b/layouts/_default/single.html
index fc95dc6..7cdea8c 100644
--- a/layouts/_default/single.html
+++ b/layouts/_default/single.html
@@ -28,7 +28,11 @@
</header>
{{- if .Params.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 }}">
+ {{else}}
+ <img src="{{ .Permalink -}} {{- .Params.cover }}" alt="cover image for {{ .Title | plainify }}">
+ {{end}}
</figure>
{{- end }}
{{- if .Params.ShowToc }}