5

Hugo升级0.74记录

 2 years ago
source link: https://wocai.de/post/2020/09/hugo%E5%8D%87%E7%BA%A70.74%E8%AE%B0%E5%BD%95/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

之前一直使用hugo的0.54版本,近期一不小心本地版本升级到了0.74,运行之后发现疯狂报错。

以下是填坑的记录:

Page.Hugo 方法将被移除 #

Page.Hugo is deprecated and will be removed in a future release. Use the global hugo function

出现的版本:v0.55

受影响的位置:

<!-- html head 部分 -->
<meta name="generator" content="Hugo {{ .Hugo.Version }}">
<!-- html head 部分 -->
<meta name="generator" content="Hugo {{ hugo.Version }}">

Page.Url 方法将被移除 #

Page.URL is deprecated and will be removed in a future release. Use .Permalink or .RelPermalink. If what you want is the front matter URL value, use .Params.url

出现的版本:v0.55

受影响的位置:

相当多地方,只要包含了这个语法,就需要替换。

<a class="pagination-prev" href="{{ $paginator.Prev.URL }}">← Prev Page</a>

解决方法:

全部替换为 .Permalink (绝对地址),或者 .RelPermalink (相对地址)。

.Page 发生变化 #

更大的问题是,0.74版本后,首页展示的文章列表全变了。经过查找,发现是0.57版本发生的变化。

新版的 .Page 只返回最高级别的文件目录,我之前的文件组织是 content/post/,现在竟然post变成了一个默认的入口,需要点进去才能看到文章。

请注意这个问题同样会影响到RSS的输出,记得把RSS也改了。

解决方法:

.Page 替换为 .Site.RegularPages 。这两者具体的区别见文档

强制使用Goldmark #

之前一直使用最老的mmark,在最新版本中已经要求升级为Goldmark了,切换方法很简单:

config.toml中添加:

[markup]
  defaultMarkdownHandler = "goldmark"

据说切换了之后会存在一些问题,目前还没有发现。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK