fix(logic): increment check with unique maps
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
parent
0ab1a2ef45
commit
50c78cdf63
@ -102,6 +102,9 @@ export default ((opts?: Partial<BreadcrumbOptions>) => {
|
|||||||
// full path until current part
|
// full path until current part
|
||||||
let currentPath = ""
|
let currentPath = ""
|
||||||
|
|
||||||
|
// Map to store the shortened names for each path segment
|
||||||
|
const shortenedNames: Map<string, string> = new Map()
|
||||||
|
|
||||||
for (let i = 0; i < slugParts.length - 1; i++) {
|
for (let i = 0; i < slugParts.length - 1; i++) {
|
||||||
let curPathSegment = slugParts[i]
|
let curPathSegment = slugParts[i]
|
||||||
|
|
||||||
@ -127,22 +130,17 @@ export default ((opts?: Partial<BreadcrumbOptions>) => {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
case "unique":
|
case "unique":
|
||||||
let uniquePart = curPathSegment.charAt(0)
|
let shortenedName = curPathSegment.charAt(0)
|
||||||
let maxLength = Math.min(curPathSegment.length, 5)
|
let uniqueName = shortenedName
|
||||||
let isUnique = false
|
let counter = 1
|
||||||
while (!isUnique && uniquePart.length <= maxLength) {
|
|
||||||
isUnique = true
|
while (shortenedNames.has(uniqueName)) {
|
||||||
for (let j = 0; j < i; j++) {
|
uniqueName = curPathSegment.slice(0, counter + 1)
|
||||||
if (slugParts[j].startsWith(uniquePart)) {
|
counter++
|
||||||
isUnique = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!isUnique) {
|
|
||||||
uniquePart = curPathSegment.slice(0, uniquePart.length + 1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
curPathSegment = uniquePart
|
|
||||||
|
shortenedNames.set(uniqueName, currentPath)
|
||||||
|
curPathSegment = uniqueName
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user