Skip to content

Commit

Permalink
feat: 支持文章分类
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 16, 2023
1 parent 058ce4e commit 782f4fb
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 45 deletions.
4 changes: 2 additions & 2 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.24.1",
"zhi-blog-api": "^1.25.1",
"zhi-common": "^1.20.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.2.1",
"zhi-siyuan-api": "^2.2.3",
"zhi-xmlrpc-middleware": "^0.4.23"
}
}
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

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

4 changes: 4 additions & 0 deletions src/adaptors/api/hexo/useHexoApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { getDynPostidKey } from "~/src/platforms/dynamicConfig.ts"
import { HexoConfig } from "~/src/adaptors/api/hexo/hexoConfig.ts"
import { HexoApiAdaptor } from "~/src/adaptors/api/hexo/hexoApiAdaptor.ts"
import { HexoYamlConverterAdaptor } from "~/src/adaptors/api/hexo/hexoYamlConverterAdaptor.ts"
import { CategoryTypeEnum } from "zhi-blog-api"

const useHexoApi = async (key: string, newCfg?: HexoConfig) => {
// 创建应用日志记录器
Expand Down Expand Up @@ -76,6 +77,9 @@ const useHexoApi = async (key: string, newCfg?: HexoConfig) => {
}
}

// Hexo 使用树形单选分类
cfg.categoryType = CategoryTypeEnum.CategoryType_Tree_Single

// 创建 Hexo 的 yamlAdaptor
const yamlAdaptor = new HexoYamlConverterAdaptor()

Expand Down
22 changes: 12 additions & 10 deletions src/adaptors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* questions.
*/

import { BlogAdaptor, BlogConfig, WebAdaptor } from "zhi-blog-api"
import { BlogAdaptor, WebAdaptor } from "zhi-blog-api"
import { getSubPlatformTypeByKey, SubPlatformType } from "~/src/platforms/dynamicConfig.ts"
import { useCnblogsApi } from "~/src/adaptors/api/cnblogs/useCnblogsApi.ts"
import { createAppLogger } from "~/src/utils/appLogger.ts"
Expand All @@ -36,6 +36,7 @@ import { useMetaweblogApi } from "~/src/adaptors/api/metaweblog/useMetaweblogApi
import { useNotionApi } from "~/src/adaptors/api/notion/useNotionApi.ts"
import { useHexoApi } from "~/src/adaptors/api/hexo/useHexoApi.ts"
import { YamlConvertAdaptor } from "~/src/platforms/yamlConvertAdaptor.ts"
import { CommonBlogConfig } from "~/src/adaptors/api/base/commonBlogConfig.ts"

/**
* 适配器统一入口
Expand All @@ -50,49 +51,50 @@ class Adaptors {
* 根据平台key查找配置
*
* @param key
* @param newCfg
*/
public static async getCfg(key: string): Promise<BlogConfig> {
public static async getCfg(key: string, newCfg?: any): Promise<CommonBlogConfig> {
let conf = null
const type: SubPlatformType = getSubPlatformTypeByKey(key)

switch (type) {
case SubPlatformType.Common_Yuque: {
const { cfg } = await useYuqueApi(key)
const { cfg } = await useYuqueApi(key, newCfg)
conf = cfg
break
}
case SubPlatformType.Common_Notion: {
const { cfg } = await useNotionApi(key)
const { cfg } = await useNotionApi(key, newCfg)
conf = cfg
break
}
case SubPlatformType.Github_Hexo: {
const { cfg } = await useHexoApi(key)
const { cfg } = await useHexoApi(key, newCfg)
conf = cfg
break
}
case SubPlatformType.Metaweblog_Metaweblog: {
const { cfg } = await useMetaweblogApi(key)
const { cfg } = await useMetaweblogApi(key, newCfg)
conf = cfg
break
}
case SubPlatformType.Metaweblog_Cnblogs: {
const { cfg } = await useCnblogsApi(key)
const { cfg } = await useCnblogsApi(key, newCfg)
conf = cfg
break
}
case SubPlatformType.Metaweblog_Typecho: {
const { cfg } = await useTypechoApi(key)
const { cfg } = await useTypechoApi(key, newCfg)
conf = cfg
break
}
case SubPlatformType.Wordpress_Wordpress: {
const { cfg } = await useWordpressApi(key)
const { cfg } = await useWordpressApi(key, newCfg)
conf = cfg
break
}
case SubPlatformType.Custom_Zhihu: {
const { cfg } = await useZhihuWeb(key)
const { cfg } = await useZhihuWeb(key, newCfg)
conf = cfg
break
}
Expand Down
7 changes: 3 additions & 4 deletions src/components/publish/BatchPublishIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { pre } from "~/src/utils/import/pre.ts"
import { Delete } from "@element-plus/icons-vue"
import { BrowserUtil } from "zhi-device"
import { usePublishConfig } from "~/src/composables/usePublishConfig.ts"
import { Post } from "zhi-blog-api"
import { CategoryTypeEnum, Post } from "zhi-blog-api"
import { IPublishCfg } from "~/src/types/IPublishCfg.ts"
import { PageEditMode } from "~/src/models/pageEditMode.ts"
import EditModeSelect from "~/src/components/publish/form/EditModeSelect.vue"
Expand Down Expand Up @@ -345,9 +345,8 @@ onMounted(async () => {
@emitSyncTags="syncTags"
/>

<!-- 分类
<publish-categories />
-->
<!-- 分类 -->
<publish-categories v-model:category-type="CategoryTypeEnum.CategoryType_Single" />

<!-- 发布时间 -->
<publish-time v-model="formData.siyuanPost" @emitSyncPublishTime="syncPublishTime" />
Expand Down
5 changes: 2 additions & 3 deletions src/components/publish/SinglePublishDoPublish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,8 @@ onMounted(async () => {
@emitSyncTags="syncTags"
/>

<!-- 分类
<publish-categories />
-->
<!-- 分类 -->
<publish-categories v-model:category-type="formData.publishCfg.cfg.categoryType" />

<!-- 发布时间 -->
<publish-time v-model="formData.mergedPost" @emitSyncPublishTime="syncPublishTime" />
Expand Down
32 changes: 26 additions & 6 deletions src/components/publish/form/PublishCategories.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,35 @@
-->

<script setup lang="ts">
import { CategoryTypeEnum } from "zhi-blog-api"
import { reactive } from "vue"
const props = defineProps({
categoryType: {
type: String,
default: CategoryTypeEnum.CategoryType_None,
},
})
const formData = reactive({
categoryType: props.categoryType,
})
</script>

<template>
<div>
发布分类
</div>
<div v-if="formData.categoryType === CategoryTypeEnum.CategoryType_Single">
<single-category />
</div>
<div v-else-if="formData.categoryType === CategoryTypeEnum.CategoryType_Multi">
<multi-categories />
</div>
<div v-else-if="formData.categoryType === CategoryTypeEnum.CategoryType_Tree_Single">
<tree-single-category />
</div>
<div v-else-if="formData.categoryType === CategoryTypeEnum.CategoryType_Tree_Multi">
<tree-multi-categories />
</div>
<div v-else></div>
</template>

<style scoped lang="stylus">
</style>
<style scoped lang="stylus"></style>
2 changes: 1 addition & 1 deletion src/components/publish/form/category/MultiCategories.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</script>

<template>

<div>简单多选分类</div>
</template>

<style scoped lang="stylus">
Expand Down
10 changes: 3 additions & 7 deletions src/components/publish/form/category/SingleCategory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@
- questions.
-->

<script setup lang="ts">
</script>
<script setup lang="ts"></script>

<template>

<div>简单单选分类</div>
</template>

<style scoped lang="stylus">
</style>
<style scoped lang="stylus"></style>
38 changes: 38 additions & 0 deletions src/components/publish/form/category/TreeMultiCategories.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--
- 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.
-->

<script setup lang="ts">
</script>

<template>
<div>
树形多选分类
</div>
</template>

<style scoped lang="stylus">
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</script>

<template>

<div>树形单选分类</div>
</template>

<style scoped lang="stylus">
Expand Down
3 changes: 2 additions & 1 deletion src/composables/usePublishConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ const usePublishConfig = () => {

// 平台配置
if (key) {
const cfg = JsonUtil.safeParse<any>(setting[key], {} as any)
const storedCfg = JsonUtil.safeParse<any>(setting[key], {} as any)
const cfg = await Adaptors.getCfg(key, storedCfg)
const dynCfg = getDynCfgByKey(dynamicConfigArray, key)

return {
Expand Down

0 comments on commit 782f4fb

Please sign in to comment.