@@ -5,35 +5,17 @@ import { Alert } from '@/infra/alert'
55import { PostService } from '@/service/post/post'
66import { PostFileMapManager } from '@/service/post/post-file-map'
77import { openPostFile } from './open-post-file'
8- import { PostCatService } from '@/service/post/post-cat'
98import sanitizeFileName from 'sanitize-filename'
109import { WorkspaceCfg } from '@/ctx/cfg/workspace'
11- import { PostCatCfg } from '@/ctx/cfg/post-cat'
1210import { fsUtil } from '@/infra/fs/fsUtil'
1311
14- export async function buildLocalPostFileUri ( post : Post , includePostId = false ) : Promise < Uri > {
12+ export function buildLocalPostFileUri ( post : Post , includePostId = false ) : Uri {
1513 const workspaceUri = WorkspaceCfg . getWorkspaceUri ( )
16- const shouldCreateLocalPostFileWithCategory = PostCatCfg . isCreateLocalPostFileWithCategory ( )
1714 const ext = `.${ post . isMarkdown ? 'md' : 'html' } `
1815 const postIdSegment = includePostId ? `.${ post . id } ` : ''
1916 const postTitle = sanitizeFileName ( post . title )
2017
21- if ( ! shouldCreateLocalPostFileWithCategory ) return Uri . joinPath ( workspaceUri , `${ postTitle } ${ postIdSegment } ${ ext } ` )
22-
23- const firstCategoryId = post . categoryIds ?. [ 0 ] ?? null
24- let i = firstCategoryId !== null ? await PostCatService . getOne ( firstCategoryId ) : null
25- let categoryTitle = ''
26- while ( i != null ) {
27- categoryTitle = path . join (
28- sanitizeFileName ( i . title , {
29- replacement : invalidChar => ( invalidChar === '/' ? '_' : '' ) ,
30- } ) ,
31- categoryTitle
32- )
33- i = i . parent ?? null
34- }
35-
36- return Uri . joinPath ( workspaceUri , categoryTitle , `${ postTitle } ${ postIdSegment } ${ ext } ` )
18+ return Uri . joinPath ( workspaceUri , `${ postTitle } ${ postIdSegment } ${ ext } ` )
3719}
3820
3921export async function openPostInVscode ( postId : number , forceUpdateLocalPostFile = false ) : Promise < Uri | false > {
@@ -53,7 +35,7 @@ export async function openPostInVscode(postId: number, forceUpdateLocalPostFile
5335
5436 const workspaceUri = WorkspaceCfg . getWorkspaceUri ( )
5537 await mkDirIfNotExist ( workspaceUri )
56- let fileUri = mappedPostFilePath !== undefined ? Uri . file ( mappedPostFilePath ) : await buildLocalPostFileUri ( post )
38+ let fileUri = mappedPostFilePath !== undefined ? Uri . file ( mappedPostFilePath ) : buildLocalPostFileUri ( post )
5739
5840 // 博文尚未关联到本地文件的情况
5941 // 本地存在和博文同名的文件, 询问用户是要覆盖还是同时保留两者
@@ -65,7 +47,7 @@ export async function openPostInVscode(postId: number, forceUpdateLocalPostFile
6547 ...opt
6648 )
6749
68- if ( selected === opt [ 0 ] ) fileUri = await buildLocalPostFileUri ( post , true )
50+ if ( selected === opt [ 0 ] ) fileUri = buildLocalPostFileUri ( post , true )
6951 }
7052
7153 // 博文内容写入本地文件, 若文件不存在, 会自动创建对应的文件
0 commit comments