chore: use padStart on month/date to keep a better output format

This commit is contained in:
sy
2023-03-13 20:24:34 +08:00
parent 4020cd5d48
commit b49686bb03

View File

@@ -157,10 +157,10 @@ function generateCustomizeUrl(postProperties) {
fullSlug += formatPostCreatedDate.getUTCFullYear()
} else if (pattern === '%month%' && postProperties?.date?.start_date) {
const formatPostCreatedDate = new Date(postProperties?.date?.start_date)
fullSlug += (formatPostCreatedDate.getUTCMonth() + 1)
fullSlug += String(formatPostCreatedDate.getUTCMonth() + 1).padStart(2, 0)
} else if (pattern === '%day%' && postProperties?.date?.start_date) {
const formatPostCreatedDate = new Date(postProperties?.date?.start_date)
fullSlug += formatPostCreatedDate.getUTCDate()
fullSlug += String(formatPostCreatedDate.getUTCDate()).padStart(2, 0)
} else if (pattern === '%slug%') {
fullSlug += (postProperties.slug ?? postProperties.id)
} else if (!pattern.includes('%')) {