【发布时间】:2022-05-04 06:05:32
【问题描述】:
使用链接到 Add template for taxonomies to Blogdown default theme 的指南,我能够添加标签以显示在我的帖子顶部并创建一个 /tags 页面 - 用于我的锂主题 Hugo 博客网站。
如何让帖子标签显示在我的锂主题网站的摘要中(即它们显示在主页上)?
【问题讨论】:
标签: html r r-markdown hugo blogdown
使用链接到 Add template for taxonomies to Blogdown default theme 的指南,我能够添加标签以显示在我的帖子顶部并创建一个 /tags 页面 - 用于我的锂主题 Hugo 博客网站。
如何让帖子标签显示在我的锂主题网站的摘要中(即它们显示在主页上)?
【问题讨论】:
标签: html r r-markdown hugo blogdown
首先,将以下 HTML 添加到您的 layouts/_default/list.html 模板中,在 <article> 标记内和 <div class="summary"> 之后。
{{ with (.GetTerms "tags") }}
<div class="tags">
{{ range . }}
<div class="tag">
<a href="{{ .Permalink }}">{{ .LinkTitle }}</a>
</div>
{{ end }}
</div>
{{ end }}
然后为了让它看起来更好,你可以添加一些类似这样的CSS:
.tags {
display: flex;
flex-flow: row wrap;
gap: 8px;
}
.tags .tag {
/* override the `margin: auto;` rule which applies to all divs and iframes,
* defined in main.css */
margin: 0;
font-size: small;
}
我提供的代码如下所示:
【讨论】: