至少一年前我就想在博客放个日历用于看游戏发售和活动时间表,
但是网上没有类似的教程可以抄,所以找deepseek写了一个,改了半天感觉能用。
游戏日历https://www.flamecho.top/calendar/

❖ js文件

新建source\js\calendar.js,复制以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
(function() {
'use strict';

// ========== 在这里维护你的事件数据 ==========
// 格式:{ date: "YYYY-MM-DD", title: "事件标题", type: "game/update/activity/deadline/sale", desc: "描述", time: "时间" }
const EVENTS_DATA = [
// 游戏发售
{ date: "YYYY-MM-DD", title: "事件标题", type: "game", desc: "描述", time: "时间" },

// 游戏更新
{ date: "YYYY-MM-DD", title: "事件标题", type: "update", desc: "描述", time: "时间" },

// 游戏活动
{ date: "YYYY-MM-DD", title: "事件标题", type: "activity", desc: "描述", time: "时间" },

// 活动截止
{ date: "YYYY-MM-DD", title: "事件标题", type: "deadline", desc: "描述", time: "时间" },

// 促销活动
{ date: "YYYY-MM-DD", title: "事件标题", type: "sale", desc: "描述", time: "时间" },
];
// ==========================================

// 日历主类
class CalendarManager {
constructor() {
this.currentYear = new Date().getFullYear();
this.currentMonth = new Date().getMonth();
this.selectedDate = null;
this.events = EVENTS_DATA;
this.init();
}

init() {
this.renderCalendar();
this.bindEvents();
this.updateSelectedDateDisplay();
}

// 获取本地日期字符串 YYYY-MM-DD
getLocalDateString(date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
}

// 获取某天的事件类型列表
getEventTypesByDate(date) {
const dateStr = this.getLocalDateString(date);
const events = this.events.filter(e => e.date === dateStr);
return [...new Set(events.map(e => e.type))];
}

// 根据事件类型获取圆点颜色
getDotColor(type) {
const colors = {
game: '#2e7d32', // 绿色
update: '#ed6c02', // 橙色
activity: '#0288d1', // 蓝色
deadline: '#c62828', // 红色
sale: '#7b1fa2' // 紫色
};
return colors[type] || '#ff6b6b';
}

renderCalendar() {
const container = document.getElementById('calendar-days');
if (!container) return;

const firstDay = new Date(this.currentYear, this.currentMonth, 1);
const lastDay = new Date(this.currentYear, this.currentMonth + 1, 0);
const startDayOfWeek = firstDay.getDay();
const daysInMonth = lastDay.getDate();
const prevMonthLastDay = new Date(this.currentYear, this.currentMonth, 0).getDate();

let html = '';

// 上个月的日期
for (let i = startDayOfWeek - 1; i >= 0; i--) {
const day = prevMonthLastDay - i;
const date = new Date(this.currentYear, this.currentMonth - 1, day);
html += this.renderDayCell(day, date, 'other-month');
}

// 当月日期
for (let day = 1; day <= daysInMonth; day++) {
const date = new Date(this.currentYear, this.currentMonth, day);
let classes = [];
if (this.isToday(date)) classes.push('today');
if (this.selectedDate && this.isSameDate(date, this.selectedDate)) classes.push('selected');
if (this.hasEvent(date)) classes.push('has-event');
html += this.renderDayCell(day, date, classes.join(' '));
}

// 下个月的日期
const totalCells = Math.ceil((startDayOfWeek + daysInMonth) / 7) * 7;
const nextMonthDays = totalCells - (startDayOfWeek + daysInMonth);
for (let day = 1; day <= nextMonthDays; day++) {
const date = new Date(this.currentYear, this.currentMonth + 1, day);
html += this.renderDayCell(day, date, 'other-month');
}

container.innerHTML = html;
document.getElementById('calendar-month-year').innerHTML = `${this.currentYear}${this.currentMonth + 1} 月`;
}

renderDayCell(day, date, className) {
const localDateStr = this.getLocalDateString(date);
const eventTypes = this.getEventTypesByDate(date);

// 生成多色圆点
let dotHtml = '';
if (eventTypes.length > 0) {
const dotColors = eventTypes.map(type => this.getDotColor(type));
const uniqueColors = [...new Set(dotColors)];
dotHtml = `<div class="event-dots">${uniqueColors.map(color => `<span class="event-dot" style="background: ${color};"></span>`).join('')}</div>`;
}

return `<div class="calendar-day ${className}" data-date="${localDateStr}">
<span class="day-number">${day}</span>
${dotHtml}
</div>`;
}

isToday(date) {
const today = new Date();
return date.getDate() === today.getDate() &&
date.getMonth() === today.getMonth() &&
date.getFullYear() === today.getFullYear();
}

isSameDate(date1, date2) {
return date1.getFullYear() === date2.getFullYear() &&
date1.getMonth() === date2.getMonth() &&
date1.getDate() === date2.getDate();
}

hasEvent(date) {
return this.getEventTypesByDate(date).length > 0;
}

getEventsByDate(dateStr) {
const uniqueEvents = [];
const seen = new Set();

this.events.filter(e => e.date === dateStr).forEach(event => {
const key = `${event.title}|${event.time}`;
if (!seen.has(key)) {
seen.add(key);
uniqueEvents.push(event);
}
});

return uniqueEvents;
}

updateSelectedDateDisplay() {
let dateStr = null;
if (this.selectedDate) {
dateStr = this.getLocalDateString(this.selectedDate);
}
const events = dateStr ? this.getEventsByDate(dateStr) : [];

const selectedDateElem = document.getElementById('selected-date');
if (selectedDateElem) {
selectedDateElem.textContent = dateStr ? `${dateStr} 的事件` : '请选择一个日期';
}

this.renderEventsList(events);
}

renderEventsList(events) {
const container = document.getElementById('events-list');
if (!container) return;

if (events.length === 0) {
container.innerHTML = `
<div class="empty-events">
<i class="fas fa-calendar-day"></i>
<p>这一天没有安排任何事件</p>
</div>
`;
return;
}

const typeMap = {
game: '🎄 游戏发售',
update: '🍹 游戏更新',
activity: '🌊 游戏活动',
deadline: '⏰ 活动截止',
sale: '🍨 促销活动'
};

let html = '';
events.forEach(event => {
const cardClass = `${event.type}-card`;

html += `
<div class="event-item ${cardClass}">
<span class="event-type ${event.type}">${typeMap[event.type]}</span>
<div class="event-title">${this.escapeHtml(event.title)}</div>
${event.desc ? `<div class="event-desc">${this.escapeHtml(event.desc)}</div>` : ''}
${event.time ? `<div class="event-time"><i class="fas fa-clock"></i> ${this.escapeHtml(event.time)}</div>` : ''}
</div>
`;
});

container.innerHTML = html;
}

bindEvents() {
const prevBtn = document.getElementById('prev-month');
const nextBtn = document.getElementById('next-month');
const todayBtn = document.getElementById('today-btn');

if (prevBtn) {
prevBtn.addEventListener('click', () => {
this.currentMonth--;
if (this.currentMonth < 0) {
this.currentMonth = 11;
this.currentYear--;
}
this.renderCalendar();
});
}

if (nextBtn) {
nextBtn.addEventListener('click', () => {
this.currentMonth++;
if (this.currentMonth > 11) {
this.currentMonth = 0;
this.currentYear++;
}
this.renderCalendar();
});
}

if (todayBtn) {
todayBtn.addEventListener('click', () => {
const today = new Date();
this.currentYear = today.getFullYear();
this.currentMonth = today.getMonth();
this.renderCalendar();
this.selectDate(today);
});
}

const container = document.getElementById('calendar-days');
if (container) {
container.addEventListener('click', (e) => {
const dayCell = e.target.closest('.calendar-day');
if (dayCell && dayCell.dataset.date) {
const dateParts = dayCell.dataset.date.split('-');
const year = parseInt(dateParts[0]);
const month = parseInt(dateParts[1]) - 1;
const day = parseInt(dateParts[2]);
const date = new Date(year, month, day);
this.selectDate(date);
}
});
}

const exportBtn = document.getElementById('export-events');
const importBtn = document.getElementById('import-events');
if (exportBtn) exportBtn.style.display = 'none';
if (importBtn) importBtn.style.display = 'none';

const addSection = document.querySelector('.add-event-section');
if (addSection) addSection.style.display = 'none';
}

selectDate(date) {
this.selectedDate = date;
this.renderCalendar();
this.updateSelectedDateDisplay();
}

escapeHtml(str) {
if (!str) return '';
return str.replace(/[&<>]/g, function(m) {
if (m === '&') return '&amp;';
if (m === '<') return '&lt;';
if (m === '>') return '&gt;';
return m;
});
}
}

if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
new CalendarManager();
});
} else {
new CalendarManager();
}
})();

❖ css文件

新建source\css\calendar.css,复制以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
.calendar-page {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}

.calendar-layout {
display: grid;
grid-template-columns: 1fr 1.2fr;
gap: 30px;
}

@media (max-width: 768px) {
.calendar-layout {
grid-template-columns: 1fr;
gap: 20px;
}
}

/* ========== 日历部分 ========== */
.calendar-container {
background: var(--card-bg, #fff);
border-radius: 16px;
padding: 20px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.calendar-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
padding: 0 10px;
}

.calendar-header h2 {
margin: 0;
font-size: 1.5rem;
color: var(--font-color, #333);
}

.calendar-nav {
display: flex;
gap: 12px;
}

.calendar-nav button {
background: var(--btn-bg, #f0f0f0);
border: none;
padding: 8px 16px;
border-radius: 8px;
cursor: pointer;
font-size: 1rem;
color: #fff;
}

.calendar-nav button:hover {
background: var(--btn-hover-bg, #809ac1);
}

.calendar-weekdays {
display: grid;
grid-template-columns: repeat(7, 1fr);
text-align: center;
font-weight: bold;
padding: 10px 0;
border-bottom: 1px solid var(--border-color, #eee);
margin-bottom: 10px;
}

.calendar-weekdays div {
padding: 8px;
color: var(--font-color, #666);
}

.calendar-days {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 4px;
}

.calendar-day {
aspect-ratio: 1;
padding: 8px;
text-align: center;
cursor: pointer;
border-radius: 12px;
position: relative;
background: var(--day-bg, transparent);
display: flex;
align-items: center;
justify-content: center;
}

.calendar-day:hover {
background: var(--day-hover-bg, #f5f5f5);
}

.calendar-day.other-month {
color: var(--other-month-color, #ccc);
}

.calendar-day.today {
background: var(--today-bg, #3a62a0);
color: white;
}

.calendar-day.has-event {
font-weight: bold;
position: relative;
}

.calendar-day.has-event::after {
content: '';
position: absolute;
bottom: 6px;
left: 50%;
transform: translateX(-50%);
width: 6px;
height: 6px;
background: var(--event-dot, #ff6b6b);
border-radius: 50%;
}

.calendar-day.today.has-event::after {
background: white;
}

.calendar-day.selected {
outline: 2px solid var(--selected-border, #3a62a0);
outline-offset: -1px;
background: var(--selected-bg, #e3f2fd);
}

/* ========== 事件列表部分 ========== */
.events-container {
background: var(--card-bg, #fff);
border-radius: 16px;
padding: 20px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.events-header {
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 2px solid var(--border-color, #eee);
}

.events-header h3 {
margin: 0 0 8px 0;
font-size: 1.3rem;
color: var(--font-color, #333);
}

.events-header .selected-date {
color: var(--accent-color, #3a62a0);
font-size: 0.9rem;
}

.events-list {
min-height: auto;
max-height: none;
overflow-y: visible;
}

/* 事件卡片 - 每种类型不同背景色 */
.event-item {
border-radius: 12px;
padding: 15px;
margin-bottom: 12px;
border-left: 4px solid;
transition: none;
}

/* 游戏发售卡片 - 极浅绿色背景 */
.event-item.game-card {
background: #f8fcf8;
border-left-color: #2e7d32;
}

/* 游戏更新卡片 - 极浅橙色背景 */
.event-item.update-card {
background: #fff6ee;
border-left-color: #ed6c02;
}

/* 游戏活动卡片 - 极浅蓝色背景 */
.event-item.activity-card {
background: #f6fbff;
border-left-color: #0288d1;
}

/* 活动截止卡片 - 极浅粉色背景 */
.event-item.deadline-card {
background: #fff5f5;
border-left-color: #d3625d;
}

/* 促销卡片 - 极浅紫色背景 */
.event-item.sale-card {
background: #faf5ff;
border-left-color: #7b1fa2;
}

/* 事件类型标签 - 每种类型不同背景色 */
.event-type {
display: inline-block;
padding: 2px 10px;
border-radius: 20px;
font-size: 0.75rem;
margin-bottom: 8px;
font-weight: 500;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* 游戏发售标签 - 浅绿色 */
.event-type.game {
background: #e0f0e0;
color: #2e7d32;
}

/* 游戏更新标签 - 浅橙色 */
.event-type.update {
background: #ffe8d6;
color: #ed6c02;
}

/* 游戏活动标签 - 浅蓝色 */
.event-type.activity {
background: #e3f2fd;
color: #0288d1;
}

/* 活动截止标签 - 浅粉色 */
.event-type.deadline {
background: #ffe5e5;
color: #c62828;
}

/* 促销标签 - 浅紫色 */
.event-type.sale {
background: #f0e5ff;
color: #7b1fa2;
}

.event-title {
font-size: 1rem;
font-weight: 600;
margin-bottom: 8px;
color: var(--font-color, #333);
}

.event-desc {
font-size: 0.85rem;
color: var(--font-light, #666);
margin-bottom: 8px;
line-height: 1.4;
}

.event-time {
font-size: 0.75rem;
color: var(--font-light, #999);
display: flex;
align-items: center;
gap: 5px;
}

.empty-events {
text-align: center;
padding: 60px 20px;
color: var(--font-light, #999);
}

/* 隐藏不需要的元素 */
.add-event-section,
.events-actions {
display: none;
}

/* ========== 暗色模式 ========== */
[data-theme="dark"] .calendar-container,
[data-theme="dark"] .events-container {
background: var(--card-bg, #1e1e1e);
}

[data-theme="dark"] .calendar-day:hover {
background: var(--day-hover-bg, #2a2a2a);
}

/* 暗色模式 - 事件卡片 */
[data-theme="dark"] .event-item.game-card {
background: rgba(46, 125, 50, 0.15);
border-left-color: #81c784;
}
[data-theme="dark"] .event-item.update-card {
background: rgba(237, 108, 2, 0.15);
border-left-color: #ffb74d;
}
[data-theme="dark"] .event-item.activity-card {
background: rgba(2, 136, 209, 0.15);
border-left-color: #64b5f6;
}
[data-theme="dark"] .event-item.deadline-card {
background: rgba(198, 40, 40, 0.15);
border-left-color: #ef9a9a;
}
[data-theme="dark"] .event-item.sale-card {
background: rgba(123, 31, 162, 0.15);
border-left-color: #ce93d8;
}

/* 暗色模式 - 事件类型标签 */
[data-theme="dark"] .event-type.game {
background: rgba(46, 125, 50, 0.3);
color: #81c784;
}
[data-theme="dark"] .event-type.update {
background: rgba(237, 108, 2, 0.3);
color: #ffb74d;
}
[data-theme="dark"] .event-type.activity {
background: rgba(2, 136, 209, 0.3);
color: #64b5f6;
}
[data-theme="dark"] .event-type.deadline {
background: rgba(198, 40, 40, 0.3);
color: #ef9a9a;
}
[data-theme="dark"] .event-type.sale {
background: rgba(123, 31, 162, 0.3);
color: #ce93d8;
}

/* 暗色模式 - 选中日期 */
[data-theme="dark"] .calendar-day.selected {
color: #000000 !important;
background: #e3f2fd !important;
outline: 2px solid #3a62a0;
outline-offset: -1px;
}

[data-theme="dark"] .calendar-day.today.selected {
color: #000000 !important;
background: #e3f2fd !important;
}

[data-theme="dark"] .calendar-day.today.selected:hover {
color: #ffffff !important;
background: #3a62a0 !important;
}

/* 事件圆点容器 */
.event-dots {
position: absolute;
bottom: 4px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 3px;
justify-content: center;
}

/* 单个圆点 */
.event-dot {
width: 6px;
height: 6px;
border-radius: 50%;
display: inline-block;
}

/* 移除原来的单圆点样式 */
.calendar-day.has-event::after {
display: none;
}

/* ========== 手机端适配 ========== */
@media (max-width: 768px) {
.calendar-page {
padding: 10px;
}

/* 日历头部缩放 */
.calendar-header {
margin-bottom: 12px;
padding: 0 5px;
}

.calendar-header h2 {
font-size: 1.2rem;
}

.calendar-nav button {
padding: 5px 10px;
font-size: 0.85rem;
}

/* 日历容器 */
.calendar-container {
padding: 12px;
overflow-x: auto;
}

.calendar-weekdays div,
.calendar-day {
font-size: 0.8rem;
padding: 6px 4px;
}

.calendar-days {
gap: 2px;
min-width: 300px;
}

/* 圆点 */
.event-dots {
bottom: 2px;
gap: 2px;
}

.event-dot {
width: 4px;
height: 4px;
}

/* 事件列表 */
.events-container {
padding: 12px;
}

.events-header h3 {
font-size: 1.1rem;
}

.event-item {
padding: 10px;
}

.event-title {
font-size: 0.9rem;
}

.event-desc,
.event-time {
font-size: 0.75rem;
}
}

/* 极小屏幕(小于480px) */
@media (max-width: 480px) {
.calendar-header h2 {
font-size: 1rem;
}

.calendar-nav button {
padding: 4px 8px;
font-size: 0.75rem;
}

.calendar-weekdays div,
.calendar-day {
font-size: 0.7rem;
padding: 4px 2px;
}

.calendar-day .day-number {
font-size: 0.7rem;
}

.events-header h3 {
font-size: 1rem;
}
}

❖ 页面文件

新建source\calendar\index.md,复制以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
---
title: 🍁 游戏日历
type: calendar
---

<link rel="stylesheet" href="/css/calendar.css">
<script src="/js/calendar.js" defer></script>

<div class="calendar-page">
<div class="calendar-layout">
<!-- 日历区域 -->
<div class="calendar-container">
<div class="calendar-header">
<h2 id="calendar-month-year"></h2>
<div class="calendar-nav">
<button id="prev-month"><i class="fas fa-chevron-left"></i></button>
<button id="today-btn">今天</button>
<button id="next-month"><i class="fas fa-chevron-right"></i></button>
</div>
</div>
<div class="calendar-weekdays">
<div></div><div></div><div></div><div></div><div></div><div></div><div></div>
</div>
<div id="calendar-days" class="calendar-days"></div>
</div>

<div class="events-container">
<div class="events-header">
<h3><i class="fas fa-list"></i> 事件列表</h3>
<div class="selected-date" id="selected-date">请选择一个日期</div>
</div>
<div id="events-list" class="events-list"></div>
</div>
</div>
</div>

<style>
.page-content {
padding-bottom: 30px;
}
</style>

❖ 完成

hexo三连查看效果。
在js里添加事件、增改标签;在css里调整颜色。