summaryrefslogtreecommitdiff
path: root/layouts/partials/head/headscript.html
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-02-03 14:32:46 +0800
committerEltrac <hi@guhub.cn>2025-02-03 14:32:46 +0800
commit95b7337f7db6b1a929dbb94a5acc59f8b41f3293 (patch)
treeed654931419d22a713208c491144e409bf6eae47 /layouts/partials/head/headscript.html
parent11fe28d6ce85850794ae42e6c2328d6d47b629ec (diff)
feat(theme): add word count heatmap to archive page
Diffstat (limited to 'layouts/partials/head/headscript.html')
-rw-r--r--layouts/partials/head/headscript.html39
1 files changed, 38 insertions, 1 deletions
diff --git a/layouts/partials/head/headscript.html b/layouts/partials/head/headscript.html
index 06835b1c..3fae65a6 100644
--- a/layouts/partials/head/headscript.html
+++ b/layouts/partials/head/headscript.html
@@ -1,4 +1,5 @@
-<!-- Global JavaScript Variables -->
+<script src="https://d3js.org/d3.v7.min.js"></script>
+<script src="https://unpkg.com/cal-heatmap/dist/cal-heatmap.min.js"></script>
<script>
/* === littlefoot options === */
var littlefootOptions = {
@@ -14,4 +15,40 @@ if (window.location.hostname !== 'localhost') {
script.dataset.websiteId = 'ae8c2619-56eb-4577-ac31-9dc6ea44bda7';
document.head.appendChild(script);
}
+
+/* === cal-heatmap Initializing Method */
+
+function initCalHeatmap() {
+ // Initialize CalHeatmap
+ const cal = new CalHeatmap();
+
+ // Calculate the date 6 months ago
+ const startDate = new Date();
+ startDate.setMonth(startDate.getMonth() - 12);
+
+ // Render the heatmap
+ cal.paint({
+ domain: {
+ type: 'month',
+ },
+ subDomain: { type: 'day' },
+ scale: {
+ color: {
+ range: ['#eee', 'black'],
+ type: 'linear',
+ domain: [0, 6000],
+ },
+ },
+ date: {
+ timezone: 'Asia/Shanghai',
+ start: startDate,
+ },
+ data: {
+ source: '/cal-heatmap.json', // 指定数据源
+ x: d => new Date(d.date), // 提取日期字段并转换为 Date 对象
+ y: d => d.value, // 提取数值字段
+ defaultValue: 0, // 缺失数据的默认值
+ },
+ });
+}
</script>