feat(更换short_id实现方式): 避免因为缩短导致的潜在bug

(cherry picked from commit 6d73a4388c1613dc0a719d68c8b4b3432fefd314)
This commit is contained in:
anime
2024-12-20 18:15:28 +08:00
parent 8493414402
commit 45a6ec1eb4
3 changed files with 4 additions and 8 deletions

View File

@@ -27,8 +27,7 @@ export const convertInnerUrl = allPages => {
const slug = getLastPartOfUrl(anchorTag.href) const slug = getLastPartOfUrl(anchorTag.href)
if (checkStrIsNotionId(slug)) { if (checkStrIsNotionId(slug)) {
const slugPage = allPages?.find(page => { const slugPage = allPages?.find(page => {
const find = idToUuid(slug).indexOf(page.short_id) === 0 return idToUuid(slug).indexOf(page.short_id) === 14
return find
}) })
if (slugPage) { if (slugPage) {
anchorTag.href = slugPage?.href anchorTag.href = slugPage?.href

View File

@@ -38,10 +38,7 @@ function getShortId(uuid) {
if (!uuid || uuid.indexOf('-') < 0) { if (!uuid || uuid.indexOf('-') < 0) {
return uuid return uuid
} }
// 找到第一个 '-' 的位置 return uuid.substring(14)
const index = uuid.indexOf('-')
// 截取从开始到第一个 '-' 之前的部分
return uuid.substring(0, index)
} }
module.exports = { extractLangPrefix, extractLangId, getShortId } module.exports = { extractLangPrefix, extractLangId, getShortId }

View File

@@ -78,7 +78,7 @@ function getNavPagesWithLatest(allNavPages, latestPosts, post) {
} }
// 属于最新文章通常6篇 && (无阅读记录 || 最近更新时间大于上次阅读时间) // 属于最新文章通常6篇 && (无阅读记录 || 最近更新时间大于上次阅读时间)
if ( if (
latestPosts.some(post => post?.id.indexOf(item?.short_id) === 0) && latestPosts.some(post => post?.id.indexOf(item?.short_id) === 14) &&
(!postReadTime[item.short_id] || (!postReadTime[item.short_id] ||
postReadTime[item.short_id] < new Date(item.lastEditedDate).getTime()) postReadTime[item.short_id] < new Date(item.lastEditedDate).getTime())
) { ) {