refactor: extract repeated star formatting logic

- Extract formattedStars calculation to avoid duplication
- Keep tabular-nums span for consistent number width during animation
- Address code review feedback from @xqliu
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
This commit is contained in:
Ember
2025-11-05 13:58:34 +08:00
parent c61f57e49e
commit 3ac5a694df

View File

@@ -22,6 +22,9 @@ export default function HeroSection({ language }: HeroSectionProps) {
duration: 2000, duration: 2000,
}) })
// 格式化 stars 显示
const formattedStars = (animatedStars / 1000).toFixed(1)
const fadeInUp = { const fadeInUp = {
initial: { opacity: 0, y: 60 }, initial: { opacity: 0, y: 60 },
animate: { opacity: 1, y: 0 }, animate: { opacity: 1, y: 0 },
@@ -48,12 +51,12 @@ export default function HeroSection({ language }: HeroSectionProps) {
) : language === 'zh' ? ( ) : language === 'zh' ? (
<> <>
{daysOld} {' '} {daysOld} {' '}
<span className='inline-block tabular-nums'>{(animatedStars / 1000).toFixed(1)}</span> <span className='inline-block tabular-nums'>{formattedStars}</span>
K+ GitHub Stars K+ GitHub Stars
</> </>
) : ( ) : (
<> <>
<span className='inline-block tabular-nums'>{(animatedStars / 1000).toFixed(1)}</span> <span className='inline-block tabular-nums'>{formattedStars}</span>
K+ GitHub Stars in {daysOld} days K+ GitHub Stars in {daysOld} days
</> </>
)} )}