Skip to content

Commit

Permalink
feat: 完成 Hexo 适配
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 7, 2023
1 parent 4634b7d commit 5081d7b
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 49 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"unplugin-auto-import": "^0.16.6",
"unplugin-vue-components": "^0.25.1",
"vercel": "^31.2.2",
"vite": "^4.4.8",
"vite": "^4.4.9",
"vite-plugin-html": "^3.2.0",
"vite-plugin-node-polyfills": "^0.8.2",
"vitest": "^0.34.1",
Expand All @@ -66,13 +66,13 @@
"vue-router": "^4.2.4",
"xmlbuilder2": "^3.1.1",
"zhi-blog-api": "^1.20.11",
"zhi-common": "^1.13.4",
"zhi-common": "^1.14.0",
"zhi-device": "^2.3.0",
"zhi-fetch-middleware": "^0.2.17",
"zhi-fetch-middleware": "^0.2.18",
"zhi-github-middleware": "^0.1.18",
"zhi-lib-base": "^0.4.4",
"zhi-notion-markdown": "^0.1.2",
"zhi-siyuan-api": "^2.0.11",
"zhi-xmlrpc-middleware": "^0.4.12"
"zhi-siyuan-api": "^2.0.12",
"zhi-xmlrpc-middleware": "^0.4.13"
}
}
74 changes: 42 additions & 32 deletions pnpm-lock.yaml

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

48 changes: 38 additions & 10 deletions src/adaptors/api/base/github/CommonGithubApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { CommonGithubClient, GithubConfig } from "zhi-github-middleware"
import { CommonGithubConfig } from "~/src/adaptors/api/base/github/CommonGithubConfig.ts"
import { StrUtil } from "zhi-common"
import { toRaw } from "vue"
import { Base64 } from "js-base64"

/**
* Github API 适配器
Expand Down Expand Up @@ -94,33 +95,60 @@ class CommonGithubApiAdaptor extends BaseBlogApi {
return res.content.path
}

async editPost(postid: string, post: Post, publish?: boolean): Promise<boolean> {
public async getPost(postid: string, useSlug?: boolean): Promise<Post> {
this.logger.debug("start getPost =>", { postid: postid })

const res = await this.githubClient.getPageData(postid)
this.logger.debug("getPost finished =>", res)
if (!res) {
throw new Error("Github 调用API异常")
}

const commonPost = new Post()
commonPost.postid = res.path
// commonPost.title = res.name
commonPost.description = Base64.fromBase64(res.content)

const cats = []
const catSlugs = []
commonPost.categories = cats
commonPost.cate_slugs = catSlugs

return commonPost
}

public async editPost(postid: string, post: Post, publish?: boolean): Promise<boolean> {
this.logger.debug("start editPost =>", { postid: postid, post: toRaw(post) })

const res = await this.githubClient.updateGithubPage(post.postid, post.description)
if (!res?.content?.path) {
throw new Error("Hugo调用API异常")
throw new Error("Github 调用API异常")
}
return true
}

public async deletePost(postid: string): Promise<boolean> {
const res = await this.githubClient.deleteGithubPage(postid)
if (!res?.commit?.sha) {
throw new Error("Hugo调用API异常")
throw new Error("Github 调用API异常")
}
return true
}

public async getCategories(): Promise<CategoryInfo[]> {
return await Promise.resolve([])
return Promise.resolve([])
}

public async getPreviewUrl(postid: string): Promise<string> {
let previewUrl: string = "/test"
// const newPostid = postid.substring(postid.lastIndexOf("/") + 1).replace(".md", "")
// previewUrl = this.cfg.previewUrl.replace("[postid]", newPostid)
// // 路径组合
// previewUrl = StrUtil.pathJoin(StrUtil.pathJoin(this.cfg.home, this.cfg.username), previewUrl)
//
const cfg = this.cfg as CommonGithubConfig
let previewUrl: string
previewUrl = cfg.previewUrl
.replace("[user]", cfg.username)
.replace("[repo]", cfg.githubRepo)
.replace("[branch]", cfg.githubBranch)
.replace("[docpath]", postid)
// 路径组合
previewUrl = StrUtil.pathJoin(this.cfg.home, previewUrl)
return previewUrl
}

Expand Down
6 changes: 4 additions & 2 deletions src/composables/usePublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ const usePublish = () => {
postid = ObjectUtil.getProperty(postMeta, posidKey)
}
singleFormData.isAdd = StrUtil.isEmptyString(postid)
// 保证postid一致
doc.postid = postid

// 分配属性
doc = await assignAttrs(doc, id, publishCfg)
Expand Down Expand Up @@ -329,7 +331,7 @@ const usePublish = () => {

// 思源笔记原始文章数据
const siyuanPost = await blogApi.getPost(id)
const platformPost = new Post()
let platformPost = new Post()
let mergedPost = new Post()
logger.debug("doInitPage start init siyuanPost =>", toRaw(siyuanPost))

Expand All @@ -343,7 +345,7 @@ const usePublish = () => {
}

// 查询平台文章
const platformPost = await api.getPost(postid)
platformPost = await api.getPost(postid)

// 暂时不合并
mergedPost = siyuanPost
Expand Down

0 comments on commit 5081d7b

Please sign in to comment.