Skip to content

Commit b2d2ba5

Browse files
authored
feat: configurable YFM upload (#163)
1 parent e0099df commit b2d2ba5

File tree

9 files changed

+20
-304
lines changed

9 files changed

+20
-304
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
<kbd><img src="https://img2022.cnblogs.com/blog/1596066/202204/1596066-20220415194545998-874211959.png" height="550"></kbd>
4949

50+
在上传博文时,扩展会默认忽略 YAML front matter,此行为可于设置中变更。
51+
5052
### 博客园博文列表
5153

5254
当点击列表中的博文时,会自动将博文内容下载到工作空间一个本地文件中(此时这个本地文件就关联到了这篇博文),完成编辑后可以再将本地的内容上传到博客园。

src/cmd/extract-img.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function extractImg(arg: unknown, inputImgSrc?: ImgSrc) {
1818

1919
const images = extractor.findImages()
2020
if (images.length <= 0) {
21-
if (inputImgSrc !== undefined) void Alert.info('没有找到可以提取的图片')
21+
if (inputImgSrc === undefined) void Alert.info('没有找到可以提取的图片')
2222
return
2323
}
2424

src/ctx/cfg/markdown.ts

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export namespace MarkdownCfg {
99
return cfgGet('showConfirmMsgWhenUploadPost') ?? true
1010
}
1111

12+
export function isIgnoreYfmWhenUploadPost(): boolean {
13+
return cfgGet('ignoreYfmWhenUploadPost') ?? true
14+
}
15+
1216
export function isShowConfirmMsgWhenPullPost(): boolean {
1317
return cfgGet('showConfirmMsgWhenPullPost') ?? true
1418
}

src/infra/rm-yfm.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// remove YAML front matter in markdown
2+
export function rmYfm(mkd: string) {
3+
const reg = /^---\n(\n|.)*?\n---\n*/g
4+
return mkd.replace(reg, '')
5+
}

src/service/global-ctx.ts

-54
This file was deleted.

src/service/mkd-img-extractor.service.ts

-244
This file was deleted.

src/service/mkd-img-extractor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import path from 'path'
22
import { isString } from 'lodash-es'
33
import fs from 'fs'
44
import { Uri, workspace } from 'vscode'
5-
import { ImgService } from '@/service/img'
65
import { isErrorResponse } from '@/model/error-response'
76
import { promisify } from 'util'
87
import { Readable } from 'stream'
98
import { tmpdir } from 'os'
9+
import { ImgService } from '@/service/img'
1010

1111
export const enum DataType {
1212
dataUrl,

src/service/post.ts

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { ZzkSearchResult } from '@/model/zzk-search-result'
1111
import got from '@/infra/http-client'
1212
import httpClient from '@/infra/http-client'
1313
import iconv from 'iconv-lite'
14+
import { MarkdownCfg } from '@/ctx/cfg/markdown'
15+
import { rmYfm } from '@/infra/rm-yfm'
1416
import { PostListState } from '@/model/post-list-state'
1517
import { Alert } from '@/infra/alert'
1618

@@ -100,6 +102,7 @@ export namespace PostService {
100102
}
101103

102104
export async function updatePost(post: Post) {
105+
if (MarkdownCfg.isIgnoreYfmWhenUploadPost()) post.postBody = rmYfm(post.postBody)
103106
const {
104107
ok: isOk,
105108
url,

src/setup/setup-watch.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import { LocalState } from '@/ctx/local-state'
99

1010
export const setupCfgWatch = () =>
1111
workspace.onDidChangeConfiguration(ev => {
12-
if (ev.affectsConfiguration('cnblogsConfig')) isTargetWorkspace()
12+
if (ev.affectsConfiguration('cnblogsClient')) isTargetWorkspace()
1313

1414
if (ev.affectsConfiguration('workbench.iconTheme')) refreshPostCategoryList()
1515

16-
if (ev.affectsConfiguration('cnblogsConfig.pageSize.postList'))
16+
if (ev.affectsConfiguration('cnblogsClient.pageSize.postList'))
1717
refreshPostList({ queue: true }).catch(() => undefined)
1818

19-
if (ev.affectsConfiguration('cnblogsConfig.markdown'))
19+
if (ev.affectsConfiguration('cnblogsClient.markdown'))
2020
execCmd('markdown.preview.refresh').then(undefined, () => undefined)
2121

22-
if (ev.affectsConfiguration('cnblogsConfig.ui')) setupUi(LocalState.getExtCfg())
22+
if (ev.affectsConfiguration('cnblogsClient.ui')) setupUi(LocalState.getExtCfg())
2323
})
2424

2525
export const setupWorkspaceWatch = () =>

0 commit comments

Comments
 (0)