Skip to content

Conversation

Escape2snap
Copy link

No description provided.

Copy link

vercel bot commented Aug 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fuwari-yags ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 5, 2025 0:25am

@Escape2snap
Copy link
Author

It's directly create this PR by VSCode that I haven't edit the PR info...

This uses a more convenient method to create the timestamp for published: in new-post and conveniently improves the precision of the timestamp, allowing articles generated by multiple new-post actions within a day to be sorted in the order of their creation time.

這使用了一個更加便捷的方法來創建 new-postpublished: 的時間戳、並很方便地提高了時間戳精度。使得一日內的多次 new-post 產生的文章也能夠按照創建時間順序進行排序。

@L4Ph L4Ph requested a review from Copilot August 6, 2025 08:44
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR simplifies the date formatting logic in the getDate function by replacing manual date component extraction and formatting with the built-in toISOString() method.

  • Removes manual year, month, and day extraction and padding logic
  • Replaces custom date formatting with toISOString() method call

const day = String(today.getDate()).padStart(2, "0")

return `${year}-${month}-${day}`
return new Date().toISOString()
Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The toISOString() method returns a full ISO 8601 timestamp (e.g., '2023-08-15T14:30:00.000Z') instead of just the date portion (e.g., '2023-08-15'). This breaks the expected format and likely affects downstream code that expects only the date. Consider using toISOString().split('T')[0] to extract just the date portion.

Suggested change
return new Date().toISOString()
return new Date().toISOString().split('T')[0]

Copilot uses AI. Check for mistakes.

@Escape2snap
Copy link
Author

Escape2snap commented Aug 6, 2025

In .\src\utils\content-utils.ts, the following code is used to sort articles in chronological order.
.\src\utils\content-utils.ts 中,使用了如下代碼使得文章能夠按照時間順序排序。

// // Retrieve posts and sort them by publication date
async function getRawSortedPosts() {
	const allBlogPosts = await getCollection("posts", ({ data }) => {
		return import.meta.env.PROD ? data.draft !== true : true;
	});

	const sorted = allBlogPosts.sort((a, b) => {
		const dateA = new Date(a.data.published);
		const dateB = new Date(b.data.published);
		return dateA > dateB ? -1 : 1;
	});
	return sorted;
}

The method uses the built-in Date() function of JavaScript, which can correctly accept the time format of Date().toISOString().
该方法使用的是 JavaScriptDate() 內置函數,可以正確地接收 Date().toISOString() 的時間格式。

In the project, I tried to search for the format keyword in the editor and listed the possible ways to format time below.
而在項目中其他格式化時間的方法、我嘗試在編輯器查找 format 關鍵字並將可能格式化時間的方式在下方列出。

.\src\utils\date-utils.ts

export function formatDateToYYYYMMDD(date: Date): string {
	return date.toISOString().substring(0, 10);
}

.\src\components\ArchivePanel.svelte

function formatDate(date: Date) {
	const month = (date.getMonth() + 1).toString().padStart(2, "0");
	const day = date.getDate().toString().padStart(2, "0");
	return `${month}-${day}`;
}

They all use the Date() method to handle and format time.
他們都使用的是 Date() 方法來處理、格式時間。

@L4Ph
Copy link
Collaborator

L4Ph commented Aug 6, 2025

The date initialized in new-post.js serves not only as a sorting criterion but also functions as the article's Frontmatter, which will be used as the actual display date and time.
As a result, ISO 8601 timestamps may display in unexpected ways for existing users.

@Escape2snap
Copy link
Author

Yes, it will be recorded in the Frontmatter, and users will definitely notice this ISO 8601 timestamp when they edit.
是的、他會被記錄在 Frontmatter 中、並且用戶編輯的時候一定會注意到這個 ISO 8601 時間戳、

It's hard to balance readability and the difficulty of editing. For me, I might edit several articles in a day, but the previous method couldn't sort my articles by editing time well.
這很難保持易讀性和編輯難度的平衡、對於我、我可能一天編輯幾篇文章而先前的方式並不能良好的將我的文章進行編輯時間的排序、

@L4Ph L4Ph requested a review from saicaca August 6, 2025 13:08
@saicaca
Copy link
Owner

saicaca commented Aug 9, 2025

I think this is a reasonable change. It makes sense for posts created on the same day to be sorted. The times on the built pages should have already been re-formatted, so this change shouldn't affect the display.

I think the only problem here is that the ISO 8601 format is less readable, but it shouldn't be a big problem since users usually don't need to edit the generated time. To make it less unreadable, I suggest we remove the parts after the seconds and use a format like 2025-08-09T12:00:00.

@Escape2snap
Copy link
Author

Escape2snap commented Aug 9, 2025

I got it...

I will put the possible modifications below.

function getDate() {
    const today = new Date()
    const year = today.getFullYear()
    const month = String(today.getMonth() + 1).padStart(2, "0")
    const day = String(today.getDate()).padStart(2, "0")
    const hours = String(today.getHours()).padStart(2, "0")
    const minutes = String(today.getMinutes()).padStart(2, "0")
    const seconds = String(today.getSeconds()).padStart(2, "0")

    return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`
}

What needs to be considered is that there is a possible time zone problem here.

If we ignore the time zone problem and keep the format just mentioned above, then a simple approach may be like this.

function getDate() {
    return date.toISOString().substring(0, 19);
}

@saicaca
Copy link
Owner

saicaca commented Aug 23, 2025

If we ignore the time zone problem and keep the format just mentioned above, then a simple approach may be like this.

function getDate() {
    return date.toISOString().substring(0, 19);
}

I think this is ok. We don't need to worry about the time zone since the time within the day is only used for sorting.

@Escape2snap
Copy link
Author

好吶————
Hoooooooooooray~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants