-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use slot title as file basename in bundle
- Loading branch information
Showing
2 changed files
with
31 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export const slugify = (str: string, character_limit: number = 0) => { | ||
// Adapted from https://byby.dev/js-slugify-string | ||
// Character limit of 0 (default) means there is no limit | ||
const slug = String(str) | ||
.normalize("NFC") // split accented characters into their base characters and diacritical marks | ||
.replace(/[\u0300-\u036f]/g, "") // remove all the accents, which happen to be all in the \u03xx UNICODE block. | ||
.trim() // trim leading or trailing whitespace | ||
.toLowerCase() // convert to lowercase | ||
.replace(/[^a-z0-9 -]/g, "") // remove non-alphanumeric characters | ||
.replace(/\s+/g, "-") // replace spaces with hyphens | ||
.replace(/-+/g, "-"); // remove consecutive hyphens | ||
|
||
if (character_limit) { | ||
return slug.substring(0, character_limit); | ||
} | ||
return slug; | ||
}; |