Skip to content

Commit

Permalink
feat(banner): allow specifying multiple images for different screens
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Aug 19, 2023
1 parent e54227f commit 0035183
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
11 changes: 8 additions & 3 deletions modules/banner/assets/hb/modules/banner/scss/index.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.hb-header {
&[data-banner] {
height: 100vh;
height: 100vh;

&[data-banner] {
.hb-header-nav {
background: transparent !important;
}
Expand All @@ -22,6 +22,11 @@
}
}

.hb-header-banner {
.hb-header-banner-img {
object-fit: cover;
}

.hb-header-banner,
.hb-header-banner-img {
height: 100vh;
}
46 changes: 32 additions & 14 deletions modules/banner/layouts/partials/hb/modules/header-banner/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
{{- with .Params.header.banner }}
{{- $img := relURL .img }}
{{- with $.Resources.GetMatch .img }}
{{- $img = .RelPermalink }}
{{- $sources := slice }}
{{- $img := "" }}
{{- if reflect.IsSlice .img }}
{{- range .img }}
{{- if .media }}
{{- $sources = $sources | append . }}
{{- else }}
{{- $img = .src | relURL }}
{{- end }}
{{- end }}
{{- else }}
{{- with resources.GetMatch .img }}
{{- $img = relURL .img }}
{{- with $.Resources.GetMatch .img }}
{{- $img = .RelPermalink }}
{{- else }}
{{- with resources.GetMatch .img }}
{{- $img = .RelPermalink }}
{{- end }}
{{- end }}
{{- end }}
<style>
.hb-header {
background-image: url('{{ $img }}');
}
</style>
<div class="hb-header-banner container d-flex flex-column justify-content-center text-white">
<div class="row">
<div class="col col-lg-8">
<h1 class="display-1">{{ default $.Title .title | markdownify }}</h1>
<div class="lead">{{ default $.Description .description | markdownify }}</div>
<picture>
{{- range $sources }}
<source
srcset="{{ .src }}"
media="{{ .media }}"
{{ with .type }}type="{{ . }}"{{ end }}/>
{{- end }}
<img class="img-fluid hb-header-banner-img d-block w-100 position-absolute top-0" src="{{ $img }}">
</picture>
<div class="hb-header-banner col d-flex flex-column justify-content-center text-white z-1 position-absolute top-0 w-100">
<div class="container">
<div class="row">
<div class="col col-lg-8">
<h1 class="display-1">{{ default $.Title .title | markdownify }}</h1>
<div class="lead">{{ default $.Description .description | markdownify }}</div>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 0035183

Please sign in to comment.