From c155c42757174391ef71fce26b8582ca1ad5c8ea Mon Sep 17 00:00:00 2001 From: terwer Date: Mon, 13 Nov 2023 13:22:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8E=A7=E5=88=B6=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E6=96=B9=E5=BC=8F=EF=BC=8C=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E6=9C=89=E9=80=82=E9=85=8D=E5=99=A8=EF=BC=8C=E4=BC=98=E5=85=88?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=20YAML?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/publish/form/SourceMode.vue | 30 +++++++--------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/components/publish/form/SourceMode.vue b/src/components/publish/form/SourceMode.vue index 75cf0fd9..13f656d0 100644 --- a/src/components/publish/form/SourceMode.vue +++ b/src/components/publish/form/SourceMode.vue @@ -41,7 +41,6 @@ import { useSiyuanApi } from "~/src/composables/useSiyuanApi.ts" const logger = createAppLogger("source-mode") const { t } = useVueI18n() const { handlePicgo } = usePicgoBridge() -const { kernelApi } = useSiyuanApi() const props = defineProps({ modelValue: { @@ -191,12 +190,19 @@ const initPage = async () => { // 如果传了 key ,但是没有 YAML 适配器,还是不能展示 formData.readonlyMode = formData.yamlAdaptor === null + // 控制默认展示方式,如果有适配器,优先展示 YAML + if (formData.readonlyMode) { + formData.stype = SourceContentShowType.YAML + } + // 处理正文 const id = formData.pageId const md = await handlePicgo(id, post.markdown) post.markdown = md - // 批量分发,此时 apiType 为空 + // 1、批量分发,此时 apiType 为空 + // 2、某些平台没有适配器 + // 这些情况生成默认的 if (formData.readonlyMode) { const yamlObj = PostUtil.toYamlObj(formData.siyuanPost) yfmObj.formatter = YamlUtil.obj2Yaml(yamlObj) @@ -205,26 +211,8 @@ const initPage = async () => { yfmObj.htmlContent = post.html logger.debug("未找到YAML适配器,将生成公共的YAML") } else { - // 检测 const key = formData.apiType - const yamlKey = getDynYamlKey(key) - const yaml = await kernelApi.getSingleBlockAttr(id, yamlKey) - const checkYaml = YamlUtil.extractFrontmatter(yaml).trim() - if (StrUtil.isEmptyString(checkYaml)) { - yfmObj = formData.yamlAdaptor.convertToYaml(post, formData.cfg) - logger.info("有适配器未保存,生成新的YAML") - } else { - // yamlFormatObj = new YamlFormatObj() - // const yamlObj = await YamlUtil.yaml2ObjAsync(yaml) - // yamlFormatObj.yamlObj = yamlFormatObj - // getPost以已经处理过了 - yfmObj.formatter = yaml - yfmObj.mdContent = post.markdown - yfmObj.mdFullContent = YamlUtil.addYamlToMd(yfmObj.formatter, yfmObj.mdContent) - yfmObj.htmlContent = post.html - logger.info("有适配器且YAML已保存,无需处理") - } - + yfmObj = formData.yamlAdaptor.convertToYaml(post, formData.cfg) logger.debug("常规发布,生成对应平台的YAML, =>", key) }