Skip to content

Commit 77cdf9d

Browse files
committed
perf: improve bind local file to post flow
1 parent ab777b0 commit 77cdf9d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/commands/posts-list/save-post.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ export const savePostFileToCnblogs = async (fileUri: Uri) => {
1717
return;
1818
}
1919
const filePath = fileUri.fsPath;
20-
const fileName = path.basename(filePath);
21-
const fileNameWithoutExt = path.basename(fileName, path.extname(fileName));
20+
// const fileName = path.basename(filePath);
21+
// const fileNameWithoutExt = path.basename(fileName, path.extname(fileName));
2222
const postId = PostFileMapManager.getPostId(filePath);
2323
if (postId && postId >= 0) {
2424
await savePostToCnblogs((await blogPostService.fetchPostEditDto(postId)).post);
2525
} else {
26-
const options = [`新建博文`, `关联已有博文(可以根据标题搜索)`];
26+
const options = [`新建博文`, `关联已有博文`];
2727
const selected = await window.showInformationMessage(
28-
'保存博文到博客园',
28+
'本地文件尚未关联到博客园博文',
2929
{
3030
modal: true,
31-
detail: `您可以新建一篇名为"${fileNameWithoutExt}"博文, 或将文件 "${filePath}" 关联到一篇已有博文并更新该博文; 若您选择后者, 您将通过标题搜索您博客园的博文并选择一个进行关联, 关联后将会更新该博文的标题和内容.`,
31+
detail: `您可以选择新建一篇博文或将本地文件关联到一篇博客园博文(您可以根据标题搜索您在博客园博文)`,
3232
} as MessageOptions,
3333
...options
3434
);

src/commands/show-local-file-to-post-info.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import path = require('path');
12
import { MessageOptions, Uri, window } from 'vscode';
23
import { AlertService } from '../services/alert.service';
34
import { blogPostService } from '../services/blog-post.service';
45
import { postCategoryService } from '../services/post-category.service';
56
import { PostFileMapManager } from '../services/post-file-map';
6-
import { savePostFileToCnblogs } from './posts-list/save-post';
7+
import { searchPostsByTitle } from '../services/search-post-by-title';
78

89
/**
910
* 本地文件所关联的博文信息
@@ -28,7 +29,14 @@ export const showLocalFileToPostInfo = async (input: Uri | number): Promise<void
2829
...options
2930
);
3031
if (selected === options[0]) {
31-
await savePostFileToCnblogs(input);
32+
const selectedPost = await searchPostsByTitle({
33+
postTitle: path.basename(filePath, path.extname(filePath)),
34+
quickPickTitle: '搜索要关联的博文',
35+
});
36+
if (selectedPost) {
37+
await PostFileMapManager.updateOrCreate(selectedPost.id, filePath);
38+
AlertService.info(`本地文件已与博文(${selectedPost.title}, Id: ${selectedPost.id})建立关联`);
39+
}
3240
}
3341
return;
3442
}

0 commit comments

Comments
 (0)