menu

hugo添加相关内容

修改主题中的如下文件,如果没有可以创建。

layouts / partials / related.html

\{\{ $related := .Site.RegularPages.Related . \| first 5 \}\}
\{\{ with $related \}\}
<h3>See Also</h3>
<ul>
	\{\{ range . \}\}
	<li><a href="\{\{ .RelPermalink \}\}"></a></li>
	
</ul>
\{\{ end \}\}

config.toml文件中添加如下内容

[related]
  includeNewer = false
  threshold = 80
  toLower = false

  [[related.indices]]
    name = "keywords"
    weight = 100
    
  [[related.indices]]
    name = "tags"
    weight = 90
    
  [[related.indices]]
    name = "date"
    weight = 10

发布文章时候不要忘记在头部添加tags内容,还有可以添加keywords.

tags:
- niubi
- haha

文档地址 https://gohugo.io/content-management/related/

编辑