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

feat: update Headroom implementation to support recent Hugo versions #2950

Merged
merged 7 commits into from
Jul 30, 2023
Merged
Changes from all 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
39 changes: 35 additions & 4 deletions modules/wowchemy/layouts/partials/site_js.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,43 @@
<script src="{{ $js_algolia_search.RelPermalink }}" type="module"></script>
{{ end }}

{{/* Page Data */}}
{{ $default_headroom := not (.IsHome | or (eq .Type "book")) }}
{{ $use_headroom := cond (isset $.Params "header.on_scroll") (eq $.Params.header.on_scroll "disappear") (default $default_headroom) }}
{{/* Headroom */}}
{{/*
Headroom JS enables hiding the header on scrolling down and showing it on scrolling up.
This is especially valuable on smaller displays such as mobile devices.
This option can be set in the following ways:
- globally, in the site's 'params.yaml':
```
header:
on_scroll: "disappear" | "sticky"
```
- per page, in the page front matter:
```
header:
on_scroll: "disappear" | "sticky"
```
When the header is set to disappear, the Headroom JS is loaded.

By default, the header is sticky in the homepage and in the book layout,
and it disappears when scrolling in all other pages.
*/}}

{{/* By default don't use Headroom in the homepage and book layout */}}
{{ $use_headroom := not (.IsHome | or (eq .Type "book")) }}

{{/* Check for the global site parameter `header.on_scroll` */}}
{{ if (isset site.Params.header "on_scroll") }}
{{ $use_headroom = eq site.Params.header.on_scroll "disappear" }}
{{ end }}

{{/* Check for the page parameter `header.on_scroll` */}}
{{ if (isset $.Params.header "on_scroll") }}
{{ $use_headroom = eq $.Params.header.on_scroll "disappear" }}
{{ end }}

{{/* Output `use_headroom` variable for Headroom initialization in Wowchemy JS */}}
{{ printf "<script id=\"page-data\" type=\"application/json\">%s</script>" (dict "use_headroom" $use_headroom | jsonify) | safeHTML}}

{{/* Headroom */}}
{{ if $use_headroom }}
{{ $headroom := resources.Get "js/wowchemy-headroom.js" | js.Build (dict "format" "esm" "minify" true) }}
{{- if hugo.IsProduction -}}
Expand Down