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 dynamic copyright year handling #355

Closed
wants to merge 6 commits into from
Closed

Conversation

kowyo
Copy link
Contributor

@kowyo kowyo commented Apr 7, 2024

One of our organization member finds that the copyright year of both our website and Hextra doc is still "2023" yet. Hence I make some changes to theme to fix this.

This PR implements dynamic handling of the copyright year in the footer template. It fetches the beginning year from the configuration file(config.yaml) and dynamically updates the copyright text based on the current year.

The convention is referred from Copyrightlaws.com. Where it mentions that:

For constantly evolving websites and blogs that contain works published over several years, the notice may include a range of years (e.g., 2011–2023), starting from the date of the oldest published elements and ending with the date of the newest published elements.

Additionally, I also modify the exampleSite as well as i18n files to adapt to changes of this new feature. Let me know if I need more work on it. All code has been tested carefully.

Copy link

netlify bot commented Apr 7, 2024

Deploy Preview for hugo-hextra ready!

Name Link
🔨 Latest commit 2ae7f20
🔍 Latest deploy log https://app.netlify.com/sites/hugo-hextra/deploys/66123d40066a9a0008970b3e
😎 Deploy Preview https://deploy-preview-355--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 Apr 7, 2024

Hi, thank you for the PR. I guess #239 is a relevant issue.

I noticed that in the footer template

{{- if .Site.Params.footer.displayCopyright }}<div class="hx-mt-6 hx-text-xs">{{ $copyright | markdownify }}</div>{{ end }}

{{- $copyright := (T "copyright") | default "© 2023 Hextra." -}}
{{ $copyright | markdownify }}

the markdownify1 will render the copyright string as markdown content which also renders the shortcode if any.

That means if we have a shortcode, e.g. layouts/shortcodes/year.html that gives us the current year:

{{- time.Now.Year -}}

we could use this shortcode in i18n/en.yaml

copyright: "© {{`{{% year %}}`}} Your Project"

similarly we can have a since shortcode, and change the copyright field to:

copyright: "© {{`{{% since %}}`}}-{{`{{% year %}}`}} Your Project"

https://gohugo.io/functions/time/ has docs for the time functions

If this works for you, we could use this PR to add better docs for this, and close #239


Footnotes

  1. https://gohugo.io/functions/transform/markdownify/

@kowyo
Copy link
Contributor Author

kowyo commented Apr 7, 2024

Thank you for your advice! It is a great idea to utilize Hugo's features to implement this function. However, it may seem a little complex to add a specific shortcode to implement a simple function like this one. Actually I also referred another hugo theme, which inplement this feature in a more concise and standard manner.

I apologize if my code is not standard enough cause I have little formal opportunities to learn frontended development knowledge in school. Therefore, I suppose you could leave this pull request open for a more refined implementation. Nonetheless, I appreciate your thorough review.

@imfing
Copy link
Owner

imfing commented Apr 7, 2024

However, it may seem a little complex to add a specific shortcode to implement a simple function like this one. Actually I also referred another hugo theme, which implement this feature in a more concise and standard manner.

My intention was to let users easily tweak the copyright notice to their liking, without being stuck to the predefined © startYear-currentYear SOME TEXT. So, if someone wants to go with All rights reserved. Copyright Company Foo 2023 they totally can.

Regarding the standard format, I'm still unsure about it. First, users are able to hardcode the years under i18n/en.yaml like this:

copyright: "© 2023-2024 YOUR PROJECT"

This way, they don't have to change the start year, and updating the current year is just a once-a-year thing.

And if users are asking dynamically generated current year, they can do so via the the utility year shortcode I mentioned earlier:

copyright: "© 2023-{{`{{% year %}}`}} YOUR PROJECT"

From my point of view, this is slightly more easier than modifying the params.footer.since plus i18n/en.yaml just to update the copyright footer.

I apologize if my code is not standard enough

no worries at all. this is a great discussion!

@kowyo
Copy link
Contributor Author

kowyo commented Apr 8, 2024

Now I understand you. It does make it easier for user if they could simply edit in i18n.yaml. I will try to implement this in the coming days.

@jonasreiher
Copy link

I like this idea, I'm not sure what the best solution is, though (I'm also not a Hugo pro). From a user perspective, it would probably be most intuitive to only edit i18n/en.yaml and have something without extra shortcodes, like

copyright: "© 2023–{{ time.Now.Year }} Your Project"

@imfing
Copy link
Owner

imfing commented Apr 11, 2024

have something without extra shortcodes

unfortunately afaik it's not possible to use hugo template functions in Markdown content

@kowyo kowyo closed this by deleting the head repository May 24, 2024
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.

None yet

3 participants