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 13, 2023
1 parent b9d1829 commit 4bf1cee
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 114 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Publish articles from siyuan-note to platforms such as Yuque, Notion, Cnblogs, W

Support features such as fast publishing, image bed management, platform expansion, smart labels, etc.

- 🎉 To celebrate the birth of my little angel, I am pleased to announce the release of version `1.14.0` of Publish Tool.
- 🎉 I am pleased to announce the `1.14.0` release of Publish Tool.

- In this update, we have added several new platforms, including JianShu, Juejin, as well as Hugo, Jekyll, Vuepress, Vuepress2, and Vitepress. The latter platforms are also compatible with both `Github` and `Gitlab`.

Expand Down
2 changes: 1 addition & 1 deletion README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

将思源笔记的文章发布到语雀、Notion、Cnblogs、WordPress、Typecho、Hexo、知乎 等平台,支持极速发布、图床管理、平台扩展、智能标签等特色功能。

> 🎉 为庆祝小天使出生,发布工具新版本 `1.14.0` 发布
> 🎉 发布工具新版本 `1.14.0` 发布
>
> 本次更新新增多个平台,包括简书、掘金以及 Hugo、Jekyll、Vuepress、Vuepress2、Vitepress,后面几个平台同时兼容 `Github``Gitlab`
>
Expand Down
1 change: 1 addition & 0 deletions src/adaptors/api/base/github/commonGithubApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class CommonGithubApiAdaptor extends BaseBlogApi {

let commonPost = new Post()
commonPost.postid = res.path
commonPost.mdFilename = res.name
commonPost.markdown = Base64.fromBase64(res.content)
commonPost.description = commonPost.markdown

Expand Down
2 changes: 2 additions & 0 deletions src/adaptors/api/base/gitlab/commonGitlabApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class CommonGitlabApiAdaptor extends BaseBlogApi {

let commonPost = new Post()
commonPost.postid = res.file_path
// 文件标题
commonPost.mdFilename = res.file_name
commonPost.markdown = Base64.fromBase64(res.content)
commonPost.description = commonPost.markdown

Expand Down
18 changes: 10 additions & 8 deletions src/adaptors/api/gitlab-hexo/gitlabhexoApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api
import { GitlabhexoYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-hexo/gitlabhexoYamlConverterAdaptor.ts"
import { CommonGitlabApiAdaptor } from "~/src/adaptors/api/base/gitlab/commonGitlabApiAdaptor.ts"
import _ from "lodash"
import {YamlUtil} from "zhi-common";

/**
* Gitlabhexo API 适配器
Expand All @@ -49,24 +50,25 @@ class GitlabhexoApiAdaptor extends CommonGitlabApiAdaptor {
const updatedPost = _.cloneDeep(doc) as Post

// 自定义处理
// 成功提示、信息提示、警告提示、错误提示
const md = updatedPost.markdown
this.logger.info("准备处理 Gitlabhexo 正文")
this.logger.debug("md =>", { md: md })
let updatedMd = md
const yfm = YamlUtil.extractFrontmatter(md, true)
let updatedMd = YamlUtil.extractMarkdown(md)

// MD暂时无法处理标记,先搁置
// 处理MD
// ======
// 可修改 updatedMd
// ======

updatedPost.markdown = updatedMd
updatedPost.markdown = `${yfm}\n${updatedMd}`
this.logger.info("Gitlabhexo 正文处理完毕")
this.logger.debug("updatedMd =>", { updatedMd: updatedMd })
this.logger.debug("updatedMd =>", { yfm: yfm, updatedMd: updatedMd })

// 发布格式
if (cfg?.pageType == PageTypeEnum.Markdown) {
post.description = post.markdown
updatedPost.description = updatedPost.markdown
} else {
post.description = post.html
updatedPost.description = updatedPost.html
}

return updatedPost
Expand Down
26 changes: 14 additions & 12 deletions src/adaptors/api/gitlab-hugo/gitlabhugoApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
*/

import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import { GitlabhexoYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-hexo/gitlabhexoYamlConverterAdaptor.ts"
import { CommonGitlabApiAdaptor } from "~/src/adaptors/api/base/gitlab/commonGitlabApiAdaptor.ts"
import _ from "lodash"
import { GitlabhugoYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-hugo/gitlabhugoYamlConverterAdaptor.ts"
import { YamlUtil } from "zhi-common"

/**
* Hugo API 适配器
Expand All @@ -37,7 +38,7 @@ import _ from "lodash"
*/
class GitlabhugoApiAdaptor extends CommonGitlabApiAdaptor {
public override getYamlAdaptor(): YamlConvertAdaptor {
return new GitlabhexoYamlConverterAdaptor()
return new GitlabhugoYamlConverterAdaptor()
}

public override async preEditPost(post: Post, id?: string, publishCfg?: any): Promise<Post> {
Expand All @@ -49,24 +50,25 @@ class GitlabhugoApiAdaptor extends CommonGitlabApiAdaptor {
const updatedPost = _.cloneDeep(doc) as Post

// 自定义处理
// 成功提示、信息提示、警告提示、错误提示
const md = updatedPost.markdown
this.logger.info("准备处理 Gitlabhexo 正文")
this.logger.info("准备处理 Gitlabhugo 正文")
this.logger.debug("md =>", { md: md })
let updatedMd = md
const yfm = YamlUtil.extractFrontmatter(md, true)
let updatedMd = YamlUtil.extractMarkdown(md)

// MD暂时无法处理标记,先搁置
// 处理MD
// ======
// 可修改 updatedMd
// ======

updatedPost.markdown = updatedMd
this.logger.info("Gitlabhexo 正文处理完毕")
this.logger.debug("updatedMd =>", { updatedMd: updatedMd })
updatedPost.markdown = `${yfm}\n${updatedMd}`
this.logger.info("Gitlabhugo 正文处理完毕")
this.logger.debug("updatedMd =>", { yfm: yfm, updatedMd: updatedMd })

// 发布格式
if (cfg?.pageType == PageTypeEnum.Markdown) {
post.description = post.markdown
updatedPost.description = updatedPost.markdown
} else {
post.description = post.html
updatedPost.description = updatedPost.html
}

return updatedPost
Expand Down
22 changes: 12 additions & 10 deletions src/adaptors/api/gitlab-jekyll/gitlabjekyllApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
*/

import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import { GitlabhexoYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-hexo/gitlabhexoYamlConverterAdaptor.ts"
import { CommonGitlabApiAdaptor } from "~/src/adaptors/api/base/gitlab/commonGitlabApiAdaptor.ts"
import _ from "lodash"
import { GitlabjekyllYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-jekyll/gitlabjekyllYamlConverterAdaptor.ts"
import { YamlUtil } from "zhi-common"

/**
* Jekyll API 适配器
Expand All @@ -37,7 +38,7 @@ import _ from "lodash"
*/
class GitlabjekyllApiAdaptor extends CommonGitlabApiAdaptor {
public override getYamlAdaptor(): YamlConvertAdaptor {
return new GitlabhexoYamlConverterAdaptor()
return new GitlabjekyllYamlConverterAdaptor()
}

public override async preEditPost(post: Post, id?: string, publishCfg?: any): Promise<Post> {
Expand All @@ -49,24 +50,25 @@ class GitlabjekyllApiAdaptor extends CommonGitlabApiAdaptor {
const updatedPost = _.cloneDeep(doc) as Post

// 自定义处理
// 成功提示、信息提示、警告提示、错误提示
const md = updatedPost.markdown
this.logger.info("准备处理 Gitlabjekyll 正文")
this.logger.debug("md =>", { md: md })
let updatedMd = md
const yfm = YamlUtil.extractFrontmatter(md, true)
let updatedMd = YamlUtil.extractMarkdown(md)

// MD暂时无法处理标记,先搁置
// 处理MD
// ======
// 可修改 updatedMd
// ======

updatedPost.markdown = updatedMd
updatedPost.markdown = `${yfm}\n${updatedMd}`
this.logger.info("Gitlabjekyll 正文处理完毕")
this.logger.debug("updatedMd =>", { updatedMd: updatedMd })
this.logger.debug("updatedMd =>", { yfm: yfm, updatedMd: updatedMd })

// 发布格式
if (cfg?.pageType == PageTypeEnum.Markdown) {
post.description = post.markdown
updatedPost.description = updatedPost.markdown
} else {
post.description = post.html
updatedPost.description = updatedPost.html
}

return updatedPost
Expand Down
23 changes: 15 additions & 8 deletions src/adaptors/api/gitlab-vuepress/gitlabvuepressApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ 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"
import { YamlUtil } from "zhi-common"

/**
* Hexo API 适配器
Expand All @@ -49,24 +50,30 @@ class GitlabvuepressApiAdaptor extends CommonGitlabApiAdaptor {
const updatedPost = _.cloneDeep(doc) as Post

// 自定义处理
// 成功提示、信息提示、警告提示、错误提示
const md = updatedPost.markdown
this.logger.info("准备处理 Gitlabvuepress 正文")
this.logger.debug("md =>", { md: md })
let updatedMd = md
const yfm = YamlUtil.extractFrontmatter(md, true)
let updatedMd = YamlUtil.extractMarkdown(md)

// MD暂时无法处理标记,先搁置
// 处理MD
// ======
// 摘要
const shortDesc = updatedPost.shortDesc ?? ""
const descRegex = /(\n{2}<!-- more -->\n{2})/
if (!descRegex.test(updatedMd)) {
updatedMd = `${shortDesc}\n\n<!-- more -->\n\n${updatedMd}`
}
// ======

updatedPost.markdown = updatedMd
updatedPost.markdown = `${yfm}\n${updatedMd}`
this.logger.info("Gitlabvuepress 正文处理完毕")
this.logger.debug("updatedMd =>", { updatedMd: updatedMd })
this.logger.debug("updatedMd =>", { yfm: yfm, updatedMd: updatedMd })

// 发布格式
if (cfg?.pageType == PageTypeEnum.Markdown) {
post.description = post.markdown
updatedPost.description = updatedPost.markdown
} else {
post.description = post.html
updatedPost.description = updatedPost.html
}

return updatedPost
Expand Down
21 changes: 13 additions & 8 deletions src/adaptors/api/hexo/hexoApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { CommonGithubApiAdaptor } from "~/src/adaptors/api/base/github/commonGit
import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import { HexoYamlConverterAdaptor } from "~/src/adaptors/api/hexo/hexoYamlConverterAdaptor.ts"
import _ from "lodash"
import { YamlUtil } from "zhi-common"

/**
* Hexo API 适配器
Expand All @@ -49,23 +50,27 @@ class HexoApiAdaptor extends CommonGithubApiAdaptor {
const updatedPost = _.cloneDeep(doc) as Post

// 自定义处理
// 信息、警告、错误
const md = updatedPost.markdown
this.logger.info("准备处理 Hexo 正文")
this.logger.debug("md =>", { md: md })
let updatedMd = md
// MD暂时无法处理标记,先搁置
// 处理MD
updatedPost.markdown = updatedMd
const yfm = YamlUtil.extractFrontmatter(md, true)
let updatedMd = YamlUtil.extractMarkdown(md)

// ======
// 可修改 updatedMd
// ======

updatedPost.markdown = `${yfm}\n${updatedMd}`
this.logger.info("Hexo 正文处理完毕")
this.logger.debug("updatedMd =>", { updatedMd: updatedMd })
this.logger.debug("updatedMd =>", { yfm: yfm, updatedMd: updatedMd })

// 发布格式
if (cfg?.pageType == PageTypeEnum.Markdown) {
post.description = post.markdown
updatedPost.description = updatedPost.markdown
} else {
post.description = post.html
updatedPost.description = updatedPost.html
}

return updatedPost
}
}
Expand Down
21 changes: 13 additions & 8 deletions src/adaptors/api/hugo/hugoApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { CommonGithubApiAdaptor } from "~/src/adaptors/api/base/github/commonGit
import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import _ from "lodash"
import { HugoYamlConverterAdaptor } from "~/src/adaptors/api/hugo/hugoYamlConverterAdaptor.ts"
import {YamlUtil} from "zhi-common";

/**
* Hugo API 适配器
Expand All @@ -49,23 +50,27 @@ class HugoApiAdaptor extends CommonGithubApiAdaptor {
const updatedPost = _.cloneDeep(doc) as Post

// 自定义处理
// 信息、警告、错误
const md = updatedPost.markdown
this.logger.info("准备处理 Hugo 正文")
this.logger.debug("md =>", { md: md })
let updatedMd = md
// MD暂时无法处理标记,先搁置
// 处理MD
updatedPost.markdown = updatedMd
const yfm = YamlUtil.extractFrontmatter(md, true)
let updatedMd = YamlUtil.extractMarkdown(md)

// ======
// 可修改 updatedMd
// ======

updatedPost.markdown = `${yfm}\n${updatedMd}`
this.logger.info("Hugo 正文处理完毕")
this.logger.debug("updatedMd =>", { updatedMd: updatedMd })
this.logger.debug("updatedMd =>", { yfm: yfm, updatedMd: updatedMd })

// 发布格式
if (cfg?.pageType == PageTypeEnum.Markdown) {
post.description = post.markdown
updatedPost.description = updatedPost.markdown
} else {
post.description = post.html
updatedPost.description = updatedPost.html
}

return updatedPost
}
}
Expand Down
21 changes: 13 additions & 8 deletions src/adaptors/api/jekyll/jekyllApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { CommonGithubApiAdaptor } from "~/src/adaptors/api/base/github/commonGit
import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import _ from "lodash"
import { JekyllYamlConverterAdaptor } from "~/src/adaptors/api/jekyll/jekyllYamlConverterAdaptor.ts"
import { YamlUtil } from "zhi-common"

/**
* Jekyll API 适配器
Expand All @@ -49,23 +50,27 @@ class JekyllApiAdaptor extends CommonGithubApiAdaptor {
const updatedPost = _.cloneDeep(doc) as Post

// 自定义处理
// 信息、警告、错误
const md = updatedPost.markdown
this.logger.info("准备处理 Jekyll 正文")
this.logger.debug("md =>", { md: md })
let updatedMd = md
// MD暂时无法处理标记,先搁置
// 处理MD
updatedPost.markdown = updatedMd
const yfm = YamlUtil.extractFrontmatter(md, true)
let updatedMd = YamlUtil.extractMarkdown(md)

// ======
// 可修改 updatedMd
// ======

updatedPost.markdown = `${yfm}\n${updatedMd}`
this.logger.info("Jekyll 正文处理完毕")
this.logger.debug("updatedMd =>", { updatedMd: updatedMd })
this.logger.debug("updatedMd =>", { yfm: yfm, updatedMd: updatedMd })

// 发布格式
if (cfg?.pageType == PageTypeEnum.Markdown) {
post.description = post.markdown
updatedPost.description = updatedPost.markdown
} else {
post.description = post.html
updatedPost.description = updatedPost.html
}

return updatedPost
}
}
Expand Down
Loading

0 comments on commit 4bf1cee

Please sign in to comment.