mirror of
https://github.com/KazooTTT/kazoottt-blog-v2.git
synced 2025-06-16 15:31:21 +08:00
feat(rss): RSS 时间转换为北京时间
- 将 RSS 源中的时间转换为北京时间,保证时区正确。 - 使用 `convertToBeijingTime` 函数进行转换。
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { getAllPosts } from "@/data/post";
|
||||
import { siteConfig } from "@/site.config";
|
||||
import { collectionDateSort } from "@/utils/date";
|
||||
import { collectionDateSort, convertToBeijingTime } from "@/utils/date";
|
||||
import rss from "@astrojs/rss";
|
||||
import MarkdownIt from "markdown-it";
|
||||
import sanitizeHtml from "sanitize-html";
|
||||
@ -25,7 +25,7 @@ export const GET = async () => {
|
||||
return {
|
||||
title: post.data.title,
|
||||
description: (post.data.description ?? "") + "\t" + tagStr,
|
||||
pubDate: post.dateToCmp,
|
||||
pubDate: convertToBeijingTime(post.dateToCmp),
|
||||
link: `posts/${post.id}/`,
|
||||
content: post.body
|
||||
? sanitizeHtml(
|
||||
|
@ -23,3 +23,18 @@ export function collectionDateSort(a: AllItem, b: AllItem) {
|
||||
export function getLatestUpdatedPost(a: AllItem, b: AllItem) {
|
||||
return getDateSortByUpdateTime(b).getTime() - getDateSortByUpdateTime(a).getTime();
|
||||
}
|
||||
|
||||
export function convertToBeijingTime(date: Date) {
|
||||
const options = {
|
||||
timeZone: "Asia/Shanghai",
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
};
|
||||
const formatter = new Intl.DateTimeFormat("zh-CN", options as Intl.DateTimeFormatOptions);
|
||||
const formattedDate = formatter.format(date);
|
||||
return formattedDate;
|
||||
}
|
||||
|
Reference in New Issue
Block a user