Skip to content

Commit

Permalink
fix: 回滚批量分发的覆盖与合并并进行优化
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 25, 2023
1 parent 6f7af83 commit bb6f1e5
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 2 deletions.
55 changes: 53 additions & 2 deletions src/components/publish/BatchPublishIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ const formData = reactive({
// =========================
// sync attrs end
// =========================
distriPattern: DistributionPattern.Merge,
actionEnable: true,
})
Expand Down Expand Up @@ -132,6 +134,21 @@ const handlePublish = async () => {
// 平台相关的元数据初始化
batchItemPost = await initPublishMethods.assignInitAttrs(siyuanPost, id, formData.publishCfg)
// 合并属性
if (formData.distriPattern === DistributionPattern.Override) {
batchItemPost = initPublishMethods.doOverideBatchPost(siyuanPost, batchItemPost)
logger.debug("批量分发模式文章已覆盖", {
siyuanPost: toRaw(siyuanPost),
mergedPost: toRaw(batchItemPost),
})
} else {
batchItemPost = initPublishMethods.doMergeBatchPost(siyuanPost, batchItemPost)
logger.debug("批量分发模式文章已合并", {
siyuanPost: toRaw(siyuanPost),
mergedPost: toRaw(batchItemPost),
})
}
}
const batchResult = await doSinglePublish(key, id, formData.publishCfg, batchItemPost)
Expand Down Expand Up @@ -390,6 +407,32 @@ onMounted(async () => {
v-model:md="formData.siyuanPost.markdown"
v-model:html="formData.siyuanPost.html"
/>

<!-- 分发模式 -->
<div class="distri-type">
<el-form-item label="分发模式">
<el-radio-group v-model="formData.distriPattern" class="ml-4 distri-type-check">
<el-radio :label="DistributionPattern.Override" size="large">覆盖</el-radio>
<el-radio :label="DistributionPattern.Merge" size="large">合并</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item class="distri-tip">
<el-alert
v-if="formData.distriPattern === DistributionPattern.Override"
:closable="false"
:title="t('distri.type.overide.warn')"
class="distri-tip-alert"
type="error"
/>
<el-alert
v-else
:closable="false"
:title="t('distri.type.merge.warn')"
class="distri-tip-alert"
type="warning"
/>
</el-form-item>
</div>
<el-divider border-style="dashed" />

<div v-if="formData.editType === PageEditMode.EditMode_complex" class="complex-mode">
Expand Down Expand Up @@ -479,7 +522,8 @@ onMounted(async () => {
<style lang="stylus" scoped>
.top-tip
margin 10px 0
padding-left 0
padding 6px 0
padding-top 8px
.batch-result
margin 16px 0
Expand Down Expand Up @@ -507,4 +551,11 @@ onMounted(async () => {
.distri-type
:deep(.el-form-item)
margin-bottom -16px
</style>
.distri-type-check
margin-top -3px
.distri-tip
margin-top 10px
.distri-tip-alert
margin 10px 0
padding: 2px 0
</style>
30 changes: 30 additions & 0 deletions src/composables/usePublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ const usePublish = () => {
// 查询平台文章
platformPost = await api.getPost(postid)
// 更新属性
mergedPost.title = platformPost.title
mergedPost.shortDesc = platformPost.shortDesc
mergedPost.mt_keywords = platformPost.mt_keywords
mergedPost.categories = platformPost.categories
Expand All @@ -477,6 +478,35 @@ const usePublish = () => {
postPreviewUrl,
}
},

doOverideBatchPost: (post: Post, newPost: Post): Post => {
// 复制原始 newPost 对象以避免直接修改它
const mergedPost = _.cloneDeep(newPost) as Post

mergedPost.title = post.title
mergedPost.shortDesc = post.shortDesc
mergedPost.mt_keywords = post.mt_keywords
mergedPost.categories = post.categories

return mergedPost
},

doMergeBatchPost: (post: Post, newPost: Post): Post => {
// 复制原始 newPost 对象以避免直接修改它
const mergedPost = _.cloneDeep(newPost) as Post

const postKeywords = post.mt_keywords.split(",")
const newPostKeywords = newPost.mt_keywords.split(",")
// 合并并去重关键词
const mergedKeywords = [...new Set([...postKeywords, ...newPostKeywords])]
mergedPost.mt_keywords = mergedKeywords.join(",")

// 合并并去重分类
const mergedCategories = [...new Set([...post.categories, ...newPost.categories])]
mergedPost.categories = mergedCategories

return mergedPost
},
}

return {
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,4 +582,6 @@ export default {
"sys.config.ai": "AI configuration",
"config.ai.use.siyuan": "Inside Siyuan notes, you can directly use Siyuan notes to configure, no configuration is required",
"setting.blog.yamlLinkEnabled": "YAML permalink",
"distri.type.overide.warn": "Note: Please use caution when overwriting the selected platform with the current data.",
"distri.type.merge.warn": "Note: In merge mode, the title and abstract changes are not valid, and the labels and categories are merged with the selected platform data.",
}
2 changes: 2 additions & 0 deletions src/locales/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,4 +564,6 @@ export default {
"sys.config.ai": "AI设置",
"config.ai.use.siyuan": "思源笔记内部,直接使用思源笔记配置,无需配置",
"setting.blog.yamlLinkEnabled": "YAML永久链接",
"distri.type.overide.warn": "注意:覆盖模式下会用当前数据覆盖所有选择的平台,请谨慎操作。",
"distri.type.merge.warn": "注意:为了保留平台数据,合并模式下,标题和摘要的修改无效,您可在在常规发布单独修改对应平台的标题和摘要,标签和分类会与所选择的平台数据合并。",
}

0 comments on commit bb6f1e5

Please sign in to comment.