Skip to content

Commit 624d2e6

Browse files
authored
Merge pull request #403 from terwer/dev
feat: support outline and docTree
2 parents 1586dd0 + 4ff83dd commit 624d2e6

File tree

26 files changed

+497
-112
lines changed

26 files changed

+497
-112
lines changed

libs/zhi-blog-api/CHANGELOG.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,54 @@
11
# zhi-blog-api
22

3+
## 1.67.0
4+
5+
### Minor Changes
6+
7+
- feat: support outline and docTree
8+
- feat: add outline and docTree
9+
10+
## 1.66.0
11+
12+
### Minor Changes
13+
14+
- feat: change uploadFile
15+
16+
## 1.65.0
17+
18+
### Minor Changes
19+
20+
- feat: passwordLabel default as undefined
21+
22+
## 1.64.0
23+
24+
### Minor Changes
25+
26+
- feat: add usernameLabel and passwordLabel option
27+
28+
## 1.63.0
29+
30+
### Minor Changes
31+
32+
- feat: fix post status
33+
34+
## 1.62.0
35+
36+
### Minor Changes
37+
38+
- feat: add post status enum
39+
40+
## 1.61.0
41+
42+
### Minor Changes
43+
44+
- feat: add forceProxy for telegra.ph like platforms
45+
46+
## 1.60.0
47+
48+
### Minor Changes
49+
50+
- feat: add image store path support for github and gitlab
51+
352
## 1.59.0
453

554
### Minor Changes

libs/zhi-blog-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zhi-blog-api",
3-
"version": "1.59.0",
3+
"version": "1.67.0",
44
"type": "module",
55
"description": "a common blog interface",
66
"main": "./dist/index.js",

libs/zhi-blog-api/src/lib/IWebApi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { IBlogApi } from "./IBlogApi"
2727
import Post from "./models/post"
2828
import ElectronCookie from "./models/ElectronCookie"
2929
import WebConfig from "./WebConfig"
30+
import MediaObject from "./models/mediaObject"
3031

3132
/**
3233
* 通用博客接口
@@ -79,11 +80,10 @@ interface IWebApi extends IBlogApi {
7980
/**
8081
* 上传图片:调用平台 API 上传图片
8182
*
82-
* @param file 图片文件
83-
* @param filename 文件名,可选
83+
* @param mediaObject
8484
* @returns Promise<string> 上传后的图片地址
8585
*/
86-
uploadFile(file: File, filename?: string): Promise<any>
86+
uploadFile(mediaObject: MediaObject): Promise<any>
8787

8888
/**
8989
* 更新文章:调用平台 API 更新文章(发布工具内部通过该接口替换文章内图片地址)

libs/zhi-blog-api/src/lib/PreferenceConfig.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,35 @@ class PreferenceConfig {
4747
*/
4848
public removeMdWidgetTag: boolean
4949

50+
/**
51+
* 是否启用目录
52+
*/
53+
public outlineEnable: boolean
54+
55+
/**
56+
* 目录层级
57+
*/
58+
public outlineLevel: number
59+
60+
/**
61+
* 是否启用文档树
62+
*/
63+
public docTreeEnable: boolean
64+
65+
/**
66+
* 文档树层级
67+
*/
68+
public docTreeLevel: number
69+
5070
constructor() {
5171
this.fixTitle = false
5272
this.keepTitle = false
5373
this.removeFirstH1 = false
5474
this.removeMdWidgetTag = false
75+
this.outlineEnable = false
76+
this.outlineLevel = 3
77+
this.docTreeEnable = false
78+
this.docTreeLevel = 3
5579
}
5680
}
5781

libs/zhi-blog-api/src/lib/blogConfig.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ abstract class BlogConfig {
100100
*/
101101
public username?: string
102102

103+
/**
104+
* 用户名标题,不设置自动选择,默认 undefined
105+
*/
106+
public usernameLabel?: string
107+
103108
/**
104109
* 密码类型
105110
*/
@@ -110,6 +115,11 @@ abstract class BlogConfig {
110115
*/
111116
public password: string
112117

118+
/**
119+
* 密码标题,不设置自动选择,默认 undefined
120+
*/
121+
public passwordLabel?: string
122+
113123
/**
114124
* 密码/token设置地址
115125
*/
@@ -275,11 +285,21 @@ abstract class BlogConfig {
275285
*/
276286
public bundledPicbedSupported?: boolean
277287

288+
/**
289+
* 图片存储目录,部分平台会用到,相对于文章存储目录,默认为 images
290+
*/
291+
public imageStorePath?: string
292+
278293
/**
279294
* 图床服务类型
280295
*/
281296
public picbedService?: PicbedServiceTypeEnum
282297

298+
/**
299+
* 强制使用代理
300+
*/
301+
public forceProxy?: boolean
302+
283303
protected constructor() {
284304
this.home = ""
285305
this.apiUrl = ""
@@ -318,6 +338,8 @@ abstract class BlogConfig {
318338
this.picgoPicbedSupported = false
319339
this.bundledPicbedSupported = false
320340
this.picbedService = PicbedServiceTypeEnum.None
341+
this.imageStorePath = "images"
342+
this.forceProxy = false
321343
}
322344
}
323345

libs/zhi-blog-api/src/lib/enums/postStatusEnum.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,42 @@
2525

2626
/**
2727
* 文章状态枚举
28+
*
29+
* @link https://codex.wordpress.org/Post_Status_Transitions
2830
*/
2931
enum PostStatusEnum {
3032
/**
31-
* 已发布
33+
* 无先前状态
34+
*/
35+
PostStatusEnum_New = "new",
36+
/**
37+
* 发布
3238
*/
3339
PostStatusEnum_Publish = "publish",
40+
/**
41+
* 待审核
42+
*/
43+
PostStatusEnum_Pending = "pending",
3444
/**
3545
* 草稿
3646
*/
3747
PostStatusEnum_Draft = "draft",
3848
/**
39-
* 继承
49+
* 自动草稿
50+
*/
51+
PostStatusEnum_AutoDraft = "auto-draft",
52+
/**
53+
* 定时发布
54+
*/
55+
PostStatusEnum_Future = "future",
56+
/**
57+
* 私密
58+
*/
59+
PostStatusEnum_Private = "private",
60+
/**
61+
* 垃圾箱
4062
*/
41-
PostStatusEnum_Inherit = "inherit",
63+
PostStatusEnum_Trash = "trash",
4264
}
4365

4466
export default PostStatusEnum

libs/zhi-blog-api/src/lib/models/post.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
* questions.
2424
*/
2525

26-
import PostStatusEnum from "../enums/postStatusEnum";
27-
import PageEditMode from "./pageEditMode";
28-
import YamlStrategy from "./yamlStrategy";
26+
import PostStatusEnum from "../enums/postStatusEnum"
27+
import PageEditMode from "./pageEditMode"
28+
import YamlStrategy from "./yamlStrategy"
2929

3030
/**
3131
* 通用文章模型定义
@@ -173,6 +173,24 @@ class Post {
173173
*/
174174
yamlType?: YamlStrategy
175175

176+
/**
177+
* 目录
178+
*/
179+
outline?: any[]
180+
/**
181+
* 目录层级
182+
*/
183+
outlineLevel?: number
184+
185+
/**
186+
* 文档树
187+
*/
188+
docTree?: any[]
189+
/**
190+
* 文档树层级
191+
*/
192+
docTreeLevel?: number
193+
176194
constructor() {
177195
this.postid = ""
178196
this.originalId = ""
@@ -197,6 +215,10 @@ class Post {
197215
this.attrs = "{}"
198216
this.editMode = PageEditMode.EditMode_simple
199217
this.yamlType = YamlStrategy.YAML_default
218+
this.outline = []
219+
this.outlineLevel = 3
220+
this.docTree = []
221+
this.docTreeLevel = 3
200222
}
201223
}
202224

libs/zhi-blog-api/src/lib/webAdaptor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { simpleLogger } from "zhi-lib-base"
2929
import ElectronCookie from "./models/ElectronCookie"
3030
import WebConfig from "./WebConfig"
3131
import WebApi from "./webApi"
32+
import MediaObject from "./models/mediaObject";
3233

3334
/**
3435
* 网页授权核心基类
@@ -81,8 +82,8 @@ class WebAdaptor extends BlogAdaptor {
8182
return await this.webAdaptor.addPost(post)
8283
}
8384

84-
public async uploadFile(file: File, filename?: string): Promise<any> {
85-
return await this.webAdaptor.uploadFile(file, filename)
85+
public async uploadFile(mediaObject: MediaObject): Promise<any> {
86+
return await this.webAdaptor.uploadFile(mediaObject)
8687
}
8788

8889
public async editPost(postid: string, post: Post, publish?: boolean): Promise<boolean> {

libs/zhi-blog-api/src/lib/webApi.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { NotImplementedException } from "zhi-lib-base"
2929
import ElectronCookie from "./models/ElectronCookie"
3030
import WebConfig from "./WebConfig"
3131
import BlogApi from "./blogApi"
32+
import MediaObject from "./models/mediaObject";
3233

3334
/**
3435
* 网页授权基类
@@ -54,7 +55,7 @@ class WebApi extends BlogApi implements IWebApi {
5455
throw new NotImplementedException("You must implement addPost in sub class")
5556
}
5657

57-
public async uploadFile(file: File, filename?: string): Promise<any> {
58+
public async uploadFile(mediaObject: MediaObject): Promise<any> {
5859
throw new NotImplementedException("You must implement uploadFile in sub class")
5960
}
6061

libs/zhi-fetch-middleware/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# zhi-fetch-middleware
22

3+
## 0.12.0
4+
5+
### Minor Changes
6+
7+
- feat: check is resp is text
8+
9+
## 0.11.0
10+
11+
### Minor Changes
12+
13+
- feat: handle fetch for text/xml
14+
315
## 0.10.0
416

517
### Minor Changes

0 commit comments

Comments
 (0)