* feat: add GDPR cookie consent banner
Add a GDPR-compliant cookie consent banner that gates analytics (Google
Analytics) and functional cookies (comments) until user consent is given.
Features:
- Theme-consistent styling using CSS variables (light/dark mode)
- Settings panel with category toggles (necessary, analytics, functional)
- Consent stored in cookie for 365 days
- Google Analytics only loads after analytics consent
- Comments only load after functional consent
- Translations for all 32 supported languages
- Accessible with proper ARIA attributes and focus management
Configuration in hugo.yaml:
params:
cookies:
enabled: true
categories:
analytics: true
functional: true
When cookies.enabled is false, scripts load normally without consent gating.
Closes #412
* refactor: move consent-gated GA to cookies/analytics.html
Move Google Analytics consent logic to avoid shadowing Hugo's internal
`_internal/google_analytics.html` template.
Changes:
- Rename google_analytics.html → cookies/analytics.html
- Update head.html to conditionally load:
- cookies.enabled=true: cookies/analytics.html (consent-gated)
- cookies.enabled=false: Hugo's _internal/google_analytics.html
- Align cookies/analytics.html with Hugo's internal template:
- Support Privacy.GoogleAnalytics.Disable setting
- Support Privacy.GoogleAnalytics.RespectDoNotTrack setting
- Add UA- prefix deprecation warning
Note: Custom JS is required for consent-gated GA because Hugo templates
render at build time, but consent happens at runtime. We cannot call
Hugo's internal template after the user grants consent - we must
dynamically inject the GA script via JavaScript.
* style: indent cookies/analytics.html
* refactor: don't use default, put default configurations in params.toml
* fix: don't use `description` as translation key because it's reserved and will throw error
* fix: remove footer/components/custom-font.html call
* fix: banner showSettings key
* style: indent comments/include
* Add missing article.alert translation back
* style: format i18n toml files
* style: indent head/head.html
* style adjustment
* style: add missing -
* style: format demo/config/params.toml
* style: remove redundant comments from cookies.scss
* style: update box-shadow for cookie banner content
---------
Co-authored-by: delize <4028612+delize@users.noreply.github.com>
Co-authored-by: Jimmy Cai <jimmy@cai.im>
70 lines
1.9 KiB
TOML
70 lines
1.9 KiB
TOML
toggleMenu = "切换菜单"
|
|
darkMode = "暗色模式"
|
|
|
|
[list]
|
|
page = "{{ .Count }} 个页面"
|
|
section = "章节"
|
|
subsection = "子章节"
|
|
|
|
[article]
|
|
back = "返回"
|
|
tableOfContents = "目录"
|
|
relatedContent = "相关文章"
|
|
lastUpdatedOn = "最后更新于"
|
|
readingTime = "阅读时长: {{ .Count }} 分钟"
|
|
|
|
[article.alert]
|
|
note = "备注"
|
|
tip = "提示"
|
|
important = "重要"
|
|
warning = "警告"
|
|
caution = "注意"
|
|
|
|
[notFound]
|
|
title = "404 错误"
|
|
subtitle = "页面不存在"
|
|
|
|
[widget]
|
|
[widget.archives]
|
|
title = "归档"
|
|
more = "更多"
|
|
|
|
[widget.tagCloud]
|
|
title = "标签云"
|
|
|
|
[widget.categoriesCloud]
|
|
title = "分类"
|
|
|
|
[search]
|
|
title = "搜索"
|
|
placeholder = "输入关键词..."
|
|
resultTitle = "#PAGES_COUNT 个结果 (用时 #TIME_SECONDS 秒)"
|
|
|
|
[footer]
|
|
builtWith = "使用 {{ .Generator }} 构建"
|
|
designedBy = "主题 {{ .Theme }} 由 {{ .DesignedBy }} 设计"
|
|
|
|
[cookies]
|
|
title = "Cookie 同意"
|
|
text = "我们使用 Cookie 来增强您的浏览体验并分析网站流量。"
|
|
acceptAll = "接受所有"
|
|
deny = "拒绝"
|
|
managePreferences = "管理偏好设置"
|
|
settingsTitle = "Cookie 偏好设置"
|
|
savePreferences = "保存偏好设置"
|
|
cancel = "取消"
|
|
footerLink = "Cookie 设置"
|
|
commentsDisabled = "评论已禁用,直到您接受功能性 Cookie。"
|
|
|
|
[cookies.necessary]
|
|
title = "必要"
|
|
text = "这些 Cookie 是网站运行所必需的,无法禁用。"
|
|
|
|
[cookies.analytics]
|
|
title = "分析"
|
|
text = "这些 Cookie 帮助我们了解访问者如何与我们的网站互动。"
|
|
|
|
[cookies.functional]
|
|
title = "功能性"
|
|
text = "这些 Cookie 启用评论和嵌入内容等功能."
|