Skip to content

Commit 68db7fc

Browse files
committed
GA add
1 parent 5fce096 commit 68db7fc

File tree

14 files changed

+345
-12
lines changed

14 files changed

+345
-12
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<!doctype html>
2+
<html
3+
lang="{{ site.LanguageCode }}"
4+
data-theme="{{ site.Params.colorScheme | default "default" }}">
5+
<head>
6+
<!-- Google tag (gtag.js) -->
7+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-7SM0DFG7FG"></script>
8+
<script>
9+
window.dataLayer = window.dataLayer || [];
10+
function gtag(){dataLayer.push(arguments);}
11+
gtag('js', new Date());
12+
gtag('config', 'G-7SM0DFG7FG');
13+
</script>
14+
15+
{{ partial "head.html" . }}
16+
{{ partial "layout/head.html" . }}
17+
<script>
18+
// 主题初始化脚本
19+
(function() {
20+
const theme = localStorage.getItem('theme') || 'system';
21+
const colorScheme = localStorage.getItem('colorScheme') || '{{ site.Params.colorScheme | default "shadcn" }}';
22+
23+
// 设置颜色主题
24+
document.documentElement.setAttribute('data-theme', colorScheme);
25+
26+
// 设置明暗模式
27+
function applyTheme() {
28+
if (theme === 'dark' || (theme === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
29+
document.documentElement.classList.add('dark');
30+
} else {
31+
document.documentElement.classList.remove('dark');
32+
}
33+
}
34+
35+
applyTheme();
36+
37+
// 监听系统主题变化
38+
if (theme === 'system') {
39+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', applyTheme);
40+
}
41+
})();
42+
</script>
43+
</head>
44+
45+
<body class="bg-background text-foreground min-h-screen antialiased">
46+
<!-- 阅读进度条 -->
47+
{{ partial "ui/reading-progress.html" . }}
48+
49+
{{ partial "navigation/header.html" . }}
50+
51+
<main class="mx-auto max-w-4xl px-4 py-6">
52+
{{ block "main" . }}{{ end }}
53+
</main>
54+
55+
{{ partial "layout/footer.html" . }}
56+
57+
<!-- 底部 Dock -->
58+
{{ partial "ui/dock.html" . }}
59+
60+
<!-- 目录卡片 - 只在有目录的页面显示 -->
61+
{{- if and .IsPage .TableOfContents }}
62+
{{ partial "ui/toc-card.html" . }}
63+
{{- end }}
64+
{{ partial "features/katex.html" . }}
65+
{{ partial "features/mermaid.html" . }}
66+
67+
<!-- 搜索组件 -->
68+
{{ partial "ui/search-modal.html" . }}
69+
</body>
70+
</html>
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
<!-- Google tag (gtag.js) -->
2+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-7SM0DFG7FG"></script>
3+
<script>
4+
window.dataLayer = window.dataLayer || [];
5+
function gtag(){dataLayer.push(arguments);}
6+
gtag('js', new Date());
7+
gtag('config', 'G-7SM0DFG7FG');
8+
</script>
9+
10+
{{- with resources.Get "js/main.js" }}
11+
{{- $opts := dict
12+
"minify" (not hugo.IsDevelopment)
13+
"sourceMap" (cond hugo.IsDevelopment "external" "")
14+
"targetPath" "js/main.js"
15+
}}
16+
{{- with . | js.Build $opts }}
17+
{{- if hugo.IsDevelopment }}
18+
<script src="{{ .RelPermalink }}"></script>
19+
{{- else }}
20+
{{- with . | fingerprint }}
21+
<script
22+
src="{{ .RelPermalink }}"
23+
integrity="{{ .Data.Integrity }}"
24+
crossorigin="anonymous"></script>
25+
{{- end }}
26+
{{- end }}
27+
{{- end }}
28+
{{- end }}
29+
30+
31+
<!-- Gumshoe 库 - 只在文章页面加载 -->
32+
{{- if .IsPage }}
33+
<script src="{{ "js/gumshoe.polyfills.min.js" | relURL }}"></script>
34+
{{- end }}
35+
36+
37+
<!-- 目录功能脚本 - 只在文章页面加载,需要在 dock.js 之前加载 -->
38+
{{- if .IsPage }}
39+
{{- with resources.Get "js/toc.js" }}
40+
{{- $opts := dict
41+
"minify" (not hugo.IsDevelopment)
42+
"sourceMap" (cond hugo.IsDevelopment "external" "")
43+
"targetPath" "js/toc.js"
44+
}}
45+
{{- with . | js.Build $opts }}
46+
{{- if hugo.IsDevelopment }}
47+
<script src="{{ .RelPermalink }}" defer></script>
48+
{{- else }}
49+
{{- with . | fingerprint }}
50+
<script
51+
src="{{ .RelPermalink }}"
52+
integrity="{{ .Data.Integrity }}"
53+
crossorigin="anonymous"
54+
defer></script>
55+
{{- end }}
56+
{{- end }}
57+
{{- end }}
58+
{{- end }}
59+
{{- end }}
60+
61+
62+
<!-- 搜索功能脚本 -->
63+
{{- with resources.Get "js/search.js" }}
64+
{{- $opts := dict
65+
"minify" (not hugo.IsDevelopment)
66+
"sourceMap" (cond hugo.IsDevelopment "external" "")
67+
"targetPath" "js/search.js"
68+
}}
69+
{{- with . | js.Build $opts }}
70+
{{- if hugo.IsDevelopment }}
71+
<script src="{{ .RelPermalink }}" defer></script>
72+
{{- else }}
73+
{{- with . | fingerprint }}
74+
<script
75+
src="{{ .RelPermalink }}"
76+
integrity="{{ .Data.Integrity }}"
77+
crossorigin="anonymous"
78+
defer></script>
79+
{{- end }}
80+
{{- end }}
81+
{{- end }}
82+
{{- end }}
83+
84+
85+
<!-- Dock 控制脚本 -->
86+
{{- with resources.Get "js/dock.js" }}
87+
{{- $opts := dict
88+
"minify" (not hugo.IsDevelopment)
89+
"sourceMap" (cond hugo.IsDevelopment "external" "")
90+
"targetPath" "js/dock.js"
91+
}}
92+
{{- with . | js.Build $opts }}
93+
{{- if hugo.IsDevelopment }}
94+
<script src="{{ .RelPermalink }}" defer></script>
95+
{{- else }}
96+
{{- with . | fingerprint }}
97+
<script
98+
src="{{ .RelPermalink }}"
99+
integrity="{{ .Data.Integrity }}"
100+
crossorigin="anonymous"
101+
defer></script>
102+
{{- end }}
103+
{{- end }}
104+
{{- end }}
105+
{{- end }}
106+
107+
108+
{{/* FJ Gallery */}}
109+
{{/* Gallery JavaScript */}}
110+
{{ if .Scratch.Get "justifiedEnabled" }}
111+
<script src="/js/fjGallery.min.js"></script>
112+
{{ end }}
113+
114+
{{ if .Scratch.Get "lightboxEnabled" }}
115+
<script src="/js/glightbox.min.js"></script>
116+
{{ end }}
117+
118+
{{/* 检测 masonry 短代码 */}}
119+
{{ $hasMasonryShortcode := false }}
120+
{{ if .RawContent }}
121+
{{ if findRE `{{<\s*masonry` .RawContent }}
122+
{{ $hasMasonryShortcode = true }}
123+
{{ end }}
124+
{{ end }}
125+
126+
{{ if $hasMasonryShortcode }}
127+
<script src="/js/macy.js"></script>
128+
{{ if not (.Scratch.Get "lightboxEnabled") }}
129+
{{ $globalLightbox := site.Params.lightbox | default dict }}
130+
{{ $lightboxEnabled := $globalLightbox.enabled | default false }}
131+
{{ if not $lightboxEnabled }}
132+
<script src="/js/glightbox.min.js"></script>
133+
{{ end }}
134+
{{ end }}
135+
{{ end }}
136+
137+
138+
{{ if or (.Scratch.Get "justifiedEnabled") (.Scratch.Get "lightboxEnabled") }}
139+
{{- with resources.Get "js/gallery.js" }}
140+
{{- $opts := dict
141+
"minify" (not hugo.IsDevelopment)
142+
"sourceMap" (cond hugo.IsDevelopment "external" "")
143+
"targetPath" "js/gallery.js"
144+
}}
145+
{{- with . | js.Build $opts }}
146+
{{- if hugo.IsDevelopment }}
147+
<script src="{{ .RelPermalink }}" defer></script>
148+
{{- else }}
149+
{{- with . | fingerprint }}
150+
<script
151+
src="{{ .RelPermalink }}"
152+
integrity="{{ .Data.Integrity }}"
153+
crossorigin="anonymous"
154+
defer></script>
155+
{{- end }}
156+
{{- end }}
157+
{{- end }}
158+
{{- end }}
159+
{{ end }}
160+
161+
162+
163+
<!-- 自定义 JS 文件 -->
164+
{{- $customJsFiles := resources.Match "js/custom/*.js" }}
165+
{{- range $customJsFiles }}
166+
{{- $fileName := .Name }}
167+
{{- $targetPath := printf "js/custom/%s" $fileName }}
168+
{{- $opts := dict
169+
"minify" (not hugo.IsDevelopment)
170+
"sourceMap" (cond hugo.IsDevelopment "external" "")
171+
"targetPath" $targetPath
172+
}}
173+
{{- with . | js.Build $opts }}
174+
{{- if hugo.IsDevelopment }}
175+
<script src="{{ .RelPermalink }}" defer></script>
176+
{{- else }}
177+
{{- with . | fingerprint }}
178+
<script
179+
src="{{ .RelPermalink }}"
180+
integrity="{{ .Data.Integrity }}"
181+
crossorigin="anonymous"
182+
defer></script>
183+
{{- end }}
184+
{{- end }}
185+
{{- end }}
186+
{{- end }}
187+
188+
189+
{{ if .Site.Params.analytics.enabled -}}
190+
{{ partial "features/analytics.html" . }}
191+
{{- end }}

public/404.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@
138138

139139

140140

141+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-7SM0DFG7FG"></script>
142+
<script>
143+
window.dataLayer = window.dataLayer || [];
144+
function gtag(){dataLayer.push(arguments);}
145+
gtag('js', new Date());
146+
gtag('config', 'G-7SM0DFG7FG');
147+
</script>
141148
<script
142149
src="/js/main.ba969e49a7a874e6938fe689a7dcaa00cb64cb4d429c2cf98d09bde512a16c6d.js"
143150
integrity="sha256-upaeSaeodOaTj&#43;aJp9yqAMtky01CnCz5jQm95RKhbG0="
@@ -186,7 +193,6 @@
186193

187194

188195

189-
190196

191197

192198
<script>

public/about/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@
150150

151151

152152

153+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-7SM0DFG7FG"></script>
154+
<script>
155+
window.dataLayer = window.dataLayer || [];
156+
function gtag(){dataLayer.push(arguments);}
157+
gtag('js', new Date());
158+
gtag('config', 'G-7SM0DFG7FG');
159+
</script>
153160
<script
154161
src="/js/main.ba969e49a7a874e6938fe689a7dcaa00cb64cb4d429c2cf98d09bde512a16c6d.js"
155162
integrity="sha256-upaeSaeodOaTj&#43;aJp9yqAMtky01CnCz5jQm95RKhbG0="
@@ -206,7 +213,6 @@
206213

207214

208215

209-
210216

211217

212218
<script>

public/archives/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@
144144

145145

146146

147+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-7SM0DFG7FG"></script>
148+
<script>
149+
window.dataLayer = window.dataLayer || [];
150+
function gtag(){dataLayer.push(arguments);}
151+
gtag('js', new Date());
152+
gtag('config', 'G-7SM0DFG7FG');
153+
</script>
147154
<script
148155
src="/js/main.ba969e49a7a874e6938fe689a7dcaa00cb64cb4d429c2cf98d09bde512a16c6d.js"
149156
integrity="sha256-upaeSaeodOaTj&#43;aJp9yqAMtky01CnCz5jQm95RKhbG0="
@@ -192,7 +199,6 @@
192199

193200

194201

195-
196202

197203

198204
<script>

public/categories/certification/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@
146146

147147

148148

149+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-7SM0DFG7FG"></script>
150+
<script>
151+
window.dataLayer = window.dataLayer || [];
152+
function gtag(){dataLayer.push(arguments);}
153+
gtag('js', new Date());
154+
gtag('config', 'G-7SM0DFG7FG');
155+
</script>
149156
<script
150157
src="/js/main.ba969e49a7a874e6938fe689a7dcaa00cb64cb4d429c2cf98d09bde512a16c6d.js"
151158
integrity="sha256-upaeSaeodOaTj&#43;aJp9yqAMtky01CnCz5jQm95RKhbG0="
@@ -194,7 +201,6 @@
194201

195202

196203

197-
198204

199205

200206
<script>

public/categories/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@
146146

147147

148148

149+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-7SM0DFG7FG"></script>
150+
<script>
151+
window.dataLayer = window.dataLayer || [];
152+
function gtag(){dataLayer.push(arguments);}
153+
gtag('js', new Date());
154+
gtag('config', 'G-7SM0DFG7FG');
155+
</script>
149156
<script
150157
src="/js/main.ba969e49a7a874e6938fe689a7dcaa00cb64cb4d429c2cf98d09bde512a16c6d.js"
151158
integrity="sha256-upaeSaeodOaTj&#43;aJp9yqAMtky01CnCz5jQm95RKhbG0="
@@ -194,7 +201,6 @@
194201

195202

196203

197-
198204

199205

200206
<script>

public/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@
147147

148148

149149

150+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-7SM0DFG7FG"></script>
151+
<script>
152+
window.dataLayer = window.dataLayer || [];
153+
function gtag(){dataLayer.push(arguments);}
154+
gtag('js', new Date());
155+
gtag('config', 'G-7SM0DFG7FG');
156+
</script>
150157
<script
151158
src="/js/main.ba969e49a7a874e6938fe689a7dcaa00cb64cb4d429c2cf98d09bde512a16c6d.js"
152159
integrity="sha256-upaeSaeodOaTj&#43;aJp9yqAMtky01CnCz5jQm95RKhbG0="
@@ -195,7 +202,6 @@
195202

196203

197204

198-
199205

200206

201207
<script>

0 commit comments

Comments
 (0)