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