@@ -5,35 +5,17 @@ import { Alert } from '@/infra/alert'
5
5
import { PostService } from '@/service/post/post'
6
6
import { PostFileMapManager } from '@/service/post/post-file-map'
7
7
import { openPostFile } from './open-post-file'
8
- import { PostCatService } from '@/service/post/post-cat'
9
8
import sanitizeFileName from 'sanitize-filename'
10
9
import { WorkspaceCfg } from '@/ctx/cfg/workspace'
11
- import { PostCatCfg } from '@/ctx/cfg/post-cat'
12
10
import { fsUtil } from '@/infra/fs/fsUtil'
13
11
14
- export async function buildLocalPostFileUri ( post : Post , includePostId = false ) : Promise < Uri > {
12
+ export function buildLocalPostFileUri ( post : Post , includePostId = false ) : Uri {
15
13
const workspaceUri = WorkspaceCfg . getWorkspaceUri ( )
16
- const shouldCreateLocalPostFileWithCategory = PostCatCfg . isCreateLocalPostFileWithCategory ( )
17
14
const ext = `.${ post . isMarkdown ? 'md' : 'html' } `
18
15
const postIdSegment = includePostId ? `.${ post . id } ` : ''
19
16
const postTitle = sanitizeFileName ( post . title )
20
17
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 } ` )
37
19
}
38
20
39
21
export async function openPostInVscode ( postId : number , forceUpdateLocalPostFile = false ) : Promise < Uri | false > {
@@ -53,7 +35,7 @@ export async function openPostInVscode(postId: number, forceUpdateLocalPostFile
53
35
54
36
const workspaceUri = WorkspaceCfg . getWorkspaceUri ( )
55
37
await mkDirIfNotExist ( workspaceUri )
56
- let fileUri = mappedPostFilePath !== undefined ? Uri . file ( mappedPostFilePath ) : await buildLocalPostFileUri ( post )
38
+ let fileUri = mappedPostFilePath !== undefined ? Uri . file ( mappedPostFilePath ) : buildLocalPostFileUri ( post )
57
39
58
40
// 博文尚未关联到本地文件的情况
59
41
// 本地存在和博文同名的文件, 询问用户是要覆盖还是同时保留两者
@@ -65,7 +47,7 @@ export async function openPostInVscode(postId: number, forceUpdateLocalPostFile
65
47
...opt
66
48
)
67
49
68
- if ( selected === opt [ 0 ] ) fileUri = await buildLocalPostFileUri ( post , true )
50
+ if ( selected === opt [ 0 ] ) fileUri = buildLocalPostFileUri ( post , true )
69
51
}
70
52
71
53
// 博文内容写入本地文件, 若文件不存在, 会自动创建对应的文件
0 commit comments