本文整理了 Demius 主题中最常用的两个文章增强组件:内置的链接卡片短代码 linkcard,以及外链跳转中转功能 linkRedirect。照着示例复制即可快速开箱。
链接卡片短代码(linkcard)
主题内置的链接卡片短代码是 linkcard。开启方式如下:
-
在
hugo.toml中打开样式与默认配置:[params.linkCard] enable = true defaultType = "auto" openInNewTab = true showArticleInfo = true showArticleDate = true showArticleSummary = true showUrl = true -
在 Markdown 中直接引用短代码,内部链接会自动读取文章的标题、摘要与日期:
{{< linkcard url="/posts/helloworld/" >}} -
常用可选参数:
type:auto/internal/externalnewtab,showinfo,showdate,showsummary,showurltitle,summary,date,ref
-
组合示例(自定义外链卡片):
{{< linkcard url="https://gohugo.io/documentation/" title="Hugo 官方文档" summary="配置、模板语法与部署指南" type="external" showurl="false" >}}
外链跳转中转功能
中转页面由 content/go.md(layout = "go")和 /themes/demius/layouts/go.html 驱动,前端脚本会自动把文章内容区域的外链改写为 /go/?goUrl=...。使用流程:
-
配置
params.linkRedirect:[params.linkRedirect] enable = true pagePath = "/go/" countdown = 3 showCountdown = true showButton = true safeMessage = "😃 💡倒计时结束自动跳转,也可自行点击跳转,请注意您的账号和财产安全" elementWhitelist = [".post-content"] pageWhitelist = [".*"] skipPatterns = [ # "https://example\\.com/.*" ] -
保持
content/go.md存在即可,无需在正文中额外操作。若某些链接不想被中转,可在 Markdown 中添加data-skip-link-redirect属性,或把匹配规则写进skipPatterns/safeWhitelist。
小提示:如果你需要在特定页面禁用中转,直接把对应的 URL 正则加入
skipPatterns,或者给链接添加data-skip-link-redirect即可。