fix(desktop): label a Windows drive path by its basename
new URL('C:\\Users\\x\\My Report.docx') parses with scheme `c:`, so the
card label was the whole backslash path. A drive letter is a path, not a
scheme; skip the URL branch for it.
This commit is contained in:
@@ -56,13 +56,16 @@ export function mediaMime(path: string): string {
|
||||
}
|
||||
|
||||
export function mediaName(path: string): string {
|
||||
try {
|
||||
const url = new URL(path)
|
||||
|
||||
return url.pathname.split('/').filter(Boolean).pop() || path
|
||||
} catch {
|
||||
return path.split(/[\\/]/).filter(Boolean).pop() || path
|
||||
// `C:\Users\…` parses as a URL with scheme `c:`; a drive letter is a path, not a scheme.
|
||||
if (!/^[A-Za-z]:[\\/]/.test(path)) {
|
||||
try {
|
||||
return new URL(path).pathname.split('/').filter(Boolean).pop() || path
|
||||
} catch {
|
||||
// not a URL — fall through to the path split
|
||||
}
|
||||
}
|
||||
|
||||
return path.split(/[\\/]/).filter(Boolean).pop() || path
|
||||
}
|
||||
|
||||
export function mediaMarkdownHref(path: string): string {
|
||||
|
||||
Reference in New Issue
Block a user