Skip to content

Commit

Permalink
Fallback to first bigimg when JavaScript disabled (#456)
Browse files Browse the repository at this point in the history
Solves #455 by statically
configuring the page source to use the source and description of the first image
in bigimg. When the description is empty, also pre-hides the description box.

When JavaScript is enabled, this theme's main.js
(https://github.com/halogenica/beautifulhugo/blob/master/static/js/main.js)
takes over and will overwrite this style attribute, changing the image in use.
  • Loading branch information
WJBarnes456 authored Jun 19, 2023
1 parent c774ab5 commit f0ff519
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@

{{ if or $bigimg $title }}
{{ if $bigimg }}
<div id="header-big-imgs" data-num-img={{len $bigimg}}
<div id="header-big-imgs" data-num-img={{len $bigimg}}
{{range $i, $img := $bigimg}}
{{ if (fileExists $img.src)}}
data-img-src-{{add $i 1}}="{{$img.src | absURL }}"
{{ if (fileExists $img.src)}}
data-img-src-{{add $i 1}}="{{$img.src | absURL }}"
{{else}}
data-img-src-{{add $i 1}}="{{$img.src}}"
data-img-src-{{add $i 1}}="{{$img.src}}"
{{end}}
{{ if $img.desc}}data-img-desc-{{add $i 1}}="{{$img.desc}}"{{end}}
{{end}}></div>
{{ end }}

<header class="header-section {{ if $bigimg }}has-img{{ end }}">
{{ if $bigimg }}
<div class="intro-header big-img">
{{ $firstimg := index $bigimg 0 }}
<div class="intro-header big-img" style="background-image: url('{{$firstimg.src}}');">
{{ $subtitle := $.Scratch.Get "subtitle" }}
<div class="container">
<div class="row">
Expand All @@ -50,7 +51,7 @@ <h2 class="{{ .Type }}-subheading">{{ $subtitle }}</h2>
</div>
</div>
</div>
<span class="img-desc" style="display: inline;"></span>
<span class="img-desc" style="display: {{ cond (isset $firstimg "desc") "inline" "none"}};">{{$firstimg.desc}}</span>
</div>
{{end}}
{{ if $title }}
Expand Down

0 comments on commit f0ff519

Please sign in to comment.