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 be175a5 commit 704241b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
37 changes: 30 additions & 7 deletions src/components/publish/form/SourceMode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ import { DateUtil, StrUtil, YamlUtil } from "zhi-common"
import { CommonBlogConfig } from "~/src/adaptors/api/base/commonBlogConfig.ts"
import Adaptors from "~/src/adaptors"
import { usePicgoBridge } from "~/src/composables/usePicgoBridge.ts"
import { getDynYamlKey } from "~/src/platforms/dynamicConfig.ts"
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: {
Expand Down Expand Up @@ -68,7 +71,9 @@ const formData = reactive({
syncStatus: "info",
syncMessage: "未修改",
cfg: {} as CommonBlogConfig,
pageId: props.pageId,
apiType: props.apiType,
cfg: props.cfg as CommonBlogConfig,
yamlAdaptor: {} as YamlConvertAdaptor,
// YAML对象
Expand Down Expand Up @@ -180,14 +185,13 @@ const initPage = async () => {
try {
let yfmObj: YamlFormatObj = new YamlFormatObj()
const post = formData.siyuanPost
formData.cfg = props.cfg as CommonBlogConfig
// 没有平台 Key,不展示 YAML
formData.yamlAdaptor = formData.readonlyMode ? null : await Adaptors.getYamlAdaptor(props.apiType, formData.cfg)
formData.yamlAdaptor = formData.readonlyMode ? null : await Adaptors.getYamlAdaptor(formData.apiType, formData.cfg)
// 如果传了 key ,但是没有 YAML 适配器,还是不能展示
formData.readonlyMode = formData.yamlAdaptor === null
// 处理正文
const id = props.pageId
const id = formData.pageId
const md = await handlePicgo(id, post.markdown)
post.markdown = md
Expand All @@ -199,8 +203,27 @@ const initPage = async () => {
yfmObj.htmlContent = post.html
logger.debug("未找到YAML适配器,将生成公共的YAML")
} else {
yfmObj = formData.yamlAdaptor.convertToYaml(post, formData.cfg)
logger.debug("常规发布,生成对应平台的YAML, =>", props.apiType)
// 检测
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已保存,无需处理")
}
logger.debug("常规发布,生成对应平台的YAML, =>", key)
}
// 初始化
Expand Down Expand Up @@ -396,4 +419,4 @@ html.dark .readonly-textarea .el-textarea__inner {
background-color: #333;
color: #ddd;
}
</style>
</style>
2 changes: 1 addition & 1 deletion src/composables/usePublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ const usePublish = () => {
},

// 分配平台相关的初始化属性
assignInitAttrs: async (post: Post, id: string, publishCfg: IPublishCfg, method: MethodEnum) => {
assignInitAttrs: async (post: Post, id: string, publishCfg: IPublishCfg) => {
const setting: typeof SypConfig = publishCfg.setting
const cfg: BlogConfig = publishCfg.cfg
const dynCfg: DynamicConfig = publishCfg.dynCfg
Expand Down

0 comments on commit 704241b

Please sign in to comment.