- 前端
【免费下载链接】hugo-theme-academic-cv
🎓 Academic portfolio that boosts citations. AI generates pages, you own as Markdown. BibTeX auto-import, Jupyter, LaTeX, slides, visual block editor — free to host forever. 学术主页,AI 生成,Markdown 拥有 👇
本篇指南系统讲解 Academic CV 学术主页模板(hugo-theme-academic-cv,基于 Hugo Blox 框架)内置的button短代码(shortcode)。你可以在任何 Markdown 页面中通过一行短代码生成带渐变样式、图标与智能链接处理的现代按钮,用于联系方式、论文下载、外部链接跳转、课程引导等场景。读完本文,你将掌握button短代码的全部参数、六类视觉变体组合方式,以及其内置的安全与无障碍特性,并能在博客、事件、课程等页面中直接复用仓库内已沉淀的实战写法。
短代码概述与实现来源
button短代码定义于 button.md,属于 Hugo Blox 格式化组件体系(formatting 指南索引)的一员,与callout、cards、toggle、steps等组件并列。
其实际渲染实现并非位于本仓库的layouts/目录,而是通过 Hugo Modules 机制从外部模块引入:在 module.yaml 中可以看到本模板导入了github.com/HugoBlox/kit/modules/blox等模块,go.mod 中对应声明了github.com/HugoBlox/kit/modules/blox的版本依赖。因此,你在自己的 Markdown 内容中使用该短代码时,构建期由 Hugo 从模块中查找并渲染按钮,无需在仓库内维护任何模板文件——这正是 Hugo Blox "Markdown 拥有内容、组件开箱即用" 的设计体现。
基本用法
button短代码采用成对(带包裹内容)的写法,url是唯一必填参数,按钮文字写在短代码包裹的中间:
{{</* button url="/contact" */>}}Contact Us{{</* /button */>}} {{</* button url="https://example.com" new_tab="true" style="secondary" */>}}Visit External Site{{</* /button */>}}渲染效果即两个按钮:
{{< button url="/contact" >}}Contact Us{{< /button >}}
{{< button url="https://example.com" new_tab="true" style="secondary" >}}Visit External Site{{< /button >}}
其中第一个按钮是站内相对链接(/contact),第二个是外链,并通过new_tab="true"在新标签页打开、用style="secondary"切换为次要样式。
除了成对写法,短代码还支持自闭合写法,并用text参数直接指定按钮文字,这在按钮文字包含复杂内容时可避免包裹歧义。仓库的 events 示例页 中即有大量这种用法:
{{</* button url="https://docs.hugoblox.com/guides/studio/" text="Try Ownable CMS" icon="paint-brush" style="secondary" size="md" new_tab="true" rounded="lg" */>}}样式变体(Style)
通过style参数可以在四种视觉风格之间切换,默认值为primary:
Primary(默认)
{{< button url="#" style="primary" >}}Primary Button{{< /button >}}
{{</* button url="#" style="primary" */>}}Primary Button{{</* /button */>}}Secondary
{{< button url="#" style="secondary" >}}Secondary Button{{< /button >}}
{{</* button url="#" style="secondary" */>}}Secondary Button{{</* /button */>}}Outline
{{< button url="#" style="outline" >}}Outline Button{{< /button >}}
{{</* button url="#" style="outline" */>}}Outline Button{{</* /button */>}}Ghost
{{< button url="#" style="ghost" >}}Ghost Button{{< /button >}}
{{</* button url="#" style="ghost" */>}}Ghost Button{{</* /button */>}}实际选型建议:页面主操作(如 "Get Started")用primary;次要与辅助操作(如 "Learn More")用secondary或outline;需要弱化视觉层级、融入内容流的操作(如 "View Source Code")用ghost。仓库的>{{</* button url="#" size="sm" */>}}Small Button{{</* /button */>}} {{</* button url="#" size="md" */>}}Medium Button{{</* /button */>}} {{</* button url="#" size="lg" */>}}Large Button{{</* /button */>}} {{</* button url="#" size="xl" */>}}Extra Large{{</* /button */>}}
尺寸应与使用场景匹配:页面内嵌的小型操作(如列表行内的 "Read")用sm;正文内的常规按钮用默认md;页面级主 CTA 用lg;需要视觉冲击力的整页横幅按钮(如 events 示例页 中的 "Get Started Now")用xl。
对齐(Alignment)
通过align参数控制按钮在页面流中的对齐方式,默认值为left:
{{< button url="#" align="left" >}}Left Aligned{{< /button >}}
{{< button url="#" align="center" >}}Center Aligned{{< /button >}}
{{< button url="#" align="right" >}}Right Aligned{{< /button >}}
{{</* button url="#" align="left" */>}}Left Aligned{{</* /button */>}} {{</* button url="#" align="center" */>}}Center Aligned{{</* /button */>}} {{</* button url="#" align="right" */>}}Right Aligned{{</* /button */>}}align="center"常用于独立成段的宣传性 CTA;align="right"可用于表格、卡片旁的操作位。注意对齐针对的是按钮在行内的排列位置,多个按钮各自声明align即可实现并列或分布效果。
图标(Icon)
button短代码内置 Hero Icons 图标支持。icon参数指定图标名称(默认图标置于文字左侧),icon_position控制图标位置,默认left,可设为right:
图标位于文字之前
{{< button url="#" icon="arrow-down-tray" >}}Download{{< /button >}}
图标位于文字之后
{{< button url="#" icon="arrow-right" icon_position="right" >}}Continue{{< /button >}}
{{</* button url="#" icon="arrow-down-tray" */>}}Download{{</* /button */>}} {{</* button url="#" icon="arrow-right" icon_position="right" */>}}Continue{{</* /button */>}}关于图标命名空间,从仓库实际使用可以观察到两种模式:直接使用图标名(如icon="chart-bar"、icon="rocket-launch"、icon="document-arrow-down"),以及使用带前缀的命名空间写法(如 events 示例页 中的icon="brands/github",用于渲染品牌类图标)。前者适用于通用操作图标,后者适用于品牌 Logo 场景。图标应与动作语义一致:下载类用arrow-down-tray/document-arrow-down,前进类用arrow-right/arrow-top-right-on-square,启动类用rocket-launch。
圆角(Rounded Corners)
通过rounded参数控制按钮圆角,默认值为md,可选sm、md、lg、full:
Small Radius
{{< button url="#" rounded="sm" >}}Small Radius{{< /button >}}
Medium Radius(默认)
{{< button url="#" rounded="md" >}}Medium Radius{{< /button >}}
Large Radius
{{< button url="#" rounded="lg" >}}Large Radius{{< /button >}}
Pill Shape(胶囊形)
{{< button url="#" rounded="full" >}}Pill Button{{< /button >}}
{{</* button url="#" rounded="sm" */>}}Small Radius{{</* /button */>}} {{</* button url="#" rounded="md" */>}}Medium Radius{{</* /button */>}} {{</* button url="#" rounded="lg" */>}}Large Radius{{</* /button */>}} {{</* button url="#" rounded="full" */>}}Pill Button{{</* /button */>}}圆角风格应与整体设计语言保持一致:学术站点通常使用md或lg的适度圆角,full胶囊形更适合品牌化 CTA。仓库中>{{</* button url="/signup" style="primary" size="lg" align="center" icon="rocket-launch" */>}}Get Started Today{{</* /button */>}}
新标签页打开的外链按钮
{{< button url="https://github.com/hugo-blox/kit" new_tab="true" style="outline" icon="arrow-top-right-on-square" icon_position="right" >}}View on GitHub{{< /button >}}
{{</* button url="https://github.com/hugo-blox/kit" new_tab="true" style="outline" icon="arrow-top-right-on-square" icon_position="right" */>}}View on GitHub{{</* /button */>}}下载按钮
{{< button url="/files/document.pdf" style="secondary" icon="document-arrow-down" rounded="full" >}}Download PDF{{< /button >}}
{{</* button url="/files/document.pdf" style="secondary" icon="document-arrow-down" rounded="full" */>}}Download PDF{{</* /button */>}}三个示例覆盖了三种典型场景:站内转化(/signup)、站外跳转(GitHub 链接 + 新标签 + 图标后置)、资源下载(PDF 文件 + 下载图标 + 胶囊圆角)。注意下载类按钮的url指向站内static目录资源(如本仓库 static/uploads 下的文件)或外链文件均可。
参数速查表
以下是button短代码的完整参数清单:
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
url | string | # | 必填。按钮目标地址,支持站内相对链接与外部绝对链接 |
text | string | 包裹内容 | 按钮文字,设置后覆盖短代码包裹内的内容 |
new_tab | boolean | false | 是否在新标签页打开链接 |
style | string | primary | 按钮样式:primary、secondary、outline、ghost |
size | string | md | 按钮尺寸:sm、md、lg、xl |
align | string | left | 按钮对齐:left、center、right |
icon | string | - | 图标名称(Hero Icons 图标集,也支持brands/github等前缀写法) |
icon_position | string | left | 图标位置:left、right |
rounded | string | md | 圆角大小:sm、md、lg、xl、full |
disabled | boolean | false | 是否禁用按钮 |
要点提示:
url为#时按钮仅作占位展示、不产生实际跳转,适合在文档中演示样式(本文示例即如此);text与包裹内容二选一即可,二者同时给出时text优先;rounded参数表同时列出了xl,可用于需要介于lg与full之间的圆角;disabled="true"会在渲染层输出禁用态,配合无障碍特性保证键盘与屏幕阅读器用户也能感知按钮不可交互。
安全特性:外链 rel 属性自动处理
button短代码会自动为外链注入安全属性,避免反向标签伪造(tabnabbing)等风险,具体规则为:
- 站外链接自动附加
rel="noreferrer"; - 站外链接且新标签打开(
new_tab="true")自动附加rel="noopener noreferrer"; - 站内链接且新标签打开自动附加
rel="noopener"。
也就是说,你无需手动记忆noopener/noreferrer的搭配规则——短代码会根据url是否为外部地址、是否new_tab="true"自动推导出最严格的组合,在保证新标签页安全导航的同时不影响链接正常跳转。在学术站点中,正文里大量引用 GitHub、DOI、机构官网等外链,这一特性让"外链 + 新标签"的常见组合默认处于安全状态。
无障碍特性(Accessibility)
button短代码内置了开箱即用的无障碍支持:
- 输出包含正确的
role="button"属性,确保语义正确; - 支持
aria-label,便于为图标按钮等无文本场景补充可访问名称; - 内置键盘焦点指示器,键盘用户可以通过 Tab 聚焦并回车触发;
- 高对比度焦点环,保证弱光环境与视力障碍用户也能清晰辨识焦点位置;
- 完整的禁用状态处理,
disabled时同步更新 ARIA 状态,屏幕阅读器可正确播报。
这些特性由短代码渲染层统一保障,意味着你只需关注url、icon等业务参数,无需为每个按钮手写 ARIA 属性。
仓库内实战案例参考
除 button.md 的示例外,本仓库还有多处真实业务页面可直接参考:
- data-visualization 博客:数据可视化文章中组合了基础按钮、数据动作按钮(View Dashboard / Download Data / View Source Code)与成对的居中胶囊按钮(Try Jupyter / Open in Colab),展示了数据分析内容页的 CTA 布局范式;
- events 示例页:会议/事件页中使用了
text参数的自闭合写法,并混用style、size、rounded、icon="brands/github"等参数,覆盖了 CMS 入口、文档链接、幻灯片新标签打开、GitHub Star 等多样场景。
小结
button短代码以极低的上手成本(仅url必填)覆盖了按钮设计的大多数维度:四种样式、四种尺寸、三种对齐、图标与位置、五档圆角,同时内置外链安全属性与无障碍支持。在 Academic CV 模板中,将其用于联系方式、论文下载、课程报名、项目演示与外部链接跳转,可显著提升页面的转化引导与可读性。完整规范以 button.md 为准,并可通过 formatting 指南索引 继续学习callout、cards、steps、toggle等配套格式化组件。
- 前端
【免费下载链接】hugo-theme-academic-cv
🎓 Academic portfolio that boosts citations. AI generates pages, you own as Markdown. BibTeX auto-import, Jupyter, LaTeX, slides, visual block editor — free to host forever. 学术主页,AI 生成,Markdown 拥有 👇
相关推荐
Agent Reach社区与支持渠道指南:Issue、微信群与作者邮箱全汇总
Agent Reach社区与支持渠道指南:Issue、微信群与作者邮箱全汇总 Agent Reach 是一款开源 CLI 工具,给你的 AI Agent 一键装
人工智能AI Agent工具调用AI 技能MCP 服务网页爬虫RSUITE IconButton 组件完全指南:带图标按钮的样式、状态与无障碍实现
RSUITE IconButton 组件完全指南:带图标按钮的样式、状态与无障碍实现 导读 IconButton 是 rsuite 中用于承载图标动作的按钮组件
前端UI组件Hugo Academic CV 模板安装与配置指南
Hugo Academic CV 模板安装与配置指南 1. 项目基础介绍 Hugo Academic CV 是一个基于 Hugo 的开源项目,它可以帮助用户轻松
前端
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考