Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatic cover image support #303

Merged
merged 3 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions layouts/partials/featured.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{ $linkToCover := "" }}
{{ if .Params.featured_image }}
{{ $linkToCover = .Params.featured_image }}
{{ else }}
{{ $img := .Resources.GetMatch "**cover*.jpg" }}
{{ with $img }}
{{ $linkToCover = .Permalink }}
{{ end }}
{{ end }}
{{ return $linkToCover }}
2 changes: 1 addition & 1 deletion layouts/partials/page-header.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ $featured_image := .Params.featured_image }}
{{ $featured_image := partial "featured.html" . }}
{{ if $featured_image }}
{{/* Trimming the slash and adding absURL make sure the image works no matter where our site lives */}}
{{ $featured_image := (trim $featured_image "/") | absURL }}
Expand Down
6 changes: 3 additions & 3 deletions layouts/partials/summary-with-image.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{ $featured_image := .Params.featured_image }}
{{ $featured_image := partial "featured.html" . }}
<article class="bb b--black-10">
<div class="db pv4 ph3 ph0-l no-underline dark-gray">
<div class="flex flex-column flex-row-ns">
{{ if .Params.featured_image }}
{{ if $featured_image }}
{{/* Trimming the slash and adding absURL make sure the image works no matter where our site lives */}}
{{ $featured_image := (trim $featured_image "/") | absURL }}
<div class="pr3-ns mb4 mb0-ns w-100 w-40-ns">
Expand All @@ -11,7 +11,7 @@
</a>
</div>
{{ end }}
<div class="blah w-100{{ if .Params.featured_image }} w-60-ns pl3-ns{{ end }}">
<div class="blah w-100{{ if $featured_image }} w-60-ns pl3-ns{{ end }}">
<h1 class="f3 fw1 athelas mt0 lh-title">
<a href="{{.Permalink}}" class="color-inherit dim link">
{{ .Title }}
Expand Down
7 changes: 4 additions & 3 deletions layouts/post/summary-with-image.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<article class="bb b--black-10">
<a class="db pv4 ph3 ph0-l no-underline dark-gray dim" href="{{ .Permalink }}">
<div class="flex flex-column flex-row-ns">
{{ if .Params.featured_image }}
{{ $featured_image := partial "featured.html" . }}
{{ if $featured_image }}
<div class="pr3-ns mb4 mb0-ns w-100 w-40-ns">
<img src="{{ .Params.featured_image }}" class="db" alt="image from {{ .Title }}">
<img src="{{ $featured_image }}" class="db" alt="image from {{ .Title }}">
</div>
{{ end }}
<div class="w-100{{ if .Params.featured_image }} w-60-ns pl3-ns{{ end }}">
<div class="w-100{{ if $featured_image }} w-60-ns pl3-ns{{ end }}">
<h1 class="f3 fw1 athelas mt0 lh-title">{{ .Title }}</h1>
<div class="f6 f5-l lh-copy nested-copy-line-height">
{{ .Summary }}
Expand Down