Replacing Deprecated Hugo Syntax in Blog Theme

Fixing Beautiful Hugo issue #261

Problem

Since the recent Hugo upgrade to v0.55.3, the following messages popped up after each local site regeneration with hugo server.

WARN 2019/04/24 18:07:00 Page's .URL is deprecated and will be removed in a futu
re release. Use .Permalink or .RelPermalink. If what you want is the front matte
r URL value, use .Params.url.
WARN 2019/04/24 18:07:00 Page's .Hugo is deprecated and will be removed in a fut
ure release. Use the global hugo function.
WARN 2019/04/24 18:07:00 Page's .RSSLink is deprecated and will be removed in a 
future release. Use the Output Format's link, e.g. something like: 
    {{ with .OutputFormats.Get "RSS" }}{{ .RelPermalink }}{{ end }}.
Total in 136 ms

GitLab’s online runner also gave the same type of warnings. This was reported in Beautiful Hugo issue #261.

Goal

To suppress the above warning messages.

Cause

The above warning messages are self-explanatory.

Deprecated New Source
{{ .Hugo.Generator }} {{ hugo.Generator }} .Hugo.Generator は廃止されるので hugo.Generator を使おう
{{ .RSSLink }} {{ with .OutputFormats.Get "RSS" }}{{ . RelPermalink }}{{ end }} Hugo Introduction theme pull request #146
{{ .Hugo.Version }} {{ .Site.Hugo.Version }} My question on Hugo Discourse
{{ .URL }} {{ .Permalink }}/{{ .RelPermalink }} Hugo Introduction theme at commit 8c258bbd

For the last row, I’ve preferred, in general, the former over the later unless for the link “[Read more]” and for Staticman’s page $slug, which is actually the post’s relative permalink with slashes / stripped off.

Difficulties

After some trial and error, I’ve observed that:

  1. {{ .URL }} in layouts/partials/nav.html doesn’t need to be replaced since it represents the site’s URL.
  2. {{ hugo.Version }} works well in Go-HTML template files, but not in YAML files. I posted a question on Stack Overflow, but it got quickly drowned by an array of newer questions. Therefore, I wrote another question on Hugo Discourse. Thanks to @bep’s solution ({{ .Site.Hugo.Version }}), I’ve completed this replacement of deprecated Hugo syntax on the fix-dotHugo-deprecated branch.

Aftermath

  1. I’ve created pull request #269 to solve issue #261.
  2. I’ve merged fix-dotHugo-deprecated against dev branch. There’s a merge conflict due to my tweaks on the theme for nested Staticman comments.

1 comment

Your email address will not be published. Required fields are marked *.