Skip to content

Commit

Permalink
feat: Hexo 平台支持修改自定义 YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 15, 2023
1 parent 4d7e85f commit e9ce0da
Show file tree
Hide file tree
Showing 16 changed files with 822 additions and 182 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"typescript": "^5.1.6",
"unplugin-auto-import": "^0.16.6",
"unplugin-vue-components": "^0.25.1",
"vercel": "^31.2.3",
"vercel": "^31.3.1",
"vite": "^4.4.9",
"vite-plugin-html": "^3.2.0",
"vite-plugin-node-polyfills": "^0.11.1",
Expand All @@ -70,14 +70,14 @@
"vue-i18n": "^9.2.2",
"vue-router": "^4.2.4",
"xmlbuilder2": "^3.1.1",
"zhi-blog-api": "^1.20.22",
"zhi-common": "^1.14.2",
"zhi-device": "^2.3.0",
"zhi-fetch-middleware": "^0.2.21",
"zhi-github-middleware": "^0.2.2",
"zhi-blog-api": "^1.23.0",
"zhi-common": "^1.17.0",
"zhi-device": "^2.3.1",
"zhi-fetch-middleware": "^0.2.28",
"zhi-github-middleware": "^0.2.8",
"zhi-lib-base": "^0.4.4",
"zhi-notion-markdown": "^0.1.4",
"zhi-siyuan-api": "^2.0.27",
"zhi-xmlrpc-middleware": "^0.4.15"
"zhi-siyuan-api": "^2.1.5",
"zhi-xmlrpc-middleware": "^0.4.22"
}
}
127 changes: 64 additions & 63 deletions pnpm-lock.yaml

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

31 changes: 30 additions & 1 deletion src/adaptors/api/base/github/commonGithubApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ import { createAppLogger } from "~/src/utils/appLogger.ts"
import { CategoryInfo, Post, UserBlog } from "zhi-blog-api"
import { CommonGithubClient, GithubConfig } from "zhi-github-middleware"
import { CommonGithubConfig } from "~/src/adaptors/api/base/github/commonGithubConfig.ts"
import { StrUtil } from "zhi-common"
import { ObjectUtil, StrUtil } from "zhi-common"
import { toRaw } from "vue"
import { Base64 } from "js-base64"
import { YamlConvertAdaptor } from "~/src/platforms/yamlConvertAdaptor.ts"
import { YamlFormatObj } from "~/src/models/yamlFormatObj.ts"
import Adaptors from "~/src/adaptors"
import { DynamicConfig, getDynYamlKey } from "~/src/platforms/dynamicConfig.ts"
import { useSettingStore } from "~/src/stores/useSettingStore.ts"

/**
* Github API 适配器
Expand All @@ -41,6 +46,7 @@ import { Base64 } from "js-base64"
*/
class CommonGithubApiAdaptor extends BaseBlogApi {
private githubClient: CommonGithubClient
private settingStore

constructor(appInstance: any, cfg: CommonGithubConfig) {
super(appInstance, cfg)
Expand All @@ -58,6 +64,7 @@ class CommonGithubApiAdaptor extends BaseBlogApi {
githubConfig.mdFilenameRule = cfg.mdFilenameRule

this.githubClient = new CommonGithubClient(githubConfig)
this.settingStore = useSettingStore()
}

public async getUsersBlogs(): Promise<UserBlog[]> {
Expand All @@ -80,6 +87,28 @@ class CommonGithubApiAdaptor extends BaseBlogApi {
return result
}

public async preEditPost(post: Post, id?: string, publishCfg?: any): Promise<Post> {
// 调用父类预处理
await super.preEditPost(post, id, publishCfg)
this.logger.info("handled preEditPost with parent")

const dynCfg = publishCfg.dynCfg as DynamicConfig
const cfg = this.cfg as CommonGithubConfig
// 处理 YAML
const yamlKey = getDynYamlKey(dynCfg.platformKey)
const setting = await this.settingStore.getSetting()
const postMeta = ObjectUtil.getProperty(setting, id, {})
const yaml = ObjectUtil.getProperty(postMeta, yamlKey, "---\n---")
this.logger.debug("get stored yaml from postMeta =>", yaml)

throw new Error("开发中")
const yamlApi: YamlConvertAdaptor = await Adaptors.getYamlAdaptor(dynCfg.platformKey, cfg)
const yamlObj: YamlFormatObj = yamlApi.convertToYaml(post, cfg)
post.description = yamlObj.mdFullContent
this.logger.info("handled yaml using HexoYamlConverterAdaptor")
return post
}

public async newPost(post: Post, publish?: boolean): Promise<string> {
this.logger.debug("start newPost =>", { post: toRaw(post) })
const cfg = this.cfg as CommonGithubConfig
Expand Down
Loading

0 comments on commit e9ce0da

Please sign in to comment.