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: Add support for custom footer #518

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
9 changes: 9 additions & 0 deletions assets/css/compiled/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,9 @@ video {
.hx-gap-4 {
gap: 1rem;
}
.hx-gap-6 {
gap: 1.5rem;
}
.hx-gap-x-1\.5 {
-moz-column-gap: 0.375rem;
column-gap: 0.375rem;
Expand Down Expand Up @@ -1152,6 +1155,9 @@ video {
.hx-pb-px {
padding-bottom: 1px;
}
.hx-pl-\[max\(env\(safe-area-inset-left\)\,0rem\)\] {
padding-left: max(env(safe-area-inset-left),0rem);
}
.hx-pl-\[max\(env\(safe-area-inset-left\)\,1\.5rem\)\] {
padding-left: max(env(safe-area-inset-left),1.5rem);
}
Expand All @@ -1167,6 +1173,9 @@ video {
.hx-pr-\[max\(env\(safe-area-inset-left\)\,1\.5rem\)\] {
padding-right: max(env(safe-area-inset-left),1.5rem);
}
.hx-pr-\[max\(env\(safe-area-inset-right\)\,0rem\)\] {
padding-right: max(env(safe-area-inset-right),0rem);
}
.hx-pr-\[max\(env\(safe-area-inset-right\)\,1\.5rem\)\] {
padding-right: max(env(safe-area-inset-right),1.5rem);
}
Expand Down
15 changes: 15 additions & 0 deletions exampleSite/content/docs/advanced/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ You may add custom scripts to the end of the head for every page by adding the f
layouts/partials/custom/head-end.html
```

## Custom Footer Section

You can add a custom section the footer between the language/theme buttons and the Copyright/Powered By section by creating a file `layouts/partials/custom/footer.html` in your site.

```html {filename="layouts/partials/custom/footer.html"}
<!-- Your footer element here -->
```

Available variables in the footer section are:

- `.aboveVisible`: `true` if the Language or Theme button(s) are visible above the footer along with a horizontal separator.
- `.belowVisible`: `true` if the Copyright or PoweredBy text are visible below the footer.

_Note: The custom footer inherits the default footer background color text color and the `width` setting in `hugo.yaml#footer` section._

## Custom Layouts

The layouts of the theme can be overridden by creating a file with the same name in the `layouts` directory of your site.
Expand Down
3 changes: 3 additions & 0 deletions exampleSite/hugo_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@
"hx-gap-1",
"hx-gap-2",
"hx-gap-4",
"hx-gap-6",
"hx-gap-x-1.5",
"hx-gap-y-2",
"hx-grid",
Expand Down Expand Up @@ -430,12 +431,14 @@
"hx-pb-8",
"hx-pb-[env(safe-area-inset-bottom)]",
"hx-pb-px",
"hx-pl-[max(env(safe-area-inset-left),0rem)]",
"hx-pl-[max(env(safe-area-inset-left),1.5rem)]",
"hx-pointer-events-none",
"hx-pr-2",
"hx-pr-4",
"hx-pr-[calc(env(safe-area-inset-right)-1.5rem)]",
"hx-pr-[max(env(safe-area-inset-left),1.5rem)]",
"hx-pr-[max(env(safe-area-inset-right),0rem)]",
"hx-pr-[max(env(safe-area-inset-right),1.5rem)]",
"hx-pt-4",
"hx-pt-6",
Expand Down
Empty file.
25 changes: 17 additions & 8 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{{- $enableFooterSwitches := .Scratch.Get "enableFooterSwitches" | default false -}}
{{- $displayThemeToggle := site.Params.theme.displayToggle | default true -}}
{{- $footerSwitchesVisible := and $enableFooterSwitches (or hugo.IsMultilingual $displayThemeToggle) -}}
{{- $copyrightSectionVisible := or (.Site.Params.footer.displayPoweredBy | default true) .Site.Params.footer.displayCopyright -}}

{{- $copyright := (T "copyright") | default "© 2024 Hextra." -}}
{{- $poweredBy := (T "poweredBy") | default "Powered by Hextra" -}}
Expand All @@ -15,7 +17,7 @@


<footer class="hextra-footer hx-bg-gray-100 hx-pb-[env(safe-area-inset-bottom)] dark:hx-bg-neutral-900 print:hx-bg-transparent">
{{- if and $enableFooterSwitches (or hugo.IsMultilingual $displayThemeToggle) -}}
{{- if $footerSwitchesVisible -}}
<div class="hx-mx-auto hx-flex hx-gap-2 hx-py-2 hx-px-4 {{ $footerWidth }}">
{{- partial "language-switch.html" (dict "context" .) -}}
{{- with $displayThemeToggle }}{{ partial "theme-toggle.html" }}{{ end -}}
Expand All @@ -24,14 +26,21 @@
<hr class="dark:hx-border-neutral-800" />
{{- end -}}
{{- end -}}
<div
class="{{ $footerWidth }} hx-mx-auto hx-flex hx-justify-center hx-py-12 hx-pl-[max(env(safe-area-inset-left),1.5rem)] hx-pr-[max(env(safe-area-inset-right),1.5rem)] hx-text-gray-600 dark:hx-text-gray-400 md:hx-justify-start"
>
<div class="hx-flex hx-w-full hx-flex-col hx-items-center sm:hx-items-start">
{{- if (.Site.Params.footer.displayPoweredBy | default true) }}<div class="hx-font-semibold">{{ template "theme-credit" $poweredBy }}</div>{{ end }}
{{- if .Site.Params.footer.displayCopyright }}<div class="hx-mt-6 hx-text-xs">{{ $copyright | markdownify }}</div>{{ end }}
<div
class="{{ $footerWidth }} hx-pl-[max(env(safe-area-inset-left),0rem)] hx-pr-[max(env(safe-area-inset-right),0rem)] hx-text-gray-600 dark:hx-text-gray-400"
>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer keep the left and right padding, e.g.

<div class="{{ $footerWidth }} hx-mx-auto hx-pl-[max(env(safe-area-inset-left),1.5rem)] hx-pr-[max(env(safe-area-inset-right),1.5rem)] hx-text-gray-600 dark:hx-text-gray-400" >

to make this section styling more consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, but I will add a custom class so people can customize its style

{{ partial "custom/footer.html" (dict "context" . "aboveVisible" $footerSwitchesVisible "belowVisible" $copyrightSectionVisible ) }}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are these variables used for exactly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aboveVisible - My use case is that I want to add a separator on the top of my custom footer but on pages where the theme/language switcher is above the footer I would end up with two separators that is visually noticeable.

Solving that with only CSS in custom.css might be impossible or extremely hacky, so it's useful to expose this in case users want to change the content or styling of the custom footer based on what is above.

belowVisible is the same thing for the PoweredBy/Copyright section but I admit I can't think of a concrete use case for this at the moment. Maybe an user wants to add extra margin on the bottom if the section is not visible? Although currently that section is not dynamic.

</div>
</div>
{{- if $copyrightSectionVisible -}}
<div
class="{{ $footerWidth }} hx-mx-auto hx-flex hx-justify-center hx-py-12 hx-pl-[max(env(safe-area-inset-left),1.5rem)] hx-pr-[max(env(safe-area-inset-right),1.5rem)] hx-text-gray-600 dark:hx-text-gray-400 md:hx-justify-start"
>
<div class="hx-flex hx-w-full hx-flex-col hx-items-center sm:hx-items-start hx-gap-6">
{{- if (.Site.Params.footer.displayPoweredBy | default true) }}<div class="hx-font-semibold">{{ template "theme-credit" $poweredBy }}</div>{{ end }}
{{- if .Site.Params.footer.displayCopyright }}<div class="hx-text-xs">{{ $copyright | markdownify }}</div>{{ end }}
</div>
</div>
{{- end -}}
</footer>

{{- define "theme-credit" -}}
Expand Down