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

Require Hugo 0.120+, fix deprecation warnings #502

Merged
merged 8 commits into from
Jul 11, 2024

Conversation

hydr0nium
Copy link
Contributor

I changed the parameter .site.IsServer parameter to hugo.isServer because the first one is deprecated.

@henryiii
Copy link
Collaborator

Any idea of how far back the new one works?

@henryiii
Copy link
Collaborator

New in 0.120 https://gohugo.io/functions/hugo/isserver/

Did they have to deprecate the same version they added the replacement?

@henryiii
Copy link
Collaborator

Eh, we are on 0.128 now, so I'd be okay with making 0.120 the minimum, I think. Anyone else?

@hydr0nium
Copy link
Contributor Author

hydr0nium commented Jul 10, 2024

@henryiii

I would say that being basically 8 versions ahead of the deprecated function is enough.


I also found another deprecated feature .Site.DisqusShortname which also got deprecated since 0.120. If we change to 0.128 0.120 we can also update that as well.

@hydr0nium hydr0nium changed the title Fixed deprecated .site.IsServer parameter Fixed deprecated .functions Jul 10, 2024
@hydr0nium hydr0nium changed the title Fixed deprecated .functions Fixed deprecated functions Jul 10, 2024
In the face of that we will update to 0.120 it would also be nice to update the README to reference the hugo.* file as the config instead of the config.* file.
I also changed the description of the disqus feature to match the updated version of the code
@henryiii
Copy link
Collaborator

Can we make it a hard error (errorf) if too old?

@hydr0nium
Copy link
Contributor Author

hydr0nium commented Jul 10, 2024

Could we use the min_version parameter in the theme.toml and HUGO_VERSION in netlify.toml file?

@hydr0nium
Copy link
Contributor Author

Other than that we could maybe use the errorf and the hugo.Version function to check if a specific version is used. Just don't know where we would put it

@henryiii
Copy link
Collaborator

The theme.toml one sounds good. I assume Hugo would error with a nice message if that was too high.

@@ -1,7 +1,7 @@
{{ if (.Params.comments) | or (and (or (not (isset .Params "comments")) (eq .Params.comments nil)) (.Site.Params.comments)) }}
{{ if .Site.DisqusShortname }}
{{ if .Site.Config.Services.Disqus.Shortname }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we error if Site.DisqusShortname is set? Similar to what I added in #481? Otherwise no one will know this was changed, it will just vanish from sites.

Copy link
Contributor Author

@hydr0nium hydr0nium Jul 10, 2024

Choose a reason for hiding this comment

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

Yeah I guess you can add that. Sounds good.

Edit: I can also add it if you have not time for that

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you'd like to, go ahead. Pretty distracted at the moment with catch up in various projects.

Copy link
Contributor Author

@hydr0nium hydr0nium Jul 11, 2024

Choose a reason for hiding this comment

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

Ok you can not access the disqusShortname as you did with author due to the fact that it is a default value in .Site and will always be set by default to the empty string. As far as I see it there is not a proper way of checking if people use this deprecated feature without getting a warning because we need to use .Site.disqusShortname to actually check if people use it. I would say a compromise is that we do a check in a central location using .Site.disqusShortname with a warning that after sometime this check will be removed as .Site.disqusShortname is deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My idea is to use this in the baseof.html

{{ if le hugo.Version "0.120.0" }}
	{{ errorf "Please use Hugo version 0.120.0 or higher!"}}
{{ end }}

{{ if not (eq .Site.DisqusShortname "") }}
	{{ errorf "Your use of disqusShortname is deprecated by Hugo; Please reference the README.md for further instructions.
	This error message will be removed in the future because we are also using .Site.DisqusShortname for checking this."}}
{{ end }}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems reasonable. I can move the other check (Site.Author) there too after it's in.

@hydr0nium
Copy link
Contributor Author

hydr0nium commented Jul 10, 2024

The theme.toml one sounds good. I assume Hugo would error with a nice message if that was too high.

I did some tests and changing theme.toml would result in telling the user that they are using the wrong version. The problem is though that it does not stop the build.

Maybe adding another check in something like the baseof.html with the hugo.Version and errorf would be a second measure to stop the build.

@henryiii
Copy link
Collaborator

Would you mind rebasing or merging to resolve conflicts? Then I'll trigger the CI.


{{ if not (eq .Site.DisqusShortname "") }}
{{ errorf "Your use of disqusShortname is deprecated by Hugo; Please reference the README.md for further instructions.
This error message will be removed in the future because we are also using .Site.DisqusShortname for checking this."}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are multiple lines allowed?

ERROR "/home/runner/work/beautifulhugo/beautifulhugo/layouts/_default/baseof.html:6:1": parse failed: template: _default/single.html:6: unterminated quoted string

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 think the problem is somewhere in the single.html, but I can't find where.

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 will take a look soon

Copy link
Collaborator

Choose a reason for hiding this comment

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

It says line 6 of baseof.html, which is exactly this multiline string.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe you need tick-marks instead? gohugoio/hugoDocs#764

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed now

@henryiii henryiii changed the title Fixed deprecated functions Require Hugo 0.120+, fix deprecation warnings Jul 11, 2024
Comment on lines +93 to +95
[services]
[services.disqus]
shortname = ''
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
[services]
[services.disqus]
shortname = ''
[services.disqus]
shortname = ''

Probably matches everything else, so not changing it here, but I really don't like this fake TOML nesting. Pretending TOML cares about indentation when it doesn't isn't helpful, IMO.

@henryiii henryiii merged commit 484d57f into halogenica:master Jul 11, 2024
1 check passed
@henryiii
Copy link
Collaborator

Thanks for pushing this through!

@hydr0nium hydr0nium deleted the deprecated_code branch July 11, 2024 17:02
sunpech pushed a commit to sunpech/beautifulhugo that referenced this pull request Aug 18, 2024
* Fixed deprecated site.isServer param to hugo.isServer param

* Also fixed another deprecated function for disqus

* Updated README.md

In the face of that we will update to 0.120 it would also be nice to update the README to reference the hugo.* file as the config instead of the config.* file.
I also changed the description of the disqus feature to match the updated version of the code

* Added checks for hugoVersion and disqus feature

* Fixed accidental delete

* Removed new line
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

2 participants