PaperMod文章添加过时提醒

技术性文章没有内容提醒怎么行的,技术快速迭代,今天可以的方法明天可能就不行了 网上搜了一圈,对应主题的没找到现成的,只能魔改了 只针对PaperMod主题的,其他自己魔改,大同小异 1、添加自定义模版 Hugo根目录创建layouts\partials\outdated_warning.html 复制下面代码到 outdated_warning.html内 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 {{- if or .Params.enableOutdatedInfoWarning (and .Site.Params.outdatedInfoWarning.enable (ne .Params.enableOutdatedInfoWarning false)) }} {{- $daysAgo := div (sub now.Unix $.Page.Params.Lastmod.Unix) 86400 }} {{- $hintThreshold := .Site.Params.outdatedInfoWarning.hint | default 30 }} {{- $warnThreshold := .Site.Params.outdatedInfoWarning.warn | default 180 }} {{- $updateTime := $.Page.Params.Lastmod }} {{- if gt $daysAgo $hintThreshold }} <div class="post-outdated"> {{- if gt $daysAgo $warnThreshold }} <div class="warn"> {{- else }} <div class="hint"> {{- end }} <p>{{ i18n "outdatedInfoWarningBefore" .}} <span class="timeago" datetime="{{ dateFormat "2006-01-02T15:04:05" $updateTime }}" title="{{ dateFormat "January 2, 2006" $updateTime }}"> {{- dateFormat "January 2, 2006" $updateTime -}} </span>{{ i18n "outdatedInfoWarningAfter" .}} </p> </div> </div> {{- end -}} {{- end -}} 2、添加到文章模版内 Hugo根目录创建layouts/_default/single.html 在目录下方或者文章上方添加 1 2 3 4 5 6 7 8 {{ partial "outdated_warning.html" . }} {{- if ....

创建: 2023-03-26 | 更新: 2024-07-16 | 字数: 300字 | 时长: 2分钟 | 作者:张三