@@ -9,13 +9,11 @@ import sanitizeFileName from 'sanitize-filename'
9
9
import { WorkspaceCfg } from '@/ctx/cfg/workspace'
10
10
import { fsUtil } from '@/infra/fs/fsUtil'
11
11
12
- export function buildLocalPostFileUri ( post : Post , includePostId = false ) : Uri {
12
+ export function buildLocalPostFileUri ( post : Post , appendToFileName = '' ) : Uri {
13
13
const workspaceUri = WorkspaceCfg . getWorkspaceUri ( )
14
14
const ext = `.${ post . isMarkdown ? 'md' : 'html' } `
15
- const postIdSegment = includePostId ? `.${ post . id } ` : ''
16
15
const postTitle = sanitizeFileName ( post . title )
17
-
18
- return Uri . joinPath ( workspaceUri , `${ postTitle } ${ postIdSegment } ${ ext } ` )
16
+ return Uri . joinPath ( workspaceUri , `${ postTitle } ${ appendToFileName } .${ post . id } ${ ext } ` )
19
17
}
20
18
21
19
export async function openPostInVscode ( postId : number , forceUpdateLocalPostFile = false ) : Promise < Uri | false > {
@@ -40,14 +38,14 @@ export async function openPostInVscode(postId: number, forceUpdateLocalPostFile
40
38
// 博文尚未关联到本地文件的情况
41
39
// 本地存在和博文同名的文件, 询问用户是要覆盖还是同时保留两者
42
40
if ( mappedPostFilePath === undefined && ( await fsUtil . exists ( fileUri . fsPath ) ) ) {
43
- const opt = [ '保留本地文件并以博文 ID 为文件名新建另一个文件 ' , '覆盖本地文件' ]
41
+ const opt = [ '保留本地文件并新建另一个文件 ' , '覆盖本地文件' ]
44
42
const selected = await Alert . info (
45
43
`无法建立博文与本地文件的关联, 文件名冲突` ,
46
44
{ detail : `本地已存在名为 ${ path . basename ( fileUri . fsPath ) } 的文件` , modal : true } ,
47
45
...opt
48
46
)
49
47
50
- if ( selected === opt [ 0 ] ) fileUri = buildLocalPostFileUri ( post , true )
48
+ if ( selected === opt [ 0 ] ) fileUri = buildLocalPostFileUri ( post , '-new' )
51
49
}
52
50
53
51
// 博文内容写入本地文件, 若文件不存在, 会自动创建对应的文件
0 commit comments