22import { Image } from ' astro:assets'
33import { Icon } from ' @/custom/components/user'
44
5- import PageLayout from ' @/layouts/BaseLayout.astro'
65import { getBlogCollection } from ' astro-pure/server'
7- import { getCurrentReading , getLatestPosts , getTotalWords } from ' @/components/shelf/utils '
6+ import PageLayout from ' @/layouts/BaseLayout.astro '
87import { calculateSiteAge , getHighlightColor } from ' @/components/home/utils'
8+ import { getCurrentReading , getLatestPosts , getTotalWords } from ' @/components/shelf/utils'
99import avatarImage from ' @/assets/home.png'
1010import config from ' @/site-config'
1111
@@ -32,10 +32,8 @@ const highlightColor = getHighlightColor()
3232 <div class =' grid grid-cols-1 md:grid-cols-[auto_1fr] gap-6 md:gap-8 items-center' >
3333 { /* 左侧:头像 - 大尺寸 */ }
3434 <div class =' flex justify-center md:justify-start' >
35- <div
36- class =' w-32 h-32 md:w-48 md:h-48 lg:w-56 lg:h-56 overflow-hidden rounded-lg'
37- >
38- <Image src ={ avatarImage } alt =' Avatar' class =' object-contain block' />
35+ <div class =' w-32 h-32 md:w-48 md:h-48 lg:w-56 lg:h-56 overflow-hidden rounded-lg' >
36+ <Image src ={ avatarImage } alt =' Avatar' class =' w-full h-full object-contain block' />
3937 </div >
4038 </div >
4139
@@ -308,80 +306,30 @@ const highlightColor = getHighlightColor()
308306
309307 <span id =' vercount_value_site_pv' class =' hidden' ></span >
310308
309+ { /* 数字动画效果已移除,直接显示数字以优化性能 */ }
311310 <script is:inline >
312- function animateCounter(element, targetValue, duration = 2000) {
313- const startValue = 0
314- const startTime = performance.now()
315- const targetNumber = parseInt(targetValue.replace(/,/g, ''))
316-
317- function updateCounter(currentTime) {
318- const elapsed = currentTime - startTime
319- const progress = Math.min(elapsed / duration, 1)
320- const easeOutCubic = 1 - Math.pow(1 - progress, 3)
321- const currentValue = Math.floor(startValue + (targetNumber - startValue) * easeOutCubic)
322- element.textContent = currentValue.toLocaleString()
323-
324- if (progress < 1) {
325- requestAnimationFrame(updateCounter)
326- } else {
327- element.textContent = targetValue
328- }
329- }
330-
331- requestAnimationFrame(updateCounter)
332- }
333-
334- function updateViewsDisplay(viewsElement, newValue, hasAnimated = false) {
335- if (viewsElement && newValue && newValue !== '-') {
336- const views = parseInt(newValue.replace(/,/g, ''))
337-
338- if (!hasAnimated) {
339- viewsElement.textContent = '0'
340- setTimeout(() => {
341- animateCounter(viewsElement, views.toLocaleString(), 2000)
342- }, 500)
343- } else {
344- viewsElement.textContent = views.toLocaleString()
311+ // 简化的 PV 统计更新 - 不使用动画,直接显示数字
312+ document.addEventListener('DOMContentLoaded', function () {
313+ const viewsEl = document.getElementById('total-views-display')
314+ const vercountEl = document.getElementById('vercount_value_site_pv')
315+
316+ if (viewsEl && vercountEl) {
317+ function updateViews() {
318+ const val = vercountEl.textContent
319+ if (val && val !== '-') {
320+ viewsEl.textContent = parseInt(val.replace(/,/g, '')).toLocaleString()
321+ }
345322 }
346- }
347- }
348323
349- document.addEventListener('DOMContentLoaded', () => {
350- const wordsDisplayElement = document.getElementById('total-words-display')
351- if (wordsDisplayElement) {
352- const targetValue = wordsDisplayElement.textContent
353- wordsDisplayElement.textContent = '0'
354- setTimeout(() => {
355- animateCounter(wordsDisplayElement, targetValue, 2000)
356- }, 500)
357- }
324+ // 检查初始值
325+ updateViews()
358326
359- const viewsDisplayElement = document.getElementById('total-views-display')
360- const vercountElement = document.getElementById('vercount_value_site_pv')
361- let hasAnimatedViews = false
362-
363- if (viewsDisplayElement && vercountElement) {
364- const observer = new MutationObserver((mutations) => {
365- mutations.forEach((mutation) => {
366- if (mutation.type === 'childList' || mutation.type === 'characterData') {
367- const newValue = vercountElement.textContent
368- updateViewsDisplay(viewsDisplayElement, newValue, hasAnimatedViews)
369- hasAnimatedViews = true
370- }
371- })
372- })
373-
374- observer.observe(vercountElement, {
375- childList: true,
376- characterData: true,
377- subtree: true
327+ // 监听一次更新后断开
328+ const obs = new MutationObserver(function () {
329+ updateViews()
330+ obs.disconnect()
378331 })
379-
380- const currentValue = vercountElement.textContent
381- if (currentValue && currentValue !== '-') {
382- updateViewsDisplay(viewsDisplayElement, currentValue, hasAnimatedViews)
383- hasAnimatedViews = true
384- }
332+ obs.observe(vercountEl, { childList: true, characterData: true, subtree: true })
385333 }
386334 })
387335 </script >
0 commit comments