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
Open

Conversation

Gr3q
Copy link
Contributor

@Gr3q Gr3q commented Dec 16, 2024

See the documentation changes for explanation.

Still, I'm not sure if this is a feature that is wanted as is because it forces you to write html.

Unfortunately I couldn't find a way to use a markdown file as a partial instead unless it's like this https://stackoverflow.com/a/39800156.

Copy link

netlify bot commented Dec 16, 2024

Deploy Preview for hugo-hextra ready!

Name Link
🔨 Latest commit c36a1ef
🔍 Latest deploy log https://app.netlify.com/sites/hugo-hextra/deploys/676545f39cfe550008fd7006
😎 Deploy Preview https://deploy-preview-518--hugo-hextra.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@imfing
Copy link
Owner

imfing commented Dec 16, 2024

@Gr3q thank you, supporting custom footer is a nice feature to add.

I was thinking we can simplify your approach by adding custom/footer-end.html, and then update the footer.html to include it:

     <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 }}
+      {{ partial "custom/footer-end.html" . }}
     </div>

thus, we can use hugo template syntax like this to render markdown from either in the template or load a param from hugo config file

{{ "**hello**" | markdownify }}

<!-- or load from your own custom parameter -->
{{ site.Params.footer.customFooter | markdownify }}

example hugo.yaml

  footer:
    enable: true
    displayCopyright: false
    displayPoweredBy: false
    width: normal
    customFooter: "**custom footer**" # you can change or add your own param

output:

image

@Gr3q
Copy link
Contributor Author

Gr3q commented Dec 17, 2024

thus, we can use hugo template syntax like this to render markdown from either in the template or load a param from hugo config file

markdownify only supports markdown features as long as it resolves to a single paragraph, so I can't do tables headings etc if I want to (I don't, but some other layout would come handy). And I can do the same with the copyright string.

I was thinking we can simplify your approach by adding custom/footer-end.html, and then update the footer.html to include it:

I started with that and I found the padding around too limiting. Still it's a good idea, except the footer should be sandwiched between the copyright/powered by text and the theme buttons (if it's a page that has the theme buttons there) separated by dividers.

The reason is that most websites have the copyright section on the very bottom but I can't link to some dataset to back up that claim.

@Gr3q
Copy link
Contributor Author

Gr3q commented Dec 17, 2024

So I can change the PR to complement the copyright section instead of replacing it.

In that case I'll try to upstream some other things in more PRs like changing the footer background/text color and the copyright section layout (centered and in a row instead of having a column)

Comment on lines 32 to 33
{{ partial "custom/footer.html" (dict "context" . "footerButtonColor" "hx-rounded-md hx-transition-colors hover:hx-bg-gray-100 hover:hx-text-gray-900 dark:hover:hx-bg-primary-100/5 dark:hover:hx-text-gray-50" ) }}
</div>
Copy link
Owner

Choose a reason for hiding this comment

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

footerButtonColor is not necessary here right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, but the other option is to dig through the hextra codebase to match it. I'll remove it.

```yaml {filename="hugo.yaml"}
footer:
enable: true
customSection: true
Copy link
Owner

Choose a reason for hiding this comment

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

I would avoid adding a new flag if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove it but then I don't know when I should show the separator and when I shouldn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I just remove the separator, people can add it back in their custom footer.

@Gr3q
Copy link
Contributor Author

Gr3q commented Dec 18, 2024

I also added a visually breaking change to only show footer section for Copyright and PoweredBy if at least one of them are enabled. This saves people that don't want the default layout of that section and they want to recreate it in the custom section.

Out of the box the footer is there unless people explicitly disable poweredby and the copyright section.

Edit: I added 2 necessary variables that you would have a hard time solving with css alone, especially if you want avoid duplicate dividers in all cases.

@Gr3q Gr3q requested a review from imfing December 18, 2024 11:22
Copy link
Owner

@imfing imfing left a comment

Choose a reason for hiding this comment

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

Let's keep the left and right padding.

I tried your change with a custom html footer in custom/footer.html

<div style="display: flex; justify-content: space-between; padding-top: 20px;">
  <div style="flex: 1;">
      <h4 style="margin-bottom: 10px; font-weight: 600;">About Us</h4>
      <p>Learn more about our company.</p>
  </div>
  <div style="flex: 1;">
      <h4 style="margin-bottom: 10px; font-weight: 600;">Services</h4>
      <ul style="list-style: none; padding: 0;">
          <li style="margin: 5px 0;">Web Design</li>
          <li style="margin: 5px 0;">SEO</li>
          <li style="margin: 5px 0;">Consulting</li>
      </ul>
  </div>
  <div style="flex: 1;">
      <h4 style="margin-bottom: 10px; font-weight: 600;">Contact</h4>
      <p>Email: [email protected]</p>
      <p>Phone: 123-456-7890</p>
  </div>
</div>

image

It works pretty well

Comment on lines 30 to 31
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

<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"
>
{{ 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.

@Gr3q Gr3q requested a review from imfing December 20, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants