Skip to content

Commit

Permalink
Merge pull request #578 from terwer/dev
Browse files Browse the repository at this point in the history
feat: 支持文章绑定
  • Loading branch information
terwer authored Aug 7, 2023
2 parents 2301978 + 15ef655 commit 38abbcb
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 137 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,13 @@ This plugin supports almost all devices and platforms of Siyuan Note, and the sp
Names not listed in order

- [X] Yuque
- [ ] Web authed of Yuque
- [X] Metaweblog
- [X] Cnblogs
- [X] Typecho
- [X] WordPress
- [ ] Github
- [ ] Hexo
- [ ] Hugo
- [X] Github
- [X] Hexo
- [X] Notion
- [ ] Web authed of Notion
- [ ] Zhihu

## Core Features
Expand Down
7 changes: 2 additions & 5 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,13 @@
排名不分先后

- [X] 语雀
- [ ] 语雀网页授权版
- [X] 博客园
- [X] Metaweblog
- [X] Typecho
- [X] WordPress
- [ ] Github
- [ ] Hexo
- [ ] Hugo
- [X] Github
- [X] Hexo
- [X] Notion
- [ ] Notion 网页授权版
- [ ] 知乎

## 核心特色
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@
"vue-i18n": "^9.2.2",
"vue-router": "^4.2.4",
"xmlbuilder2": "^3.1.1",
"zhi-blog-api": "^1.20.12",
"zhi-blog-api": "^1.20.13",
"zhi-common": "^1.14.0",
"zhi-device": "^2.3.0",
"zhi-fetch-middleware": "^0.2.18",
"zhi-github-middleware": "^0.2.0",
"zhi-lib-base": "^0.4.4",
"zhi-notion-markdown": "^0.1.2",
"zhi-siyuan-api": "^2.0.13",
"zhi-siyuan-api": "^2.0.14",
"zhi-xmlrpc-middleware": "^0.4.13"
}
}
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

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

7 changes: 6 additions & 1 deletion siyuan/invoke/widgetInvoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ export class WidgetInvoke {
}

public async showPublisherGeneralSettingDialog() {
await this.showPage("/setting/general")
let pageId: string | undefined = PageUtil.getPageId()
if (pageId == "") {
pageId = undefined
}
this.logger.debug("pageId=>", pageId)
await this.showPage(`/setting/general?id=${pageId}`)
}

private async showPage(pageUrl: string, isReload?: boolean, w?: string, h?: string, noscroll?: boolean) {
Expand Down
78 changes: 40 additions & 38 deletions src/adaptors/api/hexo/hexoYamlConverterAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
*/

import { YamlConvertAdaptor } from "~/src/platforms/yamlConvertAdaptor.ts"
import { CommonGithubConfig } from "~/src/adaptors/api/base/github/CommonGithubConfig.ts"
import { createAppLogger } from "~/src/utils/appLogger.ts"
import { YamlFormatObj } from "~/src/models/yamlFormatObj.ts"
import { Post } from "zhi-blog-api"
import { CommonblogConfig } from "~/src/adaptors/api/base/CommonblogConfig.ts"
import { DateUtil, StrUtil, YamlUtil } from "zhi-common"
import { PostForm } from "~/src/models/postForm.ts"
import { CommonGithubConfig } from "~/src/adaptors/api/base/github/CommonGithubConfig.ts"

/**
* Hexo平台的YAML解析器
Expand All @@ -39,49 +40,51 @@ import { PostForm } from "~/src/models/postForm.ts"
export class HexoYamlConverterAdaptor extends YamlConvertAdaptor {
private readonly logger = createAppLogger("hexo-yaml-converter-adaptor")

convertToYaml(postForm: PostForm, githubCfg?: CommonGithubConfig): YamlFormatObj {
convertToYaml(post: Post, cfg?: CommonblogConfig): YamlFormatObj {
let yamlFormatObj: YamlFormatObj = new YamlFormatObj()
this.logger.debug("您正在使用 Hexo Yaml Converter", postForm)
this.logger.debug("您正在使用 Hexo Yaml Converter", post)

// title
yamlFormatObj.yamlObj.title = postForm.formData.title
yamlFormatObj.yamlObj.title = post.title

// date
// yamlFormatObj.yamlObj.date = postForm.formData.created
// yamlFormatObj.yamlObj.date = post.dateCreated

// updated
yamlFormatObj.yamlObj.updated = DateUtil.formatIsoToZhDate(new Date().toISOString())

// excerpt
yamlFormatObj.yamlObj.excerpt = postForm.formData.desc

// tags
yamlFormatObj.yamlObj.tags = postForm.formData.tag.dynamicTags
yamlFormatObj.yamlObj.excerpt = post.shortDesc

// categories
yamlFormatObj.yamlObj.categories = postForm.formData.categories
// // tags
// yamlFormatObj.yamlObj.tags = postForm.formData.tag.dynamicTags
//
// // categories
// yamlFormatObj.yamlObj.categories = postForm.formData.categories

// permalink
let link = "/post/" + postForm.formData.customSlug + ".html"
if (githubCfg && !StrUtil.isEmptyString(githubCfg.previewUrl)) {
link = githubCfg.previewUrl.replace("[postid]", postForm.formData.customSlug)

const created = postForm.formData.created
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]/, "")
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 = post.dateCreated
// 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
Expand All @@ -96,17 +99,16 @@ export class HexoYamlConverterAdaptor extends YamlConvertAdaptor {
let yaml = YamlUtil.obj2Yaml(yamlFormatObj.yamlObj)
// 修复yaml的ISO日期格式(js-yaml转换的才需要)
yaml = DateUtil.formatIsoToZhDate(yaml)
// this.logger.debug("yaml=>", yaml)
this.logger.debug("yaml=>", yaml)

yamlFormatObj.formatter = yaml
yamlFormatObj.mdContent = postForm.formData.mdContent
yamlFormatObj.mdContent = post.markdown
yamlFormatObj.mdFullContent = yamlFormatObj.formatter + "\n\n" + yamlFormatObj.mdContent
yamlFormatObj.htmlContent = postForm.formData.htmlContent

yamlFormatObj.htmlContent = post.html
return yamlFormatObj
}

convertToAttr(yamlFormatObj: YamlFormatObj, githubCfg?: CommonGithubConfig): PostForm {
return super.convertToAttr(yamlFormatObj, githubCfg)
convertToAttr(yamlFormatObj: YamlFormatObj, cfg?: CommonblogConfig): Post {
return super.convertToAttr(yamlFormatObj, cfg)
}
}
11 changes: 8 additions & 3 deletions src/adaptors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,21 @@ class Adaptors {
* @param newCfg
*/
public static async getYamlAdaptor(key: string, newCfg?: any): Promise<YamlConvertAdaptor> {
let yamlAdaptor = null
let yamlAdp = null
const type: SubPlatformType = getSubPlatformTypeByKey(key)

switch (type) {
case SubPlatformType.Github_Hexo: {
const { yamlAdaptor } = await useHexoApi(key, newCfg)
yamlAdp = yamlAdaptor
break
}
default: {
break
}
}
this.logger.debug(`get yamlAdaptor from key ${key}=>`, yamlAdaptor)
return yamlAdaptor
this.logger.debug(`get yamlAdaptor from key ${key}=>`, yamlAdp)
return yamlAdp
}
}

Expand Down
17 changes: 11 additions & 6 deletions src/components/set/GeneralSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@
-->

<script setup lang="ts">
import ChangeLocal from "~/src/components/set/preference/ChangeLocal.vue"
import { useVueI18n } from "~/src/composables/useVueI18n.ts"
const { t } = useVueI18n()
</script>

<template>
<div class="general-setting">
<change-local />
</div>
<el-tabs tab-position="left">
<el-tab-pane :label="t('service.tab.change.local')">
<change-local />
</el-tab-pane>
<el-tab-pane :label="t('service.tab.post.bind')">
<post-bind />
</el-tab-pane>
</el-tabs>
</template>

<style scoped></style>
Loading

0 comments on commit 38abbcb

Please sign in to comment.