This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix different APIs with same name sharing same page in references (#361)
- Loading branch information
Showing
3 changed files
with
53 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export function uniqueSlugger(options: { | ||
base: string; | ||
isUnique: (slug: string) => boolean; | ||
}) { | ||
const limit = 10; | ||
const { base, isUnique } = options; | ||
|
||
// if slug is unique, save it and return | ||
if (isUnique(base)) { | ||
return base; | ||
} | ||
|
||
// build a new slug by adding -n where n is the first number that makes the slug unique | ||
let i = 2; | ||
while (!isUnique(`${base}-${i}`)) { | ||
i++; | ||
if (i > limit) { | ||
throw new Error(`Too many duplicates found for slug: ${base}`); | ||
} | ||
} | ||
|
||
return `${base}-${i}`; | ||
} |