Skip to content

Commit

Permalink
fix: 修复YAML转换错误
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 31, 2023
1 parent 617be1d commit 53f7196
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@
"vue-i18n": "^9.2.2",
"vue-router": "^4.2.4",
"xmlbuilder2": "^3.1.1",
"zhi-blog-api": "^1.34.14",
"zhi-blog-api": "^1.35.0",
"zhi-common": "^1.23.7",
"zhi-device": "^2.3.1",
"zhi-fetch-middleware": "^0.6.4",
"zhi-github-middleware": "^0.4.2",
"zhi-gitlab-middleware": "^0.6.4",
"zhi-lib-base": "^0.5.0",
"zhi-notion-markdown": "^0.1.4",
"zhi-siyuan-api": "^2.6.2",
"zhi-siyuan-api": "^2.7.0",
"zhi-xmlrpc-middleware": "^0.5.11"
}
}
29 changes: 17 additions & 12 deletions pnpm-lock.yaml

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

5 changes: 3 additions & 2 deletions src/components/publish/form/SourceMode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { useVueI18n } from "~/src/composables/useVueI18n.ts"
import { reactive, toRaw } from "vue"
import { SourceContentShowType } from "~/src/models/sourceContentShowType.ts"
import { createAppLogger } from "~/src/utils/appLogger.ts"
import { Post, YamlConvertAdaptor, YamlFormatObj } from "zhi-blog-api"
import { Post, PostUtil, YamlConvertAdaptor, YamlFormatObj } from "zhi-blog-api"
import { BrowserUtil } from "zhi-device"
import { ElMessage } from "element-plus"
import { DateUtil, StrUtil, YamlUtil } from "zhi-common"
Expand Down Expand Up @@ -197,7 +197,8 @@ const initPage = async () => {
// 批量分发,此时 apiType 为空
if (formData.readonlyMode) {
yfmObj.formatter = YamlUtil.obj2Yaml(formData.siyuanPost.toYamlObj())
const yamlObj = PostUtil.toYamlObj(formData.siyuanPost)
yfmObj.formatter = YamlUtil.obj2Yaml(yamlObj)
yfmObj.mdContent = post.markdown
yfmObj.mdFullContent = YamlUtil.addYamlToMd(yfmObj.formatter, yfmObj.mdContent)
yfmObj.htmlContent = post.html
Expand Down
17 changes: 13 additions & 4 deletions src/composables/usePublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ import { createAppLogger } from "~/src/utils/appLogger.ts"
import { reactive, toRaw } from "vue"
import { SypConfig } from "~/syp.config.ts"
import { AliasTranslator, ObjectUtil, StrUtil, YamlUtil } from "zhi-common"
import { BlogAdaptor, BlogConfig, Post, PostStatusEnum, YamlConvertAdaptor, YamlFormatObj } from "zhi-blog-api"
import {
BlogAdaptor,
BlogConfig,
Post,
PostStatusEnum,
PostUtil,
YamlConvertAdaptor,
YamlFormatObj,
} from "zhi-blog-api"
import { useVueI18n } from "~/src/composables/useVueI18n.ts"
import { useSettingStore } from "~/src/stores/useSettingStore.ts"
import { useSiyuanApi } from "~/src/composables/useSiyuanApi.ts"
Expand Down Expand Up @@ -326,10 +334,11 @@ const usePublish = () => {
*/
const initPublishMethods = {
// 别名初始化
assignInitSlug: async (post: Post, id: string, publishCfg: IPublishCfg) => {
assignInitSlug: async (doc: Post, id: string, publishCfg: IPublishCfg) => {
const setting: typeof SypConfig = publishCfg.setting
const postMeta = ObjectUtil.getProperty(setting, id, {})

const post = _.cloneDeep(doc) as Post
// 别名
const slug = ObjectUtil.getProperty(postMeta, SiyuanAttr.Custom_slug, post.wp_slug)
if (!StrUtil.isEmptyString(slug)) {
Expand Down Expand Up @@ -387,7 +396,7 @@ const usePublish = () => {
if (!StrUtil.isEmptyString(checkYaml)) {
const yamlObj = await YamlUtil.yaml2ObjAsync(yaml)
post.yaml = yaml
post.fromYaml(yamlObj)
PostUtil.fromYaml(post, yamlObj)
logger.info("读取已经存在的YAML,无适配器,使用fromYaml生成默认的yamlObj")
} else {
// 未保存过,默认不处理
Expand Down Expand Up @@ -479,7 +488,7 @@ const usePublish = () => {
const mergedPost = _.cloneDeep(newPost) as Post

// 摘要
if(StrUtil.isEmptyString(newPost.shortDesc) && StrUtil.isEmptyString(newPost.mt_excerpt)){
if (StrUtil.isEmptyString(newPost.shortDesc) && StrUtil.isEmptyString(newPost.mt_excerpt)) {
mergedPost.shortDesc = post.shortDesc
mergedPost.mt_excerpt = post.mt_excerpt
}
Expand Down

0 comments on commit 53f7196

Please sign in to comment.