From b9d18294841cbf797a742e575ce1dc3253b8d611 Mon Sep 17 00:00:00 2001 From: terwer Date: Mon, 11 Sep 2023 23:36:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=A8=E9=9D=A2=E6=94=AF=E6=8C=81Git?= =?UTF-8?q?hub=E5=92=8CGitlab=E5=90=84=E5=B9=B3=E5=8F=B0-Vuepress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/gitlab-hexo/gitlabhexoApiAdaptor.ts | 6 +- ...r.ts => gitlabhexoYamlConverterAdaptor.ts} | 4 +- .../api/gitlab-hexo/useGitlabhexoApi.ts | 8 +- .../api/gitlab-hugo/gitlabhugoApiAdaptor.ts | 4 +- .../gitlab-jekyll/gitlabjekyllApiAdaptor.ts | 4 +- .../gitlabvuepressApiAdaptor.ts | 76 +++++++++ .../gitlab-vuepress/gitlabvuepressConfig.ts | 69 ++++++++ .../gitlabvuepressPlaceHolder.ts | 30 ++++ .../gitlabvuepressYamlConverterAdaptor.ts | 36 ++++ .../gitlab-vuepress/useGitlabvuepressApi.ts | 112 +++++++++++++ src/adaptors/api/vuepress/useVuepressApi.ts | 111 +++++++++++++ .../api/vuepress/vuepressApiAdaptor.ts | 73 +++++++++ src/adaptors/api/vuepress/vuepressConfig.ts | 67 ++++++++ .../api/vuepress/vuepressPlaceHolder.ts | 30 ++++ .../vuepress/vuepressYamlConverterAdaptor.ts | 154 ++++++++++++++++++ src/adaptors/base/baseExtendApi.ts | 83 ++++++---- src/adaptors/index.ts | 32 ++++ .../singleplatform/SingleSettingIndex.vue | 4 + .../singleplatform/github/VuepressSetting.vue | 57 +++++++ .../gitlab/GitlabvuepressSetting.vue | 68 ++++++++ 20 files changed, 981 insertions(+), 47 deletions(-) rename src/adaptors/api/gitlab-hexo/{gitlabHexoYamlConverterAdaptor.ts => gitlabhexoYamlConverterAdaptor.ts} (92%) create mode 100644 src/adaptors/api/gitlab-vuepress/gitlabvuepressApiAdaptor.ts create mode 100644 src/adaptors/api/gitlab-vuepress/gitlabvuepressConfig.ts create mode 100644 src/adaptors/api/gitlab-vuepress/gitlabvuepressPlaceHolder.ts create mode 100644 src/adaptors/api/gitlab-vuepress/gitlabvuepressYamlConverterAdaptor.ts create mode 100644 src/adaptors/api/gitlab-vuepress/useGitlabvuepressApi.ts create mode 100644 src/adaptors/api/vuepress/useVuepressApi.ts create mode 100644 src/adaptors/api/vuepress/vuepressApiAdaptor.ts create mode 100644 src/adaptors/api/vuepress/vuepressConfig.ts create mode 100644 src/adaptors/api/vuepress/vuepressPlaceHolder.ts create mode 100644 src/adaptors/api/vuepress/vuepressYamlConverterAdaptor.ts create mode 100644 src/components/set/publish/singleplatform/github/VuepressSetting.vue create mode 100644 src/components/set/publish/singleplatform/gitlab/GitlabvuepressSetting.vue diff --git a/src/adaptors/api/gitlab-hexo/gitlabhexoApiAdaptor.ts b/src/adaptors/api/gitlab-hexo/gitlabhexoApiAdaptor.ts index 7c1a23b0..08703163 100644 --- a/src/adaptors/api/gitlab-hexo/gitlabhexoApiAdaptor.ts +++ b/src/adaptors/api/gitlab-hexo/gitlabhexoApiAdaptor.ts @@ -24,12 +24,12 @@ */ import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api" -import { GitlabHexoYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-hexo/gitlabHexoYamlConverterAdaptor.ts" +import { GitlabhexoYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-hexo/gitlabhexoYamlConverterAdaptor.ts" import { CommonGitlabApiAdaptor } from "~/src/adaptors/api/base/gitlab/commonGitlabApiAdaptor.ts" import _ from "lodash" /** - * Hexo API 适配器 + * Gitlabhexo API 适配器 * * @author terwer * @version 1.3.2 @@ -37,7 +37,7 @@ import _ from "lodash" */ class GitlabhexoApiAdaptor extends CommonGitlabApiAdaptor { public override getYamlAdaptor(): YamlConvertAdaptor { - return new GitlabHexoYamlConverterAdaptor() + return new GitlabhexoYamlConverterAdaptor() } public override async preEditPost(post: Post, id?: string, publishCfg?: any): Promise { diff --git a/src/adaptors/api/gitlab-hexo/gitlabHexoYamlConverterAdaptor.ts b/src/adaptors/api/gitlab-hexo/gitlabhexoYamlConverterAdaptor.ts similarity index 92% rename from src/adaptors/api/gitlab-hexo/gitlabHexoYamlConverterAdaptor.ts rename to src/adaptors/api/gitlab-hexo/gitlabhexoYamlConverterAdaptor.ts index c52ad8ec..26191a8f 100644 --- a/src/adaptors/api/gitlab-hexo/gitlabHexoYamlConverterAdaptor.ts +++ b/src/adaptors/api/gitlab-hexo/gitlabhexoYamlConverterAdaptor.ts @@ -31,6 +31,6 @@ import { HexoYamlConverterAdaptor } from "~/src/adaptors/api/hexo/hexoYamlConver * @author terwer * @since 0.8.1 */ -class GitlabHexoYamlConverterAdaptor extends HexoYamlConverterAdaptor {} +class GitlabhexoYamlConverterAdaptor extends HexoYamlConverterAdaptor {} -export { GitlabHexoYamlConverterAdaptor } +export { GitlabhexoYamlConverterAdaptor } diff --git a/src/adaptors/api/gitlab-hexo/useGitlabhexoApi.ts b/src/adaptors/api/gitlab-hexo/useGitlabhexoApi.ts index 3daba77c..aba1c7f1 100644 --- a/src/adaptors/api/gitlab-hexo/useGitlabhexoApi.ts +++ b/src/adaptors/api/gitlab-hexo/useGitlabhexoApi.ts @@ -31,7 +31,7 @@ import { Utils } from "~/src/utils/utils.ts" import { getDynPostidKey } from "~/src/platforms/dynamicConfig.ts" import { CategoryTypeEnum } from "zhi-blog-api" import { GitlabhexoConfig } from "~/src/adaptors/api/gitlab-hexo/gitlabhexoConfig.ts" -import { GitlabHexoYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-hexo/gitlabHexoYamlConverterAdaptor.ts" +import { GitlabhexoYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-hexo/gitlabhexoYamlConverterAdaptor.ts" import { GitlabhexoApiAdaptor } from "~/src/adaptors/api/gitlab-hexo/gitlabhexoApiAdaptor.ts" const useGitlabhexoApi = async (key: string, newCfg?: GitlabhexoConfig) => { @@ -91,15 +91,15 @@ const useGitlabhexoApi = async (key: string, newCfg?: GitlabhexoConfig) => { cfg.knowledgeSpaceEnabled = true cfg.knowledgeSpaceTitle = "发布目录" cfg.allowKnowledgeSpaceChange = false - cfg.placeholder.knowledgeSpaceReadonlyModeTip = "GitlabHexo 平台暂不支持修改发布目录,如需修改,请删除之后重新发布" + cfg.placeholder.knowledgeSpaceReadonlyModeTip = "Gitlabhexo 平台暂不支持修改发布目录,如需修改,请删除之后重新发布" cfg.knowledgeSpaceType = CategoryTypeEnum.CategoryType_Tree_Single // 创建 Hexo 的 yamlAdaptor - const yamlAdaptor = new GitlabHexoYamlConverterAdaptor() + const yamlAdaptor = new GitlabhexoYamlConverterAdaptor() // 创建 Hexo API 适配器 const blogApi = new GitlabhexoApiAdaptor(appInstance, cfg) - logger.info("Gitlbhexo API created successfully.", cfg) + logger.info("Gitlabhexo API created successfully.", cfg) return { cfg, diff --git a/src/adaptors/api/gitlab-hugo/gitlabhugoApiAdaptor.ts b/src/adaptors/api/gitlab-hugo/gitlabhugoApiAdaptor.ts index fabd2bd2..c6c5d357 100644 --- a/src/adaptors/api/gitlab-hugo/gitlabhugoApiAdaptor.ts +++ b/src/adaptors/api/gitlab-hugo/gitlabhugoApiAdaptor.ts @@ -24,7 +24,7 @@ */ import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api" -import { GitlabHexoYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-hexo/gitlabHexoYamlConverterAdaptor.ts" +import { GitlabhexoYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-hexo/gitlabhexoYamlConverterAdaptor.ts" import { CommonGitlabApiAdaptor } from "~/src/adaptors/api/base/gitlab/commonGitlabApiAdaptor.ts" import _ from "lodash" @@ -37,7 +37,7 @@ import _ from "lodash" */ class GitlabhugoApiAdaptor extends CommonGitlabApiAdaptor { public override getYamlAdaptor(): YamlConvertAdaptor { - return new GitlabHexoYamlConverterAdaptor() + return new GitlabhexoYamlConverterAdaptor() } public override async preEditPost(post: Post, id?: string, publishCfg?: any): Promise { diff --git a/src/adaptors/api/gitlab-jekyll/gitlabjekyllApiAdaptor.ts b/src/adaptors/api/gitlab-jekyll/gitlabjekyllApiAdaptor.ts index c1a1c3df..db40adda 100644 --- a/src/adaptors/api/gitlab-jekyll/gitlabjekyllApiAdaptor.ts +++ b/src/adaptors/api/gitlab-jekyll/gitlabjekyllApiAdaptor.ts @@ -24,7 +24,7 @@ */ import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api" -import { GitlabHexoYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-hexo/gitlabHexoYamlConverterAdaptor.ts" +import { GitlabhexoYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-hexo/gitlabhexoYamlConverterAdaptor.ts" import { CommonGitlabApiAdaptor } from "~/src/adaptors/api/base/gitlab/commonGitlabApiAdaptor.ts" import _ from "lodash" @@ -37,7 +37,7 @@ import _ from "lodash" */ class GitlabjekyllApiAdaptor extends CommonGitlabApiAdaptor { public override getYamlAdaptor(): YamlConvertAdaptor { - return new GitlabHexoYamlConverterAdaptor() + return new GitlabhexoYamlConverterAdaptor() } public override async preEditPost(post: Post, id?: string, publishCfg?: any): Promise { diff --git a/src/adaptors/api/gitlab-vuepress/gitlabvuepressApiAdaptor.ts b/src/adaptors/api/gitlab-vuepress/gitlabvuepressApiAdaptor.ts new file mode 100644 index 00000000..87cd4216 --- /dev/null +++ b/src/adaptors/api/gitlab-vuepress/gitlabvuepressApiAdaptor.ts @@ -0,0 +1,76 @@ +/* + * 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 { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api" +import { CommonGitlabApiAdaptor } from "~/src/adaptors/api/base/gitlab/commonGitlabApiAdaptor.ts" +import _ from "lodash" +import { GitlabvuepressYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-vuepress/gitlabvuepressYamlConverterAdaptor.ts" + +/** + * Hexo API 适配器 + * + * @author terwer + * @version 1.3.2 + * @since 0.8.1 + */ +class GitlabvuepressApiAdaptor extends CommonGitlabApiAdaptor { + public override getYamlAdaptor(): YamlConvertAdaptor { + return new GitlabvuepressYamlConverterAdaptor() + } + + public override async preEditPost(post: Post, id?: string, publishCfg?: any): Promise { + // 公共的属性预处理 + const doc = await super.preEditPost(post, id, publishCfg) + + // HEXO 自带的处理 + const cfg: BlogConfig = publishCfg?.cfg + const updatedPost = _.cloneDeep(doc) as Post + + // 自定义处理 + // 成功提示、信息提示、警告提示、错误提示 + const md = updatedPost.markdown + this.logger.info("准备处理 Gitlabvuepress 正文") + this.logger.debug("md =>", { md: md }) + let updatedMd = md + + // MD暂时无法处理标记,先搁置 + // 处理MD + + updatedPost.markdown = updatedMd + this.logger.info("Gitlabvuepress 正文处理完毕") + this.logger.debug("updatedMd =>", { updatedMd: updatedMd }) + + // 发布格式 + if (cfg?.pageType == PageTypeEnum.Markdown) { + post.description = post.markdown + } else { + post.description = post.html + } + + return updatedPost + } +} + +export { GitlabvuepressApiAdaptor } diff --git a/src/adaptors/api/gitlab-vuepress/gitlabvuepressConfig.ts b/src/adaptors/api/gitlab-vuepress/gitlabvuepressConfig.ts new file mode 100644 index 00000000..9f6c0024 --- /dev/null +++ b/src/adaptors/api/gitlab-vuepress/gitlabvuepressConfig.ts @@ -0,0 +1,69 @@ +/* + * 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 { CategoryTypeEnum, PageTypeEnum, PasswordType } from "zhi-blog-api" +import { VuepressConfig } from "~/src/adaptors/api/vuepress/vuepressConfig.ts" + +/** + * Gitlabvuepress 配置 + * + * @author terwer + * @since 1.14.0 + */ +class GitlabvuepressConfig extends VuepressConfig { + constructor( + githubUsername: string, + githubAuthToken: string, + githubRepo: string, + githubBranch: string, + middlewareUrl?: string + ) { + super(githubUsername, githubAuthToken, githubRepo, githubBranch, middlewareUrl) + + this.home = "[your-gitlab-home]" + this.apiUrl = "[your-gitlab-api-url]" + this.tokenSettingUrl = "[your-gitlab-host]/-/profile/personal_access_tokens" + this.showTokenTip = true + this.defaultPath = "docs" + this.previewUrl = "/[user]/[repo]/blob/[branch]/[docpath]" + this.previewPostUrl = "/post/[postid].html" + this.mdFilenameRule = "[filename].md" + this.pageType = PageTypeEnum.Markdown + this.passwordType = PasswordType.PasswordType_Token + this.allowPreviewUrlChange = false + this.tagEnabled = true + this.cateEnabled = true + this.allowCateChange = true + this.categoryType = CategoryTypeEnum.CategoryType_Multi + this.knowledgeSpaceEnabled = true + this.allowKnowledgeSpaceChange = false + this.placeholder.knowledgeSpaceReadonlyModeTip = "Gitlabvuepress 平台暂不支持修改发布目录,如需修改,请删除之后重新发布" + this.knowledgeSpaceType = CategoryTypeEnum.CategoryType_Tree_Single + this.useMdFilename = true + this.usePathCategory = true + } +} + +export { GitlabvuepressConfig } diff --git a/src/adaptors/api/gitlab-vuepress/gitlabvuepressPlaceHolder.ts b/src/adaptors/api/gitlab-vuepress/gitlabvuepressPlaceHolder.ts new file mode 100644 index 00000000..21403e1e --- /dev/null +++ b/src/adaptors/api/gitlab-vuepress/gitlabvuepressPlaceHolder.ts @@ -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 { VuepressPlaceHolder } from "~/src/adaptors/api/vuepress/vuepressPlaceHolder.ts" + +class GitlabvuepressPlaceHolder extends VuepressPlaceHolder {} + +export { GitlabvuepressPlaceHolder } diff --git a/src/adaptors/api/gitlab-vuepress/gitlabvuepressYamlConverterAdaptor.ts b/src/adaptors/api/gitlab-vuepress/gitlabvuepressYamlConverterAdaptor.ts new file mode 100644 index 00000000..3e6485e6 --- /dev/null +++ b/src/adaptors/api/gitlab-vuepress/gitlabvuepressYamlConverterAdaptor.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022-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 { VuepressYamlConverterAdaptor } from "~/src/adaptors/api/vuepress/vuepressYamlConverterAdaptor.ts" + +/** + * Gitlabvuepress平台的YAML解析器 + * + * @author terwer + * @since 1.14.0 + */ +class GitlabvuepressYamlConverterAdaptor extends VuepressYamlConverterAdaptor {} + +export { GitlabvuepressYamlConverterAdaptor } diff --git a/src/adaptors/api/gitlab-vuepress/useGitlabvuepressApi.ts b/src/adaptors/api/gitlab-vuepress/useGitlabvuepressApi.ts new file mode 100644 index 00000000..11b8b25a --- /dev/null +++ b/src/adaptors/api/gitlab-vuepress/useGitlabvuepressApi.ts @@ -0,0 +1,112 @@ +/* + * 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 { createAppLogger } from "~/src/utils/appLogger.ts" +import { PublisherAppInstance } from "~/src/publisherAppInstance.ts" +import { useSettingStore } from "~/src/stores/useSettingStore.ts" +import { JsonUtil, ObjectUtil, StrUtil } from "zhi-common" +import { Utils } from "~/src/utils/utils.ts" +import { getDynPostidKey } from "~/src/platforms/dynamicConfig.ts" +import { CategoryTypeEnum } from "zhi-blog-api" +import { GitlabvuepressConfig } from "~/src/adaptors/api/gitlab-vuepress/gitlabvuepressConfig.ts" +import { GitlabvuepressYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-vuepress/gitlabvuepressYamlConverterAdaptor.ts" +import { GitlabvuepressApiAdaptor } from "~/src/adaptors/api/gitlab-vuepress/gitlabvuepressApiAdaptor.ts" + +const useGitlabvuepressApi = async (key: string, newCfg?: GitlabvuepressConfig) => { + // 创建应用日志记录器 + const logger = createAppLogger("use-gitlab-hexo-api") + + // 记录开始使用 Hexo API + logger.info("Start using Gitlabvuepress API...") + + // 创建应用实例 + const appInstance = new PublisherAppInstance() + + let cfg: GitlabvuepressConfig + if (newCfg) { + logger.info("Initialize with the latest newCfg passed in...") + cfg = newCfg + } else { + // 从配置中获取数据 + const { getSetting } = useSettingStore() + const setting = await getSetting() + cfg = JsonUtil.safeParse(setting[key], {} as GitlabvuepressConfig) + + // 如果配置为空,则使用默认的环境变量值,并记录日志 + if (ObjectUtil.isEmptyObject(cfg)) { + // 从环境变量获取 Hexo API 的 URL、认证令牌和其他配置信息 + const githubUsername = Utils.emptyOrDefault(process.env.VITE_GITLAB_USERNAME, "") + const githubAuthToken = Utils.emptyOrDefault(process.env.VITE_GITLAB_AUTH_TOKEN, "") + const githubRepo = Utils.emptyOrDefault(process.env.VITE_GITLAB_REPO, "") + const githubBranch = Utils.emptyOrDefault(process.env.VITE_GITLAB_BRANCH, "main") + const middlewareUrl = Utils.emptyOrDefault( + process.env.VITE_MIDDLEWARE_URL, + "https://api.terwer.space/api/middleware" + ) + cfg = new GitlabvuepressConfig(githubUsername, githubAuthToken, githubRepo, githubBranch, middlewareUrl) + logger.info("Configuration is empty, using default environment variables.") + } else { + logger.info("Using configuration from settings...") + } + // 初始化posidKey + if (StrUtil.isEmptyString(cfg.posidKey)) { + // 默认值 + cfg.posidKey = getDynPostidKey(key) + } + } + + // 文件规则 + cfg.mdFilenameRule = "[filename].md" + cfg.useMdFilename = true + cfg.usePathCategory = true + // 标签 + cfg.tagEnabled = true + // 分类 + cfg.cateEnabled = true + cfg.allowCateChange = true + cfg.categoryType = CategoryTypeEnum.CategoryType_Multi + // 知识空间 + cfg.knowledgeSpaceEnabled = true + cfg.knowledgeSpaceTitle = "发布目录" + cfg.allowKnowledgeSpaceChange = false + cfg.placeholder.knowledgeSpaceReadonlyModeTip = + "Gitlabvuepress 平台暂不支持修改发布目录,如需修改,请删除之后重新发布" + cfg.knowledgeSpaceType = CategoryTypeEnum.CategoryType_Tree_Single + + // 创建 Hexo 的 yamlAdaptor + const yamlAdaptor = new GitlabvuepressYamlConverterAdaptor() + + // 创建 Hexo API 适配器 + const blogApi = new GitlabvuepressApiAdaptor(appInstance, cfg) + logger.info("Gitlabvuepress API created successfully.", cfg) + + return { + cfg, + yamlAdaptor, + blogApi, + } +} + +export { useGitlabvuepressApi } diff --git a/src/adaptors/api/vuepress/useVuepressApi.ts b/src/adaptors/api/vuepress/useVuepressApi.ts new file mode 100644 index 00000000..c564995c --- /dev/null +++ b/src/adaptors/api/vuepress/useVuepressApi.ts @@ -0,0 +1,111 @@ +/* + * 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 { createAppLogger } from "~/src/utils/appLogger.ts" +import { PublisherAppInstance } from "~/src/publisherAppInstance.ts" +import { useSettingStore } from "~/src/stores/useSettingStore.ts" +import { JsonUtil, ObjectUtil, StrUtil } from "zhi-common" +import { Utils } from "~/src/utils/utils.ts" +import { getDynPostidKey } from "~/src/platforms/dynamicConfig.ts" +import { CategoryTypeEnum } from "zhi-blog-api" +import { VuepressConfig } from "~/src/adaptors/api/vuepress/vuepressConfig.ts" +import { VuepressYamlConverterAdaptor } from "~/src/adaptors/api/vuepress/vuepressYamlConverterAdaptor.ts" +import { VuepressApiAdaptor } from "~/src/adaptors/api/vuepress/vuepressApiAdaptor.ts" + +const useVuepressApi = async (key: string, newCfg?: VuepressConfig) => { + // 创建应用日志记录器 + const logger = createAppLogger("use-vuepress-api") + + // 记录开始使用 Vuepress API + logger.info("Start using Vuepress API...") + + // 创建应用实例 + const appInstance = new PublisherAppInstance() + + let cfg: VuepressConfig + if (newCfg) { + logger.info("Initialize with the latest newCfg passed in...") + cfg = newCfg + } else { + // 从配置中获取数据 + const { getSetting } = useSettingStore() + const setting = await getSetting() + cfg = JsonUtil.safeParse(setting[key], {} as VuepressConfig) + + // 如果配置为空,则使用默认的环境变量值,并记录日志 + if (ObjectUtil.isEmptyObject(cfg)) { + // 从环境变量获取 Vuepress API 的 URL、认证令牌和其他配置信息 + const githubUsername = Utils.emptyOrDefault(process.env.VITE_GITHUB_USERNAME, "") + const githubAuthToken = Utils.emptyOrDefault(process.env.VITE_GITHUB_AUTH_TOKEN, "") + const githubRepo = Utils.emptyOrDefault(process.env.VITE_GITHUB_REPO, "") + const githubBranch = Utils.emptyOrDefault(process.env.VITE_GITHUB_BRANCH, "main") + const middlewareUrl = Utils.emptyOrDefault( + process.env.VITE_MIDDLEWARE_URL, + "https://api.terwer.space/api/middleware" + ) + cfg = new VuepressConfig(githubUsername, githubAuthToken, githubRepo, githubBranch, middlewareUrl) + logger.info("Configuration is empty, using default environment variables.") + } else { + logger.info("Using configuration from settings...") + } + // 初始化posidKey + if (StrUtil.isEmptyString(cfg.posidKey)) { + // 默认值 + cfg.posidKey = getDynPostidKey(key) + } + } + + // 文件规则,占位符 + cfg.mdFilenameRule = "[filename].md" + cfg.useMdFilename = true + cfg.usePathCategory = true + // 标签 + cfg.tagEnabled = true + // 分类 + cfg.cateEnabled = true + cfg.allowCateChange = true + cfg.categoryType = CategoryTypeEnum.CategoryType_Multi + // 知识空间 + cfg.knowledgeSpaceEnabled = true + cfg.knowledgeSpaceTitle = "发布目录" + cfg.allowKnowledgeSpaceChange = false + cfg.placeholder.knowledgeSpaceReadonlyModeTip = "Vuepress 平台暂不支持修改发布目录,如需修改,请删除之后重新发布" + cfg.knowledgeSpaceType = CategoryTypeEnum.CategoryType_Tree_Single + + // 创建 Vuepress 的 yamlAdaptor + const yamlAdaptor = new VuepressYamlConverterAdaptor() + + // 创建 Vuepress API 适配器 + const blogApi = new VuepressApiAdaptor(appInstance, cfg) + logger.info("Vuepress API created successfully.", cfg) + + return { + cfg, + yamlAdaptor, + blogApi, + } +} + +export { useVuepressApi } diff --git a/src/adaptors/api/vuepress/vuepressApiAdaptor.ts b/src/adaptors/api/vuepress/vuepressApiAdaptor.ts new file mode 100644 index 00000000..6e1bc6da --- /dev/null +++ b/src/adaptors/api/vuepress/vuepressApiAdaptor.ts @@ -0,0 +1,73 @@ +/* + * 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 { CommonGithubApiAdaptor } from "~/src/adaptors/api/base/github/commonGithubApiAdaptor.ts" +import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api" +import _ from "lodash" +import { VuepressYamlConverterAdaptor } from "~/src/adaptors/api/vuepress/vuepressYamlConverterAdaptor.ts" + +/** + * Vuepress API 适配器 + * + * @author terwer + * @version 1.14.0 + * @since 1.14.0 + */ +class VuepressApiAdaptor extends CommonGithubApiAdaptor { + public override getYamlAdaptor(): YamlConvertAdaptor { + return new VuepressYamlConverterAdaptor() + } + + public override async preEditPost(post: Post, id?: string, publishCfg?: any): Promise { + // 公共的属性预处理 + const doc = await super.preEditPost(post, id, publishCfg) + + // HEXO 自带的处理 + const cfg: BlogConfig = publishCfg?.cfg + const updatedPost = _.cloneDeep(doc) as Post + + // 自定义处理 + // 信息、警告、错误 + const md = updatedPost.markdown + this.logger.info("准备处理 Vuepress 正文") + this.logger.debug("md =>", { md: md }) + let updatedMd = md + // MD暂时无法处理标记,先搁置 + // 处理MD + updatedPost.markdown = updatedMd + this.logger.info("Vuepress 正文处理完毕") + this.logger.debug("updatedMd =>", { updatedMd: updatedMd }) + + // 发布格式 + if (cfg?.pageType == PageTypeEnum.Markdown) { + post.description = post.markdown + } else { + post.description = post.html + } + return updatedPost + } +} + +export { VuepressApiAdaptor } diff --git a/src/adaptors/api/vuepress/vuepressConfig.ts b/src/adaptors/api/vuepress/vuepressConfig.ts new file mode 100644 index 00000000..c21aba7b --- /dev/null +++ b/src/adaptors/api/vuepress/vuepressConfig.ts @@ -0,0 +1,67 @@ +/* + * 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 { CommonGithubConfig } from "~/src/adaptors/api/base/github/commonGithubConfig.ts" +import { CategoryTypeEnum, PageTypeEnum, PasswordType } from "zhi-blog-api" + +/** + * Vuepress 配置 + * + * @author terwer + * @since 1.14.0 + */ +class VuepressConfig extends CommonGithubConfig { + constructor( + githubUsername: string, + githubAuthToken: string, + githubRepo: string, + githubBranch: string, + middlewareUrl?: string + ) { + super(githubUsername, githubAuthToken, githubRepo, githubBranch, middlewareUrl) + + this.tokenSettingUrl = "https://github.com/settings/tokens" + this.showTokenTip = true + this.defaultPath = "docs" + this.previewUrl = "/[user]/[repo]/blob/[branch]/[docpath]" + this.previewPostUrl = "/post/[postid].html" + this.mdFilenameRule = "[filename].md" + this.pageType = PageTypeEnum.Markdown + this.passwordType = PasswordType.PasswordType_Token + this.allowPreviewUrlChange = false + this.tagEnabled = true + this.cateEnabled = true + this.allowCateChange = true + this.categoryType = CategoryTypeEnum.CategoryType_Multi + this.knowledgeSpaceEnabled = true + this.allowKnowledgeSpaceChange = false + this.placeholder.knowledgeSpaceReadonlyModeTip = "Vuepress 平台暂不支持修改发布目录,如需修改,请删除之后重新发布" + this.knowledgeSpaceType = CategoryTypeEnum.CategoryType_Tree_Single + this.useMdFilename = true + this.usePathCategory = true + } +} + +export { VuepressConfig } diff --git a/src/adaptors/api/vuepress/vuepressPlaceHolder.ts b/src/adaptors/api/vuepress/vuepressPlaceHolder.ts new file mode 100644 index 00000000..ca8dd4f6 --- /dev/null +++ b/src/adaptors/api/vuepress/vuepressPlaceHolder.ts @@ -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 { CommonGithubPlaceholder } from "~/src/adaptors/api/base/github/commonGithubPlaceholder.ts" + +class VuepressPlaceHolder extends CommonGithubPlaceholder {} + +export { VuepressPlaceHolder } diff --git a/src/adaptors/api/vuepress/vuepressYamlConverterAdaptor.ts b/src/adaptors/api/vuepress/vuepressYamlConverterAdaptor.ts new file mode 100644 index 00000000..8d62387f --- /dev/null +++ b/src/adaptors/api/vuepress/vuepressYamlConverterAdaptor.ts @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2022-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 { createAppLogger } from "~/src/utils/appLogger.ts" +import { BlogConfig, Post, YamlConvertAdaptor, YamlFormatObj } from "zhi-blog-api" +import { DateUtil, StrUtil, YamlUtil } from "zhi-common" +import { CommonGithubConfig } from "~/src/adaptors/api/base/github/commonGithubConfig.ts" +import { toRaw } from "vue" + +/** + * Vuepress平台的YAML解析器 + * + * @see {https://doc.xugaoyi.com/pages/3216b0/ front-tmatter} + * @author terwer + * @since 0.8.1 + */ +class VuepressYamlConverterAdaptor extends YamlConvertAdaptor { + private readonly logger = createAppLogger("vuepress-yaml-converter-adaptor") + + public convertToYaml(post: Post, cfg?: BlogConfig): YamlFormatObj { + this.logger.debug("您正在使用 Vuepress Yaml Converter", { post: toRaw(post) }) + let yamlFormatObj: YamlFormatObj = new YamlFormatObj() + // title + yamlFormatObj.yamlObj.title = post.title + + // date + yamlFormatObj.yamlObj.date = DateUtil.formatIsoToZh(post.dateCreated.toISOString(), true) + + // updated + if (!post.dateUpdated) { + post.dateUpdated = new Date() + } + yamlFormatObj.yamlObj.updated = DateUtil.formatIsoToZh(post.dateUpdated.toISOString(), true) + + // excerpt + if (!StrUtil.isEmptyString(post.shortDesc)) { + yamlFormatObj.yamlObj.excerpt = post.shortDesc + } + + // tags + if (!StrUtil.isEmptyString(post.mt_keywords)) { + const tags = post.mt_keywords.split(",") + yamlFormatObj.yamlObj.tags = tags + } + + // categories + if (post.categories?.length > 0) { + yamlFormatObj.yamlObj.categories = post.categories + } + + // permalink + if (cfg.yamlLinkEnabled) { + let link = "/post/" + post.wp_slug + ".html" + if (cfg instanceof CommonGithubConfig) { + const githubCfg = cfg as CommonGithubConfig + if (!StrUtil.isEmptyString(cfg.previewPostUrl)) { + link = githubCfg.previewPostUrl.replace("[postid]", post.wp_slug) + const created = DateUtil.formatIsoToZh(post.dateCreated.toISOString(), true) + const datearr = created.split(" ")[0] + const numarr = datearr.split("-") + this.logger.debug("created numarr=>", numarr) + const y = numarr[0] + const m = numarr[1] + const d = numarr[2] + link = link.replace(/\[yyyy]/g, y) + link = link.replace(/\[MM]/g, m) + link = link.replace(/\[mm]/g, m) + link = link.replace(/\[dd]/g, d) + + if (yamlFormatObj.yamlObj.categories?.length > 0) { + link = link.replace(/\[cats]/, yamlFormatObj.yamlObj.categories.join("/")) + } else { + link = link.replace(/\/\[cats]/, "") + } + } + } + yamlFormatObj.yamlObj.permalink = link + } + + // comments + yamlFormatObj.yamlObj.comments = true + + // toc + yamlFormatObj.yamlObj.toc = true + + // formatter + let yaml = YamlUtil.obj2Yaml(yamlFormatObj.yamlObj) + this.logger.debug("yaml=>", yaml) + + yamlFormatObj.formatter = yaml + yamlFormatObj.mdContent = post.markdown + yamlFormatObj.mdFullContent = YamlUtil.addYamlToMd(yamlFormatObj.formatter, yamlFormatObj.mdContent) + yamlFormatObj.htmlContent = post.html + this.logger.info("生成默认的YAML") + + return yamlFormatObj + } + + public convertToAttr(post: Post, yamlFormatObj: YamlFormatObj, cfg?: BlogConfig): Post { + this.logger.debug("开始转换YAML到Post", yamlFormatObj) + + // 标题 + if (yamlFormatObj.yamlObj?.title) { + post.title = yamlFormatObj.yamlObj?.title + } + + // 发布时间 + if (yamlFormatObj.yamlObj?.date) { + post.dateCreated = DateUtil.convertStringToDate(yamlFormatObj.yamlObj?.date) + } + if (yamlFormatObj.yamlObj?.updated) { + post.dateUpdated = DateUtil.convertStringToDate(yamlFormatObj.yamlObj?.updated) + } + + // 摘要 + post.shortDesc = yamlFormatObj.yamlObj?.excerpt + + // 标签 + post.mt_keywords = yamlFormatObj.yamlObj?.tags?.join(",") + + // 分类 + post.categories = yamlFormatObj.yamlObj?.categories + + // 添加新的YAML + post.yaml = YamlUtil.obj2Yaml(yamlFormatObj.yamlObj) + + this.logger.debug("转换完成,post =>", post) + return post + } +} + +export { VuepressYamlConverterAdaptor } diff --git a/src/adaptors/base/baseExtendApi.ts b/src/adaptors/base/baseExtendApi.ts index 032e0f63..b84b6e28 100644 --- a/src/adaptors/base/baseExtendApi.ts +++ b/src/adaptors/base/baseExtendApi.ts @@ -27,7 +27,16 @@ import { IBlogApi } from "zhi-blog-api/dist/lib/IBlogApi" import { IWebApi } from "zhi-blog-api/dist/lib/IWebApi" import { BaseBlogApi } from "~/src/adaptors/api/base/baseBlogApi.ts" import { BaseWebApi } from "~/src/adaptors/web/base/baseWebApi.ts" -import { BlogConfig, MediaObject, PageTypeEnum, Post, WebApi, YamlConvertAdaptor, YamlFormatObj } from "zhi-blog-api" +import { + BlogConfig, + MediaObject, + PageTypeEnum, + Post, + PostUtil, + WebApi, + YamlConvertAdaptor, + YamlFormatObj, +} from "zhi-blog-api" import { createAppLogger, ILogger } from "~/src/utils/appLogger.ts" import { LuteUtil } from "~/src/utils/luteUtil.ts" import { usePicgoBridge } from "~/src/composables/usePicgoBridge.ts" @@ -41,6 +50,7 @@ import { DynamicConfig } from "~/src/platforms/dynamicConfig.ts" import { MUST_USE_OWN_PLATFORM, MUST_USE_PICBED_PLATFORM } from "~/src/utils/constants.ts" import { toRaw } from "vue" import _ from "lodash" +import { usePublishPreferenceSetting } from "~/src/stores/usePublishPreferenceSetting.ts" /** * 各种模式共享的扩展基类 @@ -86,7 +96,7 @@ class BaseExtendApi extends WebApi implements IBlogApi, IWebApi { // 处理摘要 post = await this.handleDesc(post, id, publishCfg) // 处理路径分类 - post = await this.handleCtegories(post, id, publishCfg) + post = await this.handleCategories(post, id, publishCfg) // 处理图片 post = await this.handlePictures(post, id, publishCfg) // 处理Md @@ -136,6 +146,11 @@ class BaseExtendApi extends WebApi implements IBlogApi, IWebApi { .replace(/\[mm\]/g, m) .replace(/\[dd\]/g, d) post.mdFilename = filename + const { getReadOnlyPublishPreferenceSetting } = usePublishPreferenceSetting() + const pref = getReadOnlyPublishPreferenceSetting() + if (pref.value.fixTitle) { + post.title = HtmlUtil.removeTitleNumber(post.title) + } this.logger.debug("处理MD文件名完成,post", { post: toRaw(post) }) return post @@ -167,7 +182,7 @@ class BaseExtendApi extends WebApi implements IBlogApi, IWebApi { * @param publishCfg - (可选)发布配置参数 * @returns 一个 Promise,解析为处理后的 Post 对象 */ - private async handleCtegories(doc: Post, id?: string, publishCfg?: any) { + private async handleCategories(doc: Post, id?: string, publishCfg?: any) { const cfg: BlogConfig = publishCfg?.cfg const post = _.cloneDeep(doc) as Post @@ -176,7 +191,7 @@ class BaseExtendApi extends WebApi implements IBlogApi, IWebApi { if (cfg.usePathCategory) { const docPathArray = savePath.split("/") if (docPathArray.length > 1) { - for (let i = 1; i < docPathArray.length - 1; i++) { + for (let i = 1; i < docPathArray.length; i++) { const docCate = HtmlUtil.removeTitleNumber(docPathArray[i]) pathCates.push(docCate) } @@ -185,12 +200,12 @@ class BaseExtendApi extends WebApi implements IBlogApi, IWebApi { // 目录分类 this.logger.info("目录路径转换的分类 =>", pathCates) - const mergedCategories = [...new Set(...(pathCates ?? []), [...(post?.categories ?? [])])].filter( - (cate: string) => cate.trim() !== "" - ) as string[] + const mergedCategories = [...new Set([...(pathCates ?? []), ...(post?.categories ?? [])])].filter( + (cate) => cate.trim() !== "" + ) post.categories = mergedCategories this.logger.info("最终的分类 =>", post.categories) - + this.logger.debug("目录路径转换完成,post", { post: toRaw(post) }) return post } @@ -259,37 +274,37 @@ class BaseExtendApi extends WebApi implements IBlogApi, IWebApi { this.logger.debug("开始处理yaml,post", { post: toRaw(post) }) - // 前台已经处理好,这里无需再处理 - // const yamlAdaptor: YamlConvertAdaptor = this.api.getYamlAdaptor() - // if (null !== yamlAdaptor) { - // // 先生成对应平台的yaml - // const yamlObj: YamlFormatObj = yamlAdaptor.convertToYaml(post, cfg) - // // 同步发布内容 - // post.yaml = yamlObj.formatter - // post.markdown = yamlObj.mdFullContent - // post.html = yamlObj.htmlContent - // this.logger.info("handled yaml using YamlConverterAdaptor") - // } else { - // // 同步发布内容 - // const yamlObj = post.toYamlObj() - // const yaml = YamlUtil.obj2Yaml(yamlObj) - // const md = YamlUtil.extractMarkdown(post.markdown) - // post.yaml = yaml - // post.markdown = md - // post.html = LuteUtil.mdToHtml(md) - // this.logger.info("yaml adaptor not found, using default") - // } - + // 前面改过属性,需要再生成一次 const yamlAdaptor: YamlConvertAdaptor = this.api.getYamlAdaptor() if (null !== yamlAdaptor) { - const md = YamlUtil.extractMarkdown(post.markdown) - const yaml = post.yaml - post.markdown = YamlUtil.addYamlToMd(yaml, md) - this.logger.info("检测到该平台已开启YAML适配器,已附加YAML到Markdown正文") + // 先生成对应平台的yaml + const yamlObj: YamlFormatObj = yamlAdaptor.convertToYaml(post, cfg) + // 同步发布内容 + post.yaml = yamlObj.formatter + post.markdown = yamlObj.mdFullContent + post.html = yamlObj.htmlContent + this.logger.info("rehandled yaml using YamlConverterAdaptor") } else { - this.logger.info("未找到YAML适配器,不作处理") + // 同步发布内容 + const yamlObj = PostUtil.toYamlObj(post) + const yaml = YamlUtil.obj2Yaml(yamlObj) + const md = YamlUtil.extractMarkdown(post.markdown) + post.yaml = yaml + post.markdown = md + post.html = LuteUtil.mdToHtml(md) + this.logger.info("yaml adaptor not found, using default") } + // YAML与MD的处理,旧的逻辑,不考虑属性变更的情况 + // if (null !== yamlAdaptor) { + // const md = YamlUtil.extractMarkdown(post.markdown) + // const yaml = post.yaml + // post.markdown = YamlUtil.addYamlToMd(yaml, md) + // this.logger.info("检测到该平台已开启YAML适配器,已附加YAML到Markdown正文") + // } else { + // this.logger.info("未找到YAML适配器,不作处理") + // } + this.logger.debug("yaml处理之后,post", { post: toRaw(post) }) return post } diff --git a/src/adaptors/index.ts b/src/adaptors/index.ts index 1d68aa97..a0eecd58 100644 --- a/src/adaptors/index.ts +++ b/src/adaptors/index.ts @@ -44,6 +44,8 @@ import { useHugoApi } from "~/src/adaptors/api/hugo/useHugoApi.ts" import { useGitlabhugoApi } from "~/src/adaptors/api/gitlab-hugo/useGitlabhugoApi.ts" import { useJekyllApi } from "~/src/adaptors/api/jekyll/useJekyllApi.ts" import { useGitlabjekyllApi } from "~/src/adaptors/api/gitlab-jekyll/useGitlabjekyllApi.ts" +import { useVuepressApi } from "~/src/adaptors/api/vuepress/useVuepressApi.ts" +import { useGitlabvuepressApi } from "~/src/adaptors/api/gitlab-vuepress/useGitlabvuepressApi.ts" /** * 适配器统一入口 @@ -90,6 +92,11 @@ class Adaptors { conf = cfg break } + case SubPlatformType.Github_Vuepress: { + const { cfg } = await useVuepressApi(key, newCfg) + conf = cfg + break + } case SubPlatformType.Gitlab_Hexo: { const { cfg } = await useGitlabhexoApi(key, newCfg) conf = cfg @@ -105,6 +112,11 @@ class Adaptors { conf = cfg break } + case SubPlatformType.Gitlab_Vuepress: { + const { cfg } = await useGitlabvuepressApi(key, newCfg) + conf = cfg + break + } case SubPlatformType.Metaweblog_Metaweblog: { const { cfg } = await useMetaweblogApi(key, newCfg) conf = cfg @@ -200,6 +212,11 @@ class Adaptors { blogAdaptor = blogApi break } + case SubPlatformType.Github_Vuepress: { + const { blogApi } = await useVuepressApi(key, newCfg) + blogAdaptor = blogApi + break + } case SubPlatformType.Gitlab_Hexo: { const { blogApi } = await useGitlabhexoApi(key, newCfg) blogAdaptor = blogApi @@ -215,6 +232,11 @@ class Adaptors { blogAdaptor = blogApi break } + case SubPlatformType.Gitlab_Vuepress: { + const { blogApi } = await useGitlabvuepressApi(key, newCfg) + blogAdaptor = blogApi + break + } case SubPlatformType.Metaweblog_Metaweblog: { const { blogApi } = await useMetaweblogApi(key, newCfg) blogAdaptor = blogApi @@ -299,6 +321,11 @@ class Adaptors { yamlAdp = yamlAdaptor break } + case SubPlatformType.Github_Vuepress: { + const { yamlAdaptor } = await useVuepressApi(key, newCfg) + yamlAdp = yamlAdaptor + break + } case SubPlatformType.Gitlab_Hexo: { const { yamlAdaptor } = await useGitlabhexoApi(key, newCfg) yamlAdp = yamlAdaptor @@ -314,6 +341,11 @@ class Adaptors { yamlAdp = yamlAdaptor break } + case SubPlatformType.Gitlab_Vuepress: { + const { yamlAdaptor } = await useGitlabvuepressApi(key, newCfg) + yamlAdp = yamlAdaptor + break + } default: { break } diff --git a/src/components/set/publish/singleplatform/SingleSettingIndex.vue b/src/components/set/publish/singleplatform/SingleSettingIndex.vue index 6ce68344..a9f0fba9 100644 --- a/src/components/set/publish/singleplatform/SingleSettingIndex.vue +++ b/src/components/set/publish/singleplatform/SingleSettingIndex.vue @@ -29,6 +29,8 @@ import { reactive } from "vue" import { useRoute } from "vue-router" import { useVueI18n } from "~/src/composables/useVueI18n.ts" import { getSubPlatformTypeByKey, SubPlatformType } from "~/src/platforms/dynamicConfig.ts" +import VuepressSetting from "~/src/components/set/publish/singleplatform/github/VuepressSetting.vue" +import GitlabvuepressSetting from "~/src/components/set/publish/singleplatform/gitlab/GitlabvuepressSetting.vue" // uses const { t } = useVueI18n() @@ -47,9 +49,11 @@ const subtype = getSubPlatformTypeByKey(apiType) + + diff --git a/src/components/set/publish/singleplatform/github/VuepressSetting.vue b/src/components/set/publish/singleplatform/github/VuepressSetting.vue new file mode 100644 index 00000000..de619a3f --- /dev/null +++ b/src/components/set/publish/singleplatform/github/VuepressSetting.vue @@ -0,0 +1,57 @@ + + + + + diff --git a/src/components/set/publish/singleplatform/gitlab/GitlabvuepressSetting.vue b/src/components/set/publish/singleplatform/gitlab/GitlabvuepressSetting.vue new file mode 100644 index 00000000..3c03b84c --- /dev/null +++ b/src/components/set/publish/singleplatform/gitlab/GitlabvuepressSetting.vue @@ -0,0 +1,68 @@ + + + + +