feat:增加博客统计数据
This commit is contained in:
@@ -1,26 +1,31 @@
|
|||||||
<template>
|
<template>
|
||||||
<calendar-heatmap
|
<div v-if="!isMobile()">
|
||||||
v-if="!isMobile()"
|
<calendar-heatmap
|
||||||
:values="heatmapData"
|
:values="heatmapData"
|
||||||
:end-date="new Date()"
|
:end-date="new Date()"
|
||||||
no-data-text="暂无记录"
|
no-data-text="暂无记录"
|
||||||
tooltip-unit="篇"
|
tooltip-unit="篇"
|
||||||
:round="2"
|
:round="2"
|
||||||
:locale="{
|
:locale="{
|
||||||
less: '少于',
|
less: '少于',
|
||||||
more: '多于',
|
more: '多于',
|
||||||
months: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
|
months: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
|
||||||
days: ['日', '一', '二', '三', '四', '五', '六'],
|
days: ['日', '一', '二', '三', '四', '五', '六'],
|
||||||
}"
|
}"
|
||||||
class="blog-heatmap"
|
class="blog-heatmap"
|
||||||
/>
|
/>
|
||||||
|
<div class="heatmap-footer">
|
||||||
|
⏱️ 已坚持<span class="highlight">{{ getDaysDifference(new Date(), startBlogDate) }}</span> 天
|
||||||
|
| 📝 已创作<span class="highlight">{{ data.length }}</span> 篇
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { CalendarHeatmap } from 'vue3-calendar-heatmap';
|
import { CalendarHeatmap } from 'vue3-calendar-heatmap';
|
||||||
import 'vue3-calendar-heatmap/dist/style.css';
|
import 'vue3-calendar-heatmap/dist/style.css';
|
||||||
import { data } from '../../data/posts.data.js'
|
import { data } from '../../data/posts.data.js'
|
||||||
import {isMobile} from "../utils";
|
import { isMobile, getDaysDifference, startBlogDate } from "../utils";
|
||||||
|
|
||||||
const dateCountMap = new Map<string, number>();
|
const dateCountMap = new Map<string, number>();
|
||||||
|
|
||||||
@@ -58,4 +63,20 @@ const heatmapData = Array.from(dateCountMap.entries()).map(([date, count]) => ({
|
|||||||
.blog-heatmap :deep(.vch__day__label) {
|
.blog-heatmap :deep(.vch__day__label) {
|
||||||
font-size: 8px !important;
|
font-size: 8px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.heatmap-footer {
|
||||||
|
font-size: 15px;
|
||||||
|
color: #666;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
padding: 6px 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight {
|
||||||
|
font-weight: 700;
|
||||||
|
color: #6366f1;
|
||||||
|
margin: 0 2px;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -31,6 +31,11 @@
|
|||||||
padding: 18px;
|
padding: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.vp-doc h2 {
|
||||||
|
margin: 0;
|
||||||
|
border-top: none;
|
||||||
|
}
|
||||||
|
|
||||||
.medium-zoom-overlay {
|
.medium-zoom-overlay {
|
||||||
background-color: var(--vp-c-bg) !important;
|
background-color: var(--vp-c-bg) !important;
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
|
|||||||
@@ -54,4 +54,14 @@ export const isMobile = (): boolean => {
|
|||||||
const mobileRegex = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
|
const mobileRegex = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
|
||||||
|
|
||||||
return mobileRegex.test(userAgent);
|
return mobileRegex.test(userAgent);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const startBlogDate = new Date('2025-11-26');
|
||||||
|
|
||||||
|
export const getDaysDifference = (date1: Date, date2: Date): number => {
|
||||||
|
let d1 = new Date(date1);
|
||||||
|
let d2 = new Date(date2);
|
||||||
|
|
||||||
|
const diffMs = Math.abs(d2.getTime() - d1.getTime());
|
||||||
|
return Math.floor(diffMs / (1000 * 60 * 60 * 24));
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user