Skip to content

Commit

Permalink
fix: 修复 Yaml 修改未生效问题
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Nov 6, 2023
1 parent 4645104 commit c3180b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
37 changes: 18 additions & 19 deletions src/adaptors/base/baseExtendApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class BaseExtendApi extends WebApi implements IBlogApi, IWebApi {
if (docPathArray.length > 1) {
for (let i = 1; i < docPathArray.length; i++) {
const docPath = docPathArray[i]
if(StrUtil.isEmptyString(docPath)){
if (StrUtil.isEmptyString(docPath)) {
continue
}
const docCate = HtmlUtil.removeTitleNumber(docPath)
Expand All @@ -264,7 +264,6 @@ class BaseExtendApi extends WebApi implements IBlogApi, IWebApi {
}
}


// 目录分类
this.logger.info("目录路径转换的分类 =>", pathCates)
const mergedCategories = [...new Set([...(pathCates ?? []), ...(post?.categories ?? [])])].filter(
Expand Down Expand Up @@ -359,13 +358,23 @@ class BaseExtendApi extends WebApi implements IBlogApi, IWebApi {
// 前面改过属性,需要再生成一次
const yamlAdaptor: YamlConvertAdaptor = this.api.getYamlAdaptor()
if (null !== yamlAdaptor) {
// 先生成对应平台的yaml
const yamlObj: YamlFormatObj = yamlAdaptor.convertToYaml(post, cfg)
// 同步发布内容
post.yaml = yamlObj.formatter
post.markdown = yamlObj.mdFullContent
post.html = yamlObj.htmlContent
this.logger.info("rehandled yaml using YamlConverterAdaptor")
let yamlObj: YamlFormatObj
const defaultYaml = PostUtil.toYamlObj(post)
if (defaultYaml?.slug?.indexOf("siyuan://") > -1) {
// 先生成对应平台的yaml
yamlObj = yamlAdaptor.convertToYaml(post, cfg)
// 同步发布内容
post.yaml = yamlObj.formatter
post.markdown = yamlObj.mdFullContent
post.html = yamlObj.htmlContent
this.logger.info("rehandled yaml using YamlConverterAdaptor")
} else {
const md = YamlUtil.extractMarkdown(post.markdown)
// post.yaml 始终保持最新
post.markdown = YamlUtil.addYamlToMd(post.yaml, md)
post.html = LuteUtil.mdToHtml(md)
this.logger.info("assign latest custom yaml to md")
}
} else {
// 同步发布内容
const yamlObj = PostUtil.toYamlObj(post)
Expand All @@ -377,16 +386,6 @@ class BaseExtendApi extends WebApi implements IBlogApi, IWebApi {
this.logger.info("yaml adaptor not found, using default")
}

// YAML与MD的处理,旧的逻辑,不考虑属性变更的情况
// if (null !== yamlAdaptor) {
// const md = YamlUtil.extractMarkdown(post.markdown)
// const yaml = post.yaml
// post.markdown = YamlUtil.addYamlToMd(yaml, md)
// this.logger.info("检测到该平台已开启YAML适配器,已附加YAML到Markdown正文")
// } else {
// this.logger.info("未找到YAML适配器,不作处理")
// }

this.logger.debug("yaml处理之后,post", { post: toRaw(post) })
return post
}
Expand Down
7 changes: 6 additions & 1 deletion src/components/publish/SinglePublishDoPublish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ onMounted(async () => {
:page-id="id"
:cfg="formData.publishCfg.cfg"
@emitSyncPost="syncPost"
@edmtSyncToSiyuan="handleSyncToSiyuan"
/>
<div v-else class="normal-mode">
<!-- 文章标题 -->
Expand Down Expand Up @@ -616,7 +617,11 @@ onMounted(async () => {
>
{{ t("main.force.cancel") }}
</el-button>
<el-button type="warning" @click="handleSyncToSiyuan" :disabled="!formData.actionEnable">
<el-button
type="warning"
@click="handleSyncToSiyuan"
:disabled="!formData.actionEnable && formData.editType !== PageEditMode.EditMode_source"
>
同步修改到思源笔记
</el-button>
</el-form-item>
Expand Down
3 changes: 2 additions & 1 deletion src/components/publish/form/SourceMode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const formData = reactive({
isSaved: true,
})
const emit = defineEmits(["emitSyncPost"])
const emit = defineEmits(["emitSyncPost", "edmtSyncToSiyuan"])
// methods
const onYamlShowTypeChange = (val: SourceContentShowType) => {
Expand Down Expand Up @@ -157,6 +157,7 @@ const doSaveContentChange = () => {
post: toRaw(formData.siyuanPost),
})
emit("emitSyncPost", formData.siyuanPost)
emit("edmtSyncToSiyuan")
formData.syncStatus = "success"
formData.syncMessage = "YAML已解析成功并同步。同步时间 =>" + DateUtil.formatIsoToZh(new Date().toISOString(), true)
formData.isSaved = true
Expand Down

0 comments on commit c3180b9

Please sign in to comment.