Skip to content

Commit 5a715c6

Browse files
committed
refactor: mv dateFormate function to src/lib/utils
1 parent 6d220c3 commit 5a715c6

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/layouts/PostLayout.astro

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
---
2+
import { formatDate } from '@/lib/utils';
23
import Baselayout from './Baselayout.astro';
34
45
const { post } = Astro.props;
56
const { title, pubDate, description, update } = post.data;
67
7-
const formatDate = (date: Date) => {
8-
return date
9-
.toLocaleDateString('zh-CN', {
10-
year: 'numeric',
11-
month: '2-digit',
12-
day: '2-digit',
13-
})
14-
.replace(/\//g, '.');
15-
};
168
---
179

1810
<Baselayout>

src/lib/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,13 @@ import { clsx, type ClassValue } from 'clsx';
22
import { twMerge } from 'tailwind-merge';
33

44
export const cn = (...inputs: ClassValue[]) => twMerge(clsx(inputs));
5+
6+
export const formatDate = (date: Date) => {
7+
return date
8+
.toLocaleDateString('zh-CN', {
9+
year: 'numeric',
10+
month: '2-digit',
11+
day: '2-digit',
12+
})
13+
.replace(/\//g, '.');
14+
};

0 commit comments

Comments
 (0)