Skip to content

Commit 9a174c3

Browse files
committed
Refactor heatmap from shortcode to partial, so it could be seamless integrated with archive.
1 parent 18e3a61 commit 9a174c3

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

content/en/about_me.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ lastmod = 2022-02-23T17:23:37+08:00
55
draft = false
66
+++
77

8-
{{< heatmap >}}
9-
108
## About me {#about-me}
119

1210
I'm Ramsay, a software engineer making a living by pressing keyboard, an amateur cook, an Emacs deadhead and Linux enthusiast.

content/zh/about_me_zh.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ draft = false
66
toc = true
77
+++
88

9-
{{< heatmap title_text="文章日历" language="ZH" >}}
10-
119
## <span class="section-num">0x0</span> 自我认知 {#自我认知}
1210
一个努力但平凡的人,希望做个有趣的人, work hard and be nice to people.
1311

i18n/en.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
- id: highlighted_posts
22
translation: "Highlighted Posts"
3+
- id: article_activity
4+
translation: "Article Activity"
5+
- id: thousand_words
6+
translation: "k words"
7+

i18n/zh.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
- id: highlighted_posts
22
translation: "精选阅读"
3+
- id: article_activity
4+
translation: "文章日历"
5+
- id: thousand_words
6+
translation: "千字"
7+

layouts/_default/archives.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ <h1>
2626
{{- end }}
2727
</header>
2828

29+
<div class="heatmap-section">
30+
{{ partial "heatmap.html" .}}
31+
</div>
32+
2933
{{/* Get all pages */}}
3034
{{- $pages := where site.RegularPages "Type" "in" site.Params.mainSections }}
3135
{{- if site.Params.ShowAllPagesInArchive }}

layouts/shortcodes/heatmap.html renamed to layouts/partials/heatmap.html

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
<!DOCTYPE html>
2-
<html lang="en">
1+
<!-- Add heatmap section at the top -->
32
<head>
43
<meta charset="UTF-8">
54
<meta name="viewport" content="width=device-width, initial-scale=1.0">
65
<title>Responsive Heatmap</title>
76
<style>
7+
.heatmap-section {
8+
margin-bottom: 30px;
9+
}
10+
811
/* Default styles */
912
.heatmap-container {
1013
display: block;
@@ -45,7 +48,7 @@
4548
<div>
4649
<div style="display: flex; justify-content: center; align-items: center">
4750
<p style="margin-right: 15px; margin-bottom: 0; padding: 8px">
48-
{{ default "Article Activity" (.Get "title_text") }}
51+
{{ i18n "article_activity" }}
4952
</p>
5053
<select id="yearSelector">
5154
<!-- Years will be dynamically added here -->
@@ -141,7 +144,6 @@
141144
function populatePostData() {
142145
var postsByDate = new Map();
143146
var years = new Set();
144-
145147
{{ range ((where .Site.RegularPages "Type" "post")) }}
146148
var date = {{ .Date.Format "2006-01-02" }};
147149
var year = {{ .Date.Format "2006" }};
@@ -163,7 +165,7 @@
163165
totalWordCount += wordCount;
164166
data.set("totalWordCount", totalWordCount);
165167
postsByDate.set(date, data);
166-
{{- end -}}
168+
{{- end -}}
167169

168170
years = Array.from(years).sort().reverse();
169171
return [postsByDate, years];
@@ -251,10 +253,10 @@
251253
yearLabel: { show: false },
252254
dayLabel: {
253255
firstDay: 1,
254-
nameMap: {{ default "EN" (.Get "language")}}
256+
nameMap: "{{.Lang}}"
255257
},
256258
monthLabel: {
257-
nameMap: {{ default "EN" (.Get "language")}}
259+
nameMap: "{{.Lang}}"
258260
},
259261
splitLine: {
260262
show: false,
@@ -268,7 +270,7 @@
268270
},
269271
backgroundColor: getTooltipBgColor(),
270272
formatter: function (params) {
271-
const thousandWordsText = {{ default "EN" (.Get "language")}} === "EN" ? 'k words': '千字';
273+
const thousandWordsText = {{ i18n "thousand_words" }};
272274
const date = params.data[0];
273275
const posts = postsByDate.get(date).get("posts");
274276
var content = `${date}`;

0 commit comments

Comments
 (0)