Skip to content

Commit 6b85274

Browse files
authored
fix(create-local-post-file-with-category): encode name of the category (#100)
1 parent b77b0c5 commit 6b85274

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/commands/posts-list/open-post-in-vscode.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Settings } from '../../services/settings.service';
99
import { openPostFile } from './open-post-file';
1010
import { PostTitleSanitizer } from '../../services/post-title-sanitizer.service';
1111
import { postCategoryService } from '../../services/post-category.service';
12+
import sanitizeFileName from 'sanitize-filename';
1213

1314
const buildLocalPostFileUri = async (post: Post, includePostId = false): Promise<Uri> => {
1415
const workspaceUri = Settings.workspaceUri;
@@ -19,7 +20,9 @@ const buildLocalPostFileUri = async (post: Post, includePostId = false): Promise
1920
if (shouldCreateLocalPostFileWithCategory) {
2021
let categories = await postCategoryService.fetchCategories();
2122
categories = categories.filter(x => post.categoryIds?.includes(x.categoryId));
22-
const categoryTitle = categories[0]?.title ?? '';
23+
const categoryTitle = sanitizeFileName(categories[0]?.title ?? '', {
24+
replacement: invalidChar => (invalidChar === '/' ? '_' : ''),
25+
});
2326
return Uri.joinPath(workspaceUri, categoryTitle, `${postTitle}${postIdSegment}${ext}`);
2427
} else {
2528
return Uri.joinPath(workspaceUri, `${postTitle}${postIdSegment}${ext}`);

0 commit comments

Comments
 (0)