feat: 修复时区问题
This commit is contained in:
9
.editorconfig
Normal file
9
.editorconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
@@ -1,5 +1,10 @@
|
||||
import dayjs from 'dayjs';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import timezone from 'dayjs/plugin/timezone';
|
||||
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
export const formatDatetime = (date: string,format = 'YYYY-MM-DD HH:mm') => {
|
||||
return dayjs(date).format(format);
|
||||
};
|
||||
return dayjs(date).tz('Asia/Shanghai').format(format);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
import Layout from "@/layouts/Layout.astro";
|
||||
|
||||
import { http } from "@/lib/request";
|
||||
import {http} from "@/lib/request";
|
||||
import {formatDatetime} from "@/lib/format.ts";
|
||||
|
||||
interface Post {
|
||||
@@ -9,6 +9,7 @@ interface Post {
|
||||
summary: string;
|
||||
slug: string;
|
||||
cover: string;
|
||||
category_name: string;
|
||||
published_at: string;
|
||||
}
|
||||
|
||||
@@ -24,12 +25,13 @@ const {list} = await http.get<ApiPageResponse<Post>>("post");
|
||||
href={`/posts/${post.slug}`}
|
||||
>
|
||||
<div class="cover">
|
||||
<img src={post.cover} alt={post.title} />
|
||||
<img src={post.cover} alt={post.title}/>
|
||||
</div>
|
||||
<div class="post-content">
|
||||
<h2>{post.title}</h2>
|
||||
<p class="summary">{post.summary}</p>
|
||||
<div>{formatDatetime(post.published_at,'YYYY 年 MM 月 DD 日')}</div>
|
||||
<p class="summary">summary:{post.summary}</p>
|
||||
<p class="summary">category_name:{post.category_name}</p>
|
||||
<div>{formatDatetime(post.published_at, 'YYYY 年 MM 月 DD 日')}</div>
|
||||
</div>
|
||||
</a>
|
||||
))
|
||||
@@ -53,8 +55,8 @@ const {list} = await http.get<ApiPageResponse<Post>>("post");
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.post-content{
|
||||
flex:1;
|
||||
.post-content {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
@@ -63,7 +65,7 @@ const {list} = await http.get<ApiPageResponse<Post>>("post");
|
||||
color: rgb(66, 63, 63);
|
||||
}
|
||||
|
||||
.cover{
|
||||
.cover {
|
||||
width: 250px;
|
||||
height: 150px;
|
||||
border-radius: 8px;
|
||||
|
||||
Reference in New Issue
Block a user