mirror of
https://codeberg.org/HPCesia/AstralHalo.git
synced 2025-04-08 17:34:27 +08:00
feat(user scripts): post file name sanitization
This commit is contained in:
parent
92e7cd5fcd
commit
cc73993047
@ -53,13 +53,13 @@ export function parseTimezoneOffset(timezone) {
|
|||||||
/**
|
/**
|
||||||
* 将标题转换为合法的文件名
|
* 将标题转换为合法的文件名
|
||||||
* @param {string} title - 原始标题
|
* @param {string} title - 原始标题
|
||||||
* @returns {string} 转换后的合法文件名,只包含小写字母、数字和连字符
|
* @returns {string} 转换后的合法文件名,不包含特殊字符
|
||||||
*/
|
*/
|
||||||
export function sanitizeTitle(title) {
|
export function sanitizeTitle(title) {
|
||||||
return title
|
return title
|
||||||
.toLowerCase()
|
.replace(/[/\\:*?"<>|]/g, '-') // 替换文件系统不允许的字符
|
||||||
.replace(/[^a-z0-9]+/g, '-')
|
.replace(/[. ]+/g, '-') // 将一个或多个点号/空格替换为单个连字符
|
||||||
.replace(/^-+|-+$/g, '');
|
.replace(/^-+|-+$/g, ''); // 移除首尾的连字符
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user