support for images in page bundles as relative paths
This commit is contained in:
parent
bedcf7a212
commit
e4a10bab22
|
@ -4,6 +4,14 @@
|
||||||
{{ $mscratch.Add "articles" slice }}
|
{{ $mscratch.Add "articles" slice }}
|
||||||
{{ $pages := where .Site.RegularPages "Params.nosearch" "!=" "true" }}
|
{{ $pages := where .Site.RegularPages "Params.nosearch" "!=" "true" }}
|
||||||
{{ range $pages }}
|
{{ range $pages }}
|
||||||
|
{{ $image := "" }}
|
||||||
|
{{ if .Params.Image }}
|
||||||
|
{{ if or (hasPrefix .Params.Image "/") (hasPrefix .Params.Image "http://") (hasPrefix .Params.Image "https://") }}
|
||||||
|
{{ $image = .Params.Image }}
|
||||||
|
{{ else }}
|
||||||
|
{{ $image = path.Join "/" (path.Join .File.Dir .Params.Image) }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
{{ $mscratch.Add "articles" (dict
|
{{ $mscratch.Add "articles" (dict
|
||||||
"title" .Title
|
"title" .Title
|
||||||
"date" (.Date.Format "2006-01-02")
|
"date" (.Date.Format "2006-01-02")
|
||||||
|
@ -11,7 +19,7 @@
|
||||||
"summary" (or .Params.description .Summary)
|
"summary" (or .Params.description .Summary)
|
||||||
"text" (lower .Plain)
|
"text" (lower .Plain)
|
||||||
"link" .Permalink
|
"link" .Permalink
|
||||||
"image" (or .Params.Image "")) }}
|
"image" $image) }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
"pages": {{ $mscratch.Get "articles" | jsonify }}
|
"pages": {{ $mscratch.Get "articles" | jsonify }}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,21 @@
|
||||||
{{ $mscratch := newScratch }}
|
{{ $mscratch := newScratch }}
|
||||||
{{ $mscratch.Add "articles" slice }}
|
{{ $mscratch.Add "articles" slice }}
|
||||||
{{ range (.Paginate $postsList).Pages }}
|
{{ range (.Paginate $postsList).Pages }}
|
||||||
|
{{ $image := "" }}
|
||||||
|
{{ if .Params.Image }}
|
||||||
|
{{ if or (hasPrefix .Params.Image "/") (hasPrefix .Params.Image "http://") (hasPrefix .Params.Image "https://") }}
|
||||||
|
{{ $image = .Params.Image }}
|
||||||
|
{{ else }}
|
||||||
|
{{ $image = path.Join (path.Join .File.Dir .Params.Image) }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
{{ $mscratch.Add "articles" (dict
|
{{ $mscratch.Add "articles" (dict
|
||||||
"title" .Title
|
"title" .Title
|
||||||
"date" (.Date.Format "2006-01-02")
|
"date" (.Date.Format "2006-01-02")
|
||||||
"tags" (sort (or .Params.tags slice))
|
"tags" (sort (or .Params.tags slice))
|
||||||
"summary" (or .Params.description .Summary)
|
"summary" (or .Params.description .Summary)
|
||||||
"link" .Permalink
|
"link" .Permalink
|
||||||
"image" (or .Params.Image "")) }}
|
"image" $image) }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
"articles": {{ $mscratch.Get "articles" | jsonify }},
|
"articles": {{ $mscratch.Get "articles" | jsonify }},
|
||||||
"test": "{{range $postsList}}{{.Title}} {{end}}",
|
"test": "{{range $postsList}}{{.Title}} {{end}}",
|
||||||
|
|
|
@ -17,7 +17,11 @@
|
||||||
{{ if .Site.Params.imageInArticlePreview }}
|
{{ if .Site.Params.imageInArticlePreview }}
|
||||||
{{ if .Params.Image }}
|
{{ if .Params.Image }}
|
||||||
<a class="unstyledLink" href="{{ .Permalink }}">
|
<a class="unstyledLink" href="{{ .Permalink }}">
|
||||||
|
{{ if or (hasPrefix .Params.Image "/") (hasPrefix .Params.Image "http://") (hasPrefix .Params.Image "https://") }}
|
||||||
<img src="{{ .Params.Image }}" />
|
<img src="{{ .Params.Image }}" />
|
||||||
|
{{ else }}
|
||||||
|
<img src="/{{ path.Join .File.Dir .Params.Image }}" />
|
||||||
|
{{ end }}
|
||||||
</a>
|
</a>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
<div class="featured postlist gridView">
|
<div class="featured postlist gridView">
|
||||||
{{ range . }}
|
{{ range . }}
|
||||||
|
{{ $image := "" }}
|
||||||
|
{{ if .Params.Image }}
|
||||||
|
{{ if or (hasPrefix .Params.Image "/") (hasPrefix .Params.Image "http://") (hasPrefix .Params.Image "https://") }}
|
||||||
|
{{ $image = .Params.Image }}
|
||||||
|
{{ else }}
|
||||||
|
{{ $image = path.Join "/" (path.Join .File.Dir .Params.Image) }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
<a class="featuredCardLink" href="{{ .Permalink }}">
|
<a class="featuredCardLink" href="{{ .Permalink }}">
|
||||||
<article class="featuredCard"
|
<article class="featuredCard"
|
||||||
style="
|
style="
|
||||||
|
@ -7,7 +15,7 @@
|
||||||
rgba(0, 0, 0, 0) 0%,
|
rgba(0, 0, 0, 0) 0%,
|
||||||
rgba(0, 0, 0, 0.1) 45%,
|
rgba(0, 0, 0, 0.1) 45%,
|
||||||
rgba(0, 0, 0, 0.7) 100%
|
rgba(0, 0, 0, 0.7) 100%
|
||||||
), url('{{ .Params.Image }}');
|
), url('{{ $image }}');
|
||||||
">
|
">
|
||||||
<div class="contentArea">
|
<div class="contentArea">
|
||||||
<h2>{{ .Title }}</h2>
|
<h2>{{ .Title }}</h2>
|
||||||
|
|
|
@ -15,10 +15,16 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<meta property="og:url" content="{{ .Permalink }}" />
|
<meta property="og:url" content="{{ .Permalink }}" />
|
||||||
|
{{ $image := .Site.Params.icon512 | default "/img/icon.svg" }}
|
||||||
|
{{ if .Params.Image }}
|
||||||
|
{{ if or (hasPrefix .Params.Image "/") (hasPrefix .Params.Image "http://") (hasPrefix .Params.Image "https://") }}
|
||||||
|
{{ $image = .Params.Image }}
|
||||||
|
{{ else }}
|
||||||
|
{{ $image = path.Join (path.Join .File.Dir .Params.Image) }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
<meta property="og:image"
|
<meta property="og:image"
|
||||||
content='{{ if .Params.Image }}{{ .Params.Image | absURL }}
|
content="{{ $image | absURL }}" />
|
||||||
{{ else }}{{ .Site.Params.icon512 | default "/img/icon.svg" | absURL }}
|
|
||||||
{{ end }}' />
|
|
||||||
{{ if .Params.description }}
|
{{ if .Params.description }}
|
||||||
<meta property="og:description" content="{{ .Params.description }}" />
|
<meta property="og:description" content="{{ .Params.description }}" />
|
||||||
{{ else }}
|
{{ else }}
|
||||||
|
|
|
@ -7,10 +7,16 @@
|
||||||
{{ if .IsPage }}
|
{{ if .IsPage }}
|
||||||
<meta name="twitter:title" content="{{ .Title }}" />
|
<meta name="twitter:title" content="{{ .Title }}" />
|
||||||
|
|
||||||
|
{{ $image := .Site.Params.icon512 | default "/img/icon.svg" }}
|
||||||
|
{{ if .Params.Image }}
|
||||||
|
{{ if or (hasPrefix .Params.Image "/") (hasPrefix .Params.Image "http://") (hasPrefix .Params.Image "https://") }}
|
||||||
|
{{ $image = .Params.Image }}
|
||||||
|
{{ else }}
|
||||||
|
{{ $image = path.Join (path.Join .File.Dir .Params.Image) }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
<meta name="twitter:image"
|
<meta name="twitter:image"
|
||||||
content='{{ if .Params.Image }}{{ .Params.Image | absURL }}
|
content="{{ $image | absURL }}" />
|
||||||
{{ else }}{{ .Site.Params.icon512 | default "/img/icon.svg" | absURL }}
|
|
||||||
{{ end }}' />
|
|
||||||
{{ if .Params.description }}
|
{{ if .Params.description }}
|
||||||
<meta name="twitter:description" content="{{ .Params.description }}" />
|
<meta name="twitter:description" content="{{ .Params.description }}" />
|
||||||
{{ else }}
|
{{ else }}
|
||||||
|
|
|
@ -14,7 +14,11 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if .Params.Image }}
|
{{ if .Params.Image }}
|
||||||
<figure style="margin: 0">
|
<figure style="margin: 0">
|
||||||
<img src="{{ .Params.Image }}" alt="" />
|
{{ if or (hasPrefix .Params.Image "/") (hasPrefix .Params.Image "http://") (hasPrefix .Params.Image "https://") }}
|
||||||
|
<img src="{{ .Params.Image }}" />
|
||||||
|
{{ else }}
|
||||||
|
<img src="/{{ path.Join .File.Dir .Params.Image }}" />
|
||||||
|
{{ end }}
|
||||||
{{ if .Params.ImageCaption }}
|
{{ if .Params.ImageCaption }}
|
||||||
<figcaption>
|
<figcaption>
|
||||||
<p>{{ .Params.ImageCaption | markdownify }}</p>
|
<p>{{ .Params.ImageCaption | markdownify }}</p>
|
||||||
|
|
Loading…
Reference in New Issue