Skip to content

Commit

Permalink
feat: #130 支持发布到CSDN
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Sep 1, 2023
1 parent d97499d commit 5566040
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 17 deletions.
38 changes: 38 additions & 0 deletions docs/插件开发.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## 插件开发指南

先要确定插件所属的大类,这个是发布工具内置的,需要发布工具内部添加维护,不支持用户自定义。
目前可用的有
- Common
- Metaweblog
- Wordpress
- Github
- Gitlab
- Custom
- System

新增大类的时候需要维护
- DynamicJsonCfg
- getSubtypeList
- setDynamicJsonCfg
- src/utils/import/pre.ts

## API授权插件开发指南

## 网页授权插件开发指南

1. 确定大类。例如:CSDN属于Custom
2. 新建子类别。例如:SubPlatformType加一个Custom_CSDN
3. 注册子类别,需要修改
- getSubtypeList
- src/utils/import/pre.ts
4. 新增适配器
网页授权需要再 src/adaptors/web 新建文件。例如
- csdnWebAdaptor 需要继承 BaseWebApi
- csdnConfig 需要继承 CommonWebConfig
- csdnPlaceholder 需要继承 CommonWebPlaceholder
- useCsdnWeb 定义 const useCsdnWeb = async (key?: string, newCfg?: CsdnConfig) => {}
5. 注册适配器
适配器 src/adaptors/index.ts getCfg
配置 src/adaptors/index.ts getAdaptor
YAML适配器(不一定有)

14 changes: 13 additions & 1 deletion src/adaptors/web/csdn/csdnConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,24 @@
*/

import { CommonWebConfig } from "~/src/adaptors/web/base/commonWebConfig.ts"
import { CategoryTypeEnum, PageTypeEnum, PasswordType } from "zhi-blog-api"

/**
* CSDN配置
*/
export class CsdnConfig extends CommonWebConfig {
constructor(username: string, password: string, middlewareUrl?: string) {
super("", "", username, password, middlewareUrl)
super("https://blog.csdn.net", "https://blog.csdn.net/api", username, password, middlewareUrl)
this.previewUrl = "[userid]/article/details/[postid]"
this.pageType = PageTypeEnum.Html
this.usernameEnabled = true
this.passwordType = PasswordType.PasswordType_Cookie
this.cateEnabled = false
this.knowledgeSpaceEnabled = true
this.knowledgeSpaceTitle = "分类"
this.knowledgeSpaceType = CategoryTypeEnum.CategoryType_Single
this.allowKnowledgeSpaceChange = false
this.placeholder.knowledgeSpaceReadonlyModeTip =
"由于CSDN平台限制,暂时不支持编辑CSDN分类,如需修改,请删除后重新发布"
}
}
30 changes: 30 additions & 0 deletions src/adaptors/web/csdn/csdnPlaceholder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
* or visit www.terwer.space if you need additional information or have any
* questions.
*/

import { CommonWebPlaceholder } from "~/src/adaptors/web/base/commonWebPlaceholder.ts"

class CsdnPlaceholder extends CommonWebPlaceholder {}

export { CsdnPlaceholder }
1 change: 0 additions & 1 deletion src/adaptors/web/csdn/docs.md

This file was deleted.

9 changes: 9 additions & 0 deletions src/adaptors/web/csdn/useCsdnWeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { JsonUtil, ObjectUtil, StrUtil } from "zhi-common"
import { Utils } from "~/src/utils/utils.ts"
import { getDynPostidKey } from "~/src/platforms/dynamicConfig.ts"
import { CsdnWebAdaptor } from "~/src/adaptors/web/csdn/csdnWebAdaptor.ts"
import { CategoryTypeEnum } from "zhi-blog-api"

/**
* 用于获取CsdnWeb的API的自定义Hook
Expand Down Expand Up @@ -80,8 +81,16 @@ const useCsdnWeb = async (key?: string, newCfg?: CsdnConfig) => {
}
}

// CSDN使用单选分类作为专栏
cfg.cateEnabled = false
cfg.knowledgeSpaceEnabled = true
cfg.knowledgeSpaceType = CategoryTypeEnum.CategoryType_Single
cfg.allowKnowledgeSpaceChange = false
cfg.placeholder.knowledgeSpaceReadonlyModeTip = "由于CSDN平台限制,暂时不支持编辑CSDN分类,如需修改,请删除后重新发布"

const webApi = new CsdnWebAdaptor(appInstance, cfg)
return {
cfg,
webApi,
}
}
Expand Down
1 change: 0 additions & 1 deletion src/adaptors/web/zhihu/docs.md

This file was deleted.

4 changes: 2 additions & 2 deletions src/platforms/dynamicConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export enum SubPlatformType {

// Custom
Custom_Zhihu = "Zhihu",
// Custom_CSDN = "Csdn",
Custom_CSDN = "Csdn",
// Custom_Jianshu = "Jianshu",
// Custom_Juejin = "Juejin",
// Custom_Wechat = "Wechat",
Expand Down Expand Up @@ -245,7 +245,7 @@ export function getSubtypeList(ptype: PlatformType): SubPlatformType[] {
break
case PlatformType.Custom:
subtypeList.push(SubPlatformType.Custom_Zhihu)
// subtypeList.push(SubPlatformType.Custom_CSDN)
subtypeList.push(SubPlatformType.Custom_CSDN)
// subtypeList.push(SubPlatformType.Custom_Jianshu)
// subtypeList.push(SubPlatformType.Custom_Juejin)
// subtypeList.push(SubPlatformType.Custom_Wechat)
Expand Down
24 changes: 12 additions & 12 deletions src/utils/import/pre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,18 @@ export const pre = {
domain: "zhihu.com",
isEnabled: false,
},
// // CSDN 目前有CA验证
// {
// platformType: PlatformType.Custom,
// subPlatformType: SubPlatformType.Custom_CSDN,
// platformKey: "custom_Csdn",
// platformName: "CSDN",
// platformIcon: svgIcons.iconIFCSDN,
// authMode: AuthMode.WEBSITE,
// authUrl: "https://passport.csdn.net/login",
// domain: "csdn.net",
// isEnabled: false,
// },
// CSDN 目前有CA验证
{
platformType: PlatformType.Custom,
subPlatformType: SubPlatformType.Custom_CSDN,
platformKey: "custom_Csdn",
platformName: "CSDN",
platformIcon: svgIcons.iconIFCSDN,
authMode: AuthMode.WEBSITE,
authUrl: "https://passport.csdn.net/login",
domain: "csdn.net",
isEnabled: false,
},
// {
// platformType: PlatformType.Custom,
// subPlatformType: SubPlatformType.Custom_Jianshu,
Expand Down

0 comments on commit 5566040

Please sign in to comment.