Skip to content

Commit

Permalink
feat: 支持知识空间-树形单选知识空间
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 20, 2023
1 parent 9593c4a commit eb9c56c
Show file tree
Hide file tree
Showing 20 changed files with 350 additions and 117 deletions.
38 changes: 24 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,6 @@ In later releases, the release configuration will only be backward compatible to
- Support automatic generation of article aliases
- Support for changing the default knowledge base

## Compatibility of Origin notes

This plugin supports almost all devices and platforms of Siyuan Note, and the specific compatibility is as follows:

- [X] Siyuan Note Client (zero configuration) <sup>is highly recommended</sup>
- [X] Servo environment (Zero configuration, cross-domain request proxy built-in)
- [X] CentSource Note Browser Servo
- [X] Siyuan Note Client Servo
- [X] Siyuan Note mobile servo
- [X] Siyuan Note docker version (Zero configuration, cross-domain request proxy built-in)

🎉 **All platforms have been migrated to the official forward proxy, achieving zero user configuration and supporting cross-domain request proxies by default 🎉**


## Platform List

Names not listed in order
Expand Down Expand Up @@ -86,6 +72,30 @@ This plugin promises that the basic functions will be free forever, and the foll
>
> In addition to [Extended Functions], **Other functions do not require any dependencies** , and there is no need to download the previous widget, which is already built-in in the plugin.
## Compatibility of Origin notes

This plugin supports almost all devices and platforms of Siyuan Note, and the specific compatibility is as follows:

- [X] Siyuan Note Client (zero configuration) <sup>is highly recommended</sup>
- [X] Servo environment (Zero configuration, cross-domain request proxy built-in)
- [X] CentSource Note Browser Servo
- [X] Siyuan Note Client Servo
- [X] Siyuan Note mobile servo
- [X] Siyuan Note docker version (Zero configuration, cross-domain request proxy built-in)

🎉 **All platforms have been migrated to the official forward proxy, achieving zero user configuration and supporting cross-domain request proxies by default 🎉**

## Supported taxonomy

- [ ] Classification
- [ ] Single selection classification
- [X] Multi-select classification
- [ ] Tree-shaped radio classification

- [ ] Knowledge space
- [ ] Single selection knowledge space
- [X] Tree-shaped radio knowledge space

## Platform Adaptation Plan

If you have a platform you want to use, but this tool has not yet been implemented, you can submit
Expand Down
37 changes: 24 additions & 13 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,6 @@
- 支持自动生成文章别名
- 语雀支持更改默认知识库

## 思源笔记兼容情况

本插件支持思源笔记几乎所有设备和平台,具体兼容情况如下:

- [X] 思源笔记客户端(零配置)<sup>强烈推荐</sup>
- [X] 伺服环境(零配置,跨域请求代理已内置)
- [X] 思源笔记浏览器伺服
- [X] 思源笔记客户端伺服
- [X] 思源笔记移动端伺服
- [X] 思源笔记docker版(零配置,跨域请求代理已内置)

**🎉 所有平台均已迁移到官方的正向代理,实现了用户零配置,默认支持跨域请求代理 🎉**

## 平台列表

排名不分先后
Expand Down Expand Up @@ -82,6 +69,30 @@
>
> [扩展功能] 外,**其他功能无需任何依赖** ,也无需下载之前的挂件,挂件在插件中已经内置。
## 思源笔记兼容情况

本插件支持思源笔记几乎所有设备和平台,具体兼容情况如下:

- [X] 思源笔记客户端(零配置)<sup>强烈推荐</sup>
- [X] 伺服环境(零配置,跨域请求代理已内置)
- [X] 思源笔记浏览器伺服
- [X] 思源笔记客户端伺服
- [X] 思源笔记移动端伺服
- [X] 思源笔记docker版(零配置,跨域请求代理已内置)

**🎉 所有平台均已迁移到官方的正向代理,实现了用户零配置,默认支持跨域请求代理 🎉**

## 支持的分类体系

- [ ] 分类
- [ ] 单选分类
- [X] 多选分类
- [ ] 树形单选分类

- [ ] 知识空间
- [ ] 单选知识空间
- [X] 树形单选知识空间

## 平台适配计划

如果你有想使用的平台,但是此工具目前还没实现,可在这里提交 [思源笔记发布工具插件平台适配跟踪表](https://terwergreen.feishu.cn/share/base/form/shrcnGRdThUiqnhBg15xgclMM0c)
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
"vue-i18n": "^9.2.2",
"vue-router": "^4.2.4",
"xmlbuilder2": "^3.1.1",
"zhi-blog-api": "^1.30.0",
"zhi-common": "^1.21.0",
"zhi-blog-api": "^1.31.1",
"zhi-common": "^1.23.0",
"zhi-device": "^2.3.1",
"zhi-fetch-middleware": "^0.2.29",
"zhi-github-middleware": "^0.2.9",
"zhi-lib-base": "^0.4.4",
"zhi-notion-markdown": "^0.1.4",
"zhi-siyuan-api": "^2.3.6",
"zhi-siyuan-api": "^2.3.9",
"zhi-xmlrpc-middleware": "^0.4.23"
}
}
34 changes: 17 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/adaptors/api/base/github/commonGithubApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,12 @@ class CommonGithubApiAdaptor extends BaseBlogApi {
// YAML属性转换
const yamlAdaptor: YamlConvertAdaptor = this.getYamlAdaptor()
if (null !== yamlAdaptor) {
const yamlObj = YamlUtil.yaml2Obj(commonPost.description)
commonPost = yamlAdaptor.convertToAttr(commonPost, yamlObj, this.cfg)
this.logger.debug("generate yamlObj using YamlConverterAdaptor =>", yamlObj)
this.logger.info("handled yaml using YamlConverterAdaptor")
const yamlObj = await YamlUtil.yaml2ObjAsync(commonPost.description)
const yamlFormatObj = new YamlFormatObj()
yamlFormatObj.yamlObj = yamlObj
this.logger.debug("extract frontFormatter, yamlFormatObj =>", yamlFormatObj)
commonPost = yamlAdaptor.convertToAttr(commonPost, yamlFormatObj, this.cfg)
this.logger.debug("handled yamlObj using YamlConverterAdaptor =>", yamlObj)
}

// 初始化知识空间
Expand Down
8 changes: 7 additions & 1 deletion src/adaptors/api/hexo/hexoApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/

import { CommonGithubApiAdaptor } from "~/src/adaptors/api/base/github/commonGithubApiAdaptor.ts"
import { YamlConvertAdaptor } from "zhi-blog-api"
import { HexoYamlConverterAdaptor } from "~/src/adaptors/api/hexo/hexoYamlConverterAdaptor.ts"

/**
* Hexo API 适配器
Expand All @@ -32,6 +34,10 @@ import { CommonGithubApiAdaptor } from "~/src/adaptors/api/base/github/commonGit
* @version 1.3.2
* @since 0.8.1
*/
class HexoApiAdaptor extends CommonGithubApiAdaptor {}
class HexoApiAdaptor extends CommonGithubApiAdaptor {
public override getYamlAdaptor(): YamlConvertAdaptor {
return new HexoYamlConverterAdaptor()
}
}

export { HexoApiAdaptor }
9 changes: 7 additions & 2 deletions src/adaptors/api/hexo/hexoConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
* questions.
*/

import { CommonGithubConfig } from "~/src/adaptors/api/base/github/commonGithubConfig.ts"
import { PageTypeEnum, PasswordType } from "zhi-blog-api"
import {CommonGithubConfig} from "~/src/adaptors/api/base/github/commonGithubConfig.ts"
import {CategoryTypeEnum, PageTypeEnum, PasswordType} from "zhi-blog-api"

/**
* 博 Hexo 配置
Expand All @@ -51,6 +51,11 @@ class HexoConfig extends CommonGithubConfig {
this.pageType = PageTypeEnum.Markdown
this.passwordType = PasswordType.PasswordType_Token
this.allowPreviewUrlChange = false
this.allowCateChange = true
this.categoryType = CategoryTypeEnum.CategoryType_Multi
this.allowKnowledgeSpaceChange = false
this.placeholder.knowledgeSpaceReadonlyModeTip = "Hexo 平台暂不支持修改发布目录,如需修改,请删除之后重新发布"
this.knowledgeSpaceType = CategoryTypeEnum.CategoryType_Tree_Single
}
}

Expand Down
21 changes: 16 additions & 5 deletions src/adaptors/api/hexo/hexoYamlConverterAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export class HexoYamlConverterAdaptor extends YamlConvertAdaptor {
// tags
yamlFormatObj.yamlObj.tags = post.mt_keywords.split(",")

// // categories
// yamlFormatObj.yamlObj.categories = postForm.formData.categories
// categories
yamlFormatObj.yamlObj.categories = post.categories

// permalink
let link = "/post/" + post.wp_slug + ".html"
Expand Down Expand Up @@ -107,20 +107,31 @@ export class HexoYamlConverterAdaptor extends YamlConvertAdaptor {
this.logger.debug("开始转换YAML到Post", yamlFormatObj)

// 标题
post.title = yamlFormatObj.yamlObj.title
post.title = yamlFormatObj.yamlObj?.title

// 发布时间
post.dateCreated = DateUtil.convertStringToDate(yamlFormatObj.yamlObj.date)
post.dateUpdated = DateUtil.convertStringToDate(yamlFormatObj.yamlObj.updated)

// 摘要
post.shortDesc = yamlFormatObj.yamlObj.excerpt
post.shortDesc = yamlFormatObj.yamlObj?.excerpt

// 标签
post.mt_keywords = yamlFormatObj.yamlObj.tags.join(",")
post.mt_keywords = yamlFormatObj.yamlObj?.tags?.join(",")

// 分类
post.categories = yamlFormatObj.yamlObj?.categories

// 添加新的YAML
post.yaml = YamlUtil.obj2Yaml(yamlFormatObj.yamlObj)
const regex = /^---\n([\s\S]*?\n)---/;
if (regex.test(post.markdown)) {
post.markdown = post.markdown.replace(regex, "");
this.logger.debug("发现原有的YAML,已移除")
}
post.markdown = `${post.yaml}\n${post.markdown}`

this.logger.debug("转换完成,post =>", post)
return post
}
}
6 changes: 5 additions & 1 deletion src/adaptors/api/hexo/useHexoApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ const useHexoApi = async (key: string, newCfg?: HexoConfig) => {
}
}

// Hexo 使用树形单选分类
// 分类
cfg.allowCateChange = true
cfg.categoryType = CategoryTypeEnum.CategoryType_Multi
// 知识空间
cfg.allowKnowledgeSpaceChange = false
cfg.placeholder.knowledgeSpaceReadonlyModeTip = "Hexo 平台暂不支持修改发布目录,如需修改,请删除之后重新发布"
cfg.knowledgeSpaceType = CategoryTypeEnum.CategoryType_Tree_Single

// 创建 Hexo 的 yamlAdaptor
Expand Down
16 changes: 10 additions & 6 deletions src/components/publish/SinglePublishDoPublish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ const syncPublishTime = (val1: Date, val2: Date) => {
const syncPost = (post: Post) => {
formData.mergedPost = post
logger.debug("syncPost in single publish")
}
const onBack = () => {
Expand Down Expand Up @@ -341,17 +342,18 @@ onMounted(async () => {
// 分类数据初始化
formData.categoryConfig = {
cateEnabled: true,
readonlyMode: false,
categories: formData.mergedPost.categories,
readonlyMode: formData.method === MethodEnum.METHOD_EDIT && !cfg.allowCateChange,
readonlyModeTip: cfg.placeholder.cateReadonlyModeTip,
apiType: key,
cfg: cfg,
}
// 知识空间
formData.knowledgeSpaceConfig = {
cateEnabled: true,
readonlyMode: formData.method === MethodEnum.METHOD_EDIT && !cfg.allowCateChange,
readonlyModeTip: cfg.placeholder.cateReadonlyModeTip,
readonlyMode: formData.method === MethodEnum.METHOD_EDIT && !cfg.allowKnowledgeSpaceChange,
readonlyModeTip: cfg.placeholder.knowledgeSpaceReadonlyModeTip,
apiType: key,
cfg: cfg,
cateSlugs: formData.mergedPost.cate_slugs,
}
logger.debug("single publish inited mergedPost =>", toRaw(formData.mergedPost))
Expand Down Expand Up @@ -430,14 +432,16 @@ onMounted(async () => {
<publish-categories
v-model:category-type="formData.publishCfg.cfg.categoryType"
v-model:category-config="formData.categoryConfig"
v-model:categories="formData.mergedPost.categories"
@emitSyncCates="syncCates"
/>

<!-- 知识空间 -->
<publish-knowledge-space
v-model:knowledge-space-type="formData.publishCfg.cfg.knowledgeSpaceType"
v-model:knowledge-space-config="formData.knowledgeSpaceConfig"
@emitSyncCates="syncCateSlugs"
v-model:cate-slugs="formData.mergedPost.cate_slugs"
@emitSyncCateSlugs="syncCateSlugs"
/>

<!-- 发布时间 -->
Expand Down
3 changes: 2 additions & 1 deletion src/components/publish/form/CommonCategories.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ const cateMethods = {
</el-button>
</el-form-item>
<el-form-item>
<el-alert :closable="false" :title="t('category.batch.not.supported')" class="form-item-tip form-item-bottom" type="warning" />
<el-alert :closable="false" :title="t('category.batch.not.supported')" class="form-item-tip" type="warning" />
</el-form-item>
<div class="form-item-bottom"></div>
</div>
</template>

Expand Down

0 comments on commit eb9c56c

Please sign in to comment.