Skip to content

Commit

Permalink
feat: 全面支持Github和Gitlab各平台-Vuepress
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Sep 11, 2023
1 parent e9d38d4 commit b9d1829
Show file tree
Hide file tree
Showing 20 changed files with 981 additions and 47 deletions.
6 changes: 3 additions & 3 deletions src/adaptors/api/gitlab-hexo/gitlabhexoApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@
*/

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
* @since 0.8.1
*/
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<Post> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
8 changes: 4 additions & 4 deletions src/adaptors/api/gitlab-hexo/useGitlabhexoApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/adaptors/api/gitlab-hugo/gitlabhugoApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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<Post> {
Expand Down
4 changes: 2 additions & 2 deletions src/adaptors/api/gitlab-jekyll/gitlabjekyllApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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<Post> {
Expand Down
76 changes: 76 additions & 0 deletions src/adaptors/api/gitlab-vuepress/gitlabvuepressApiAdaptor.ts
Original file line number Diff line number Diff line change
@@ -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, [email protected]
* 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<Post> {
// 公共的属性预处理
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 }
69 changes: 69 additions & 0 deletions src/adaptors/api/gitlab-vuepress/gitlabvuepressConfig.ts
Original file line number Diff line number Diff line change
@@ -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, [email protected]
* 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 }
30 changes: 30 additions & 0 deletions src/adaptors/api/gitlab-vuepress/gitlabvuepressPlaceHolder.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, [email protected]
* 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 }
Original file line number Diff line number Diff line change
@@ -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, [email protected]
* 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 }
Loading

0 comments on commit b9d1829

Please sign in to comment.