版权声明模块(CopyrightCard)
建站
0 字 / 约 0 分钟
版权声明模块(CopyrightCard)
目标
- 在文档页正文底部(页脚前)插入统一的版权声明卡片,自动展示作者、文章标题、链接与协议信息。
- 支持明暗主题、响应式与页面级开关;索引页默认不显示。
接入位置
- 插槽:
doc-footer-before - 接入文件:
docs/.vitepress/theme/index.ts
ts
// docs/.vitepress/theme/index.ts
return h(DefaultTheme.Layout, null, {
'sidebar-nav-before': () => h(SiteNotification),
'doc-footer-before': () => h(CopyrightCard)
})组件位置与职责
- 组件:
docs/.vitepress/theme/components/CopyrightCard.vue- 读取站点与 frontmatter,计算作者、站点与当前页 URL
- 控制显隐(索引页与开关项)
- 结构化输出卡片内容
数据来源优先级
- 作者名:
frontmatter.author→themeConfig.defaultAuthor→ 站点title - 作者链接:
frontmatter.authorUrl→themeConfig.defaultAuthorUrl→'/' - 站点名:
docs/.vitepress/config.ts的title - 站点链接:
themeConfig.siteUrl
站点默认项示例:
ts
// docs/.vitepress/config.ts
export default defineConfig({
title: '芯片版图',
themeConfig: {
siteUrl: 'https://chiplayout.top',
defaultAuthor: 'ChipLayout',
defaultAuthorUrl: 'https://github.com/ICtechO'
}
})显隐规则(页面开关)
- 自动隐藏索引页:
route.path非根且以/结尾 - 可选开关(任一满足即隐藏):
copyright: falseoutside: falseaside: true
页面示例:
yaml
---
title: 某文章
author: 张三 # 可选
authorUrl: https://xx # 可选
copyright: true # 默认显示;设为 false 则隐藏
---样式与图标
- 样式统一放在:
docs/.vitepress/theme/style.css - 使用 Tailwind 的
@apply组合工具类,配合主题变量--vp-c-* - 图标组件:
<Icon />(已在主题全局注册)
相关选择器(节选):
css
.shiguang-public { /* 外层容器 */ }
.copyright-card { /* 卡片容器 */ }
.copyright-symbol { /* 卡片角标装饰 */ }
.copyright-content { /* 内容区布局 */ }
.copyright-item { /* 行布局 */ }
.copyright-meta { /* 元信息标签(作者/标题/链接/协议)*/ }
.copyright-info { /* 对应值与链接 */ }效果说明
- 位置:文档正文底部到页脚之间
- 内容:作者、标题、文章链接、协议(CC BY-NC-SA 4.0)与站点名/链接
- 交互:悬停时边框/阴影响应;移动端自适应排版;明暗配色适配
常见问题
- 索引页为何不显示?
- 索引页常作为目录容器,卡片会增加视觉噪音,因此默认隐藏;可通过页面开关覆盖。
- 如何替换协议?
- 在组件中可扩展优先级:
frontmatter.licenseName、frontmatter.licenseUrl优先于默认协议。
- 在组件中可扩展优先级:
参考
- 本实现思路与样式细节部分参考了:
声明新风格-v2
相关文件
docs/.vitepress/theme/index.tsdocs/.vitepress/theme/components/CopyrightCard.vuedocs/.vitepress/theme/style.cssdocs/.vitepress/config.ts