feat: use better names for md files
This commit is contained in:
@@ -12,21 +12,25 @@ export function formatDate(date?: string | Date): string {
|
||||
return new Intl.DateTimeFormat("en-US", options).format(date);
|
||||
}
|
||||
|
||||
export function safeFileName(inputString: string): string {
|
||||
let fileName = inputString.toLowerCase();
|
||||
fileName = fileName.replace(/ /g, "_");
|
||||
fileName = fileName.replace(/[^\w.-]/g, "");
|
||||
fileName = fileName.replaceAll(":", "");
|
||||
return fileName;
|
||||
export function safeFileName(input: string): string {
|
||||
return input
|
||||
.normalize("NFKD")
|
||||
.replace(/[\u0300-\u036f]/g, "")
|
||||
.replace(/[\s-]+/g, "_")
|
||||
.replace(/[^A-Za-z0-9._]+/g, "")
|
||||
.replace(/_+/g, "_")
|
||||
// Trim underscores/dots from ends and prevent leading dots
|
||||
.replace(/^[_\.]+|[_\.]+$/g, "").replace(/^\.+/, "")
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
export function toUrlSafeString(input: string): string {
|
||||
return input
|
||||
.trim() // Remove leading and trailing whitespace
|
||||
.toLowerCase() // Convert to lowercase
|
||||
.replace(/[^a-z0-9\s-]/g, "") // Remove non-alphanumeric characters except spaces and hyphens
|
||||
.replace(/\s+/g, "-") // Replace spaces with hyphens
|
||||
.replace(/-+/g, "-"); // Remove consecutive hyphens
|
||||
.normalize("NFKD")
|
||||
.replace(/[\u0300-\u036f]/g, "")
|
||||
.replace(/[^A-Za-z0-9 _-]+/g, "")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
export function extractHashTags(inputString: string) {
|
||||
|
||||
Reference in New Issue
Block a user