Skip to content

Commit

Permalink
fix: #1530 add option for slug change
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Dec 16, 2024
1 parent e246f27 commit 16c0c16
Show file tree
Hide file tree
Showing 28 changed files with 87 additions and 28 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@types/crypto-js": "^4.2.2",
"@types/iframe-resizer": "^3.5.13",
"@types/katex": "^0.16.7",
"@types/lodash-es": "^4.17.12",
"@types/minimist": "^1.2.5",
"@types/node": "^18.19.68",
"@vitejs/plugin-vue": "^5.2.1",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/adaptors/api/gitlab-hexo/gitlabhexoApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import { GitlabhexoYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-hexo/gitlabhexoYamlConverterAdaptor.ts"
import { CommonGitlabApiAdaptor } from "~/src/adaptors/api/base/gitlab/commonGitlabApiAdaptor.ts"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { YamlUtil } from "zhi-common"

/**
Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/api/gitlab-hugo/gitlabhugoApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import { CommonGitlabApiAdaptor } from "~/src/adaptors/api/base/gitlab/commonGitlabApiAdaptor.ts"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { GitlabhugoYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-hugo/gitlabhugoYamlConverterAdaptor.ts"
import { YamlUtil } from "zhi-common"

Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/api/gitlab-jekyll/gitlabjekyllApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import { CommonGitlabApiAdaptor } from "~/src/adaptors/api/base/gitlab/commonGitlabApiAdaptor.ts"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { GitlabjekyllYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-jekyll/gitlabjekyllYamlConverterAdaptor.ts"
import { YamlUtil } from "zhi-common"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import { GitlabvitepressYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-vitepress/gitlabvitepressYamlConverterAdaptor.ts"
import { CommonGitlabApiAdaptor } from "~/src/adaptors/api/base/gitlab/commonGitlabApiAdaptor.ts"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { YamlUtil } from "zhi-common"

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import { CommonGitlabApiAdaptor } from "~/src/adaptors/api/base/gitlab/commonGitlabApiAdaptor.ts"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { GitlabvuepressYamlConverterAdaptor } from "~/src/adaptors/api/gitlab-vuepress/gitlabvuepressYamlConverterAdaptor.ts"
import { YamlUtil } from "zhi-common"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import { Gitlabvuepress2YamlConverterAdaptor } from "~/src/adaptors/api/gitlab-vuepress2/gitlabvuepress2YamlConverterAdaptor.ts"
import { CommonGitlabApiAdaptor } from "~/src/adaptors/api/base/gitlab/commonGitlabApiAdaptor.ts"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { YamlUtil } from "zhi-common"

/**
Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/api/hexo/hexoApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import { CommonGithubApiAdaptor } from "~/src/adaptors/api/base/github/commonGithubApiAdaptor.ts"
import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import { HexoYamlConverterAdaptor } from "~/src/adaptors/api/hexo/hexoYamlConverterAdaptor.ts"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { YamlUtil } from "zhi-common"

/**
Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/api/hugo/hugoApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import { CommonGithubApiAdaptor } from "~/src/adaptors/api/base/github/commonGithubApiAdaptor.ts"
import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { HugoYamlConverterAdaptor } from "~/src/adaptors/api/hugo/hugoYamlConverterAdaptor.ts"
import {YamlUtil} from "zhi-common";

Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/api/jekyll/jekyllApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import { CommonGithubApiAdaptor } from "~/src/adaptors/api/base/github/commonGithubApiAdaptor.ts"
import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { JekyllYamlConverterAdaptor } from "~/src/adaptors/api/jekyll/jekyllYamlConverterAdaptor.ts"
import { YamlUtil } from "zhi-common"

Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/api/vitepress/vitepressApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import { CommonGithubApiAdaptor } from "~/src/adaptors/api/base/github/commonGithubApiAdaptor.ts"
import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import { VitepressYamlConverterAdaptor } from "~/src/adaptors/api/vitepress/vitepressYamlConverterAdaptor.ts"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { YamlUtil } from "zhi-common"

/**
Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/api/vuepress/vuepressApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import { CommonGithubApiAdaptor } from "~/src/adaptors/api/base/github/commonGithubApiAdaptor.ts"
import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { VuepressYamlConverterAdaptor } from "~/src/adaptors/api/vuepress/vuepressYamlConverterAdaptor.ts"
import { YamlUtil } from "zhi-common"

Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/api/vuepress2/vuepress2ApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import { CommonGithubApiAdaptor } from "~/src/adaptors/api/base/github/commonGithubApiAdaptor.ts"
import { BlogConfig, PageTypeEnum, Post, YamlConvertAdaptor } from "zhi-blog-api"
import { Vuepress2YamlConverterAdaptor } from "~/src/adaptors/api/vuepress2/vuepress2YamlConverterAdaptor.ts"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { YamlUtil } from "zhi-common"

/**
Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/base/baseExtendApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { SiyuanAttr, SiyuanKernelApi } from "zhi-siyuan-api"
import { DynamicConfig, getDynPlatformKeyFromPostidKey } from "~/src/platforms/dynamicConfig.ts"
import { CATE_AUTO_NAME } from "~/src/utils/constants.ts"
import { toRaw } from "vue"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { usePreferenceSettingStore } from "~/src/stores/usePreferenceSettingStore.ts"
import { SypConfig } from "~/syp.config.ts"
import { usePlatformMetadataStore } from "~/src/stores/usePlatformMetadataStore.ts"
Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/web/csdn/csdnWebAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { BaseWebApi } from "~/src/adaptors/web/base/baseWebApi.ts"
import CsdnUtils from "~/src/adaptors/web/csdn/csdnUtils.ts"
import { BlogConfig, CategoryInfo, MediaObject, PageTypeEnum, Post, UserBlog } from "zhi-blog-api"
import WebUtils from "~/src/adaptors/web/base/webUtils.ts"
import _ from "lodash-es"
import * as _ from "lodash-es"
import FormDataUtils from "~/src/utils/FormDataUtils.ts"

/**
Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/web/wechat/wechatWebAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import * as cheerio from "cheerio"
import { HtmlUtil, JsonUtil, ObjectUtil, StrUtil } from "zhi-common"
import { BlogConfig, MediaObject, PageTypeEnum, Post, UserBlog } from "zhi-blog-api"
import { toRaw } from "vue"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { fileToBuffer } from "~/src/utils/polyfillUtils.ts"
import {MockBrowser} from "~/src/utils/MockBrowser.ts";

Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/web/zhihu/zhihuWebAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { JsonUtil, ObjectUtil, StrUtil } from "zhi-common"
import CryptoJS from "crypto-js"
import { arrayToBuffer } from "~/src/utils/polyfillUtils.ts"
import { getAliOssClient } from "~/src/vendors/alioss/s3oss.ts"
import _ from "lodash-es"
import * as _ from "lodash-es"
import ZhihuUtils from "~/src/adaptors/web/zhihu/zhihuUtils.ts"
import { MockBrowser } from "~/src/utils/MockBrowser.ts"

Expand Down
11 changes: 9 additions & 2 deletions src/components/publish/BatchPublishIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ import PublishTime from "~/src/components/publish/form/PublishTime.vue"
import { ICategoryConfig } from "~/src/types/ICategoryConfig.ts"
import { SiyuanAttr } from "zhi-siyuan-api"
import { DistributionPattern } from "~/src/models/distributionPattern.ts"
import _ from "lodash-es"
import * as _ from "lodash-es"
import PublishTitle from "~/src/components/publish/form/PublishTitle.vue"
import { useChatGPT } from "~/src/composables/useChatGPT.ts"
import { useLoadingTimer } from "~/src/composables/useLoadingTimer.ts"
import { usePreferenceSettingStore } from "~/src/stores/usePreferenceSettingStore.ts"

const logger = createAppLogger("publisher-index")

Expand All @@ -65,6 +66,7 @@ const { doSinglePublish, doSingleDelete, doForceSingleDelete, initPublishMethods
const { blogApi } = useSiyuanApi()
const { getPublishCfg } = usePublishConfig()
const { kernelApi } = useSiyuanApi()
const { getReadOnlyPublishPreferenceSetting } = usePreferenceSettingStore()

// datas
const sysKeys = pre.systemCfg.map((item) => {
Expand Down Expand Up @@ -106,6 +108,11 @@ const formData = reactive({
// sync attrs end
// =========================

// 系统偏好设置-全局配置,非篇文章独有
// 单篇文章配置是publishCfg的cfg
// 单个平台配置是publishCfg的dynCfg
pref: getReadOnlyPublishPreferenceSetting(),

distriPattern: DistributionPattern.Merge,
actionEnable: true,
})
Expand Down Expand Up @@ -469,7 +476,7 @@ onMounted(async () => {

<!-- 别名 -->
<el-form-item :label="t('main.slug')">
<el-input v-model="formData.siyuanPost.wp_slug" :disabled="true" />
<el-input v-model="formData.siyuanPost.wp_slug" :disabled="formData.pref?.allowChangeSlug !== true" />
</el-form-item>

<!-- 摘要 -->
Expand Down
15 changes: 13 additions & 2 deletions src/components/publish/SinglePublishDoPublish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ import PublishKnowledgeSpace from "~/src/components/publish/form/PublishKnowledg
import { SiyuanAttr } from "zhi-siyuan-api"
import PublishTitle from "~/src/components/publish/form/PublishTitle.vue"
import { useChatGPT } from "~/src/composables/useChatGPT.ts"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { useLoadingTimer } from "~/src/composables/useLoadingTimer.ts"
import PageUtils from "~/common/pageUtils.ts"
import { ITagConfig } from "~/src/types/ITagConfig.ts"
import { usePreferenceSettingStore } from "~/src/stores/usePreferenceSettingStore.ts"

const logger = createAppLogger("single-publish-do-publish")

Expand All @@ -63,6 +64,7 @@ const { kernelApi } = useSiyuanApi()
const { doSinglePublish, doSingleDelete, initPublishMethods, doForceSingleDelete } = usePublish()
const router = useRouter()
const { getPublishCfg } = usePublishConfig()
const { getReadOnlyPublishPreferenceSetting } = usePreferenceSettingStore()

// datas
const sysKeys = pre.systemCfg.map((item) => {
Expand Down Expand Up @@ -107,6 +109,11 @@ const formData = reactive({
// sync attrs end
// =========================

// 系统偏好设置-全局配置,非篇文章独有
// 单篇文章配置是publishCfg的cfg
// 单个平台配置是publishCfg的dynCfg
pref: getReadOnlyPublishPreferenceSetting(),

actionEnable: true,
})

Expand Down Expand Up @@ -420,6 +427,7 @@ onMounted(async () => {
// ==================
// 初始化属性
formData.publishCfg = await getPublishCfg(key)
debugger
// 单篇文章初始化
await initPage()
// 元数据初始化
Expand Down Expand Up @@ -553,7 +561,10 @@ onMounted(async () => {

<!-- 别名字段 -->
<el-form-item :label="t('main.slug')">
<el-input v-model="formData.mergedPost.wp_slug" :disabled="true" />
<el-input
v-model="formData.mergedPost.wp_slug"
:disabled="formData.pref?.allowChangeSlug !== true"
/>
</el-form-item>

<!-- 摘要 -->
Expand Down
34 changes: 31 additions & 3 deletions src/components/set/preference/PreferenceSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,41 @@
- questions.
-->

<!--suppress ALL -->
<script setup lang="ts">
import { useVueI18n } from "~/src/composables/useVueI18n.ts"
import { usePreferenceSettingStore } from "~/src/stores/usePreferenceSettingStore.ts"
import { useSiyuanDevice } from "~/src/composables/useSiyuanDevice.ts"
import { StrUtil } from "zhi-common"
import { getSiyuanWidgetId } from "~/src/utils/siyuanUtils.ts"
import { createAppLogger } from "~/src/utils/appLogger.ts"
import { ElMessageBox, type MessageBoxData } from "element-plus"
import { markRaw } from "vue"
import { WarnTriangleFilled } from "@element-plus/icons-vue"

const logger = createAppLogger("preference-setting")
const { t } = useVueI18n()
const { getPublishPreferenceSetting } = usePreferenceSettingStore()
const { isInSiyuanWin, isInSiyuanWidget } = useSiyuanDevice()

const publishPreferenceSettingForm = getPublishPreferenceSetting()
const isSiyuanPlugin = isInSiyuanWin() || (isInSiyuanWidget() && StrUtil.isEmptyString(getSiyuanWidgetId()))

const onBeforeChange = (): boolean | Promise<boolean> => {
return doBeforeChange()
}

const doBeforeChange = async (): Promise<boolean> => {
const result = await ElMessageBox.confirm(t("preference.setting.allowChangeSlug.tips"), {
type: "error",
icon: markRaw(WarnTriangleFilled),
confirmButtonText: t("main.opt.ok"),
cancelButtonText: t("main.opt.cancel"),
} as any)
logger.debug("confirm result=>", result)
debugger
return result === "confirm"
}
</script>

<template>
Expand All @@ -59,9 +81,6 @@ const isSiyuanPlugin = isInSiyuanWin() || (isInSiyuanWidget() && StrUtil.isEmpty
<el-form-item :label="t('preference.setting.showDocQuickMenu')">
<el-switch v-model="publishPreferenceSettingForm.showDocQuickMenu"></el-switch>
</el-form-item>

<el-divider border-style="dashed" class="psd" />

<el-form-item :label="t('preference.setting.showQuickMenu')">
<el-switch v-model="publishPreferenceSettingForm.showQuickMenu"></el-switch>
</el-form-item>
Expand All @@ -71,6 +90,9 @@ const isSiyuanPlugin = isInSiyuanWin() || (isInSiyuanWidget() && StrUtil.isEmpty
<el-form-item :label="t('preference.setting.showBatchMenu')">
<el-switch v-model="publishPreferenceSettingForm.showBatchMenu"></el-switch>
</el-form-item>

<el-divider border-style="dashed" class="psd" />

<el-form-item :label="t('preference.setting.showAIMenu')">
<el-switch v-model="publishPreferenceSettingForm.showAIMenu"></el-switch>
</el-form-item>
Expand All @@ -83,6 +105,12 @@ const isSiyuanPlugin = isInSiyuanWin() || (isInSiyuanWidget() && StrUtil.isEmpty
<el-form-item :label="t('preference.setting.ignoreBlockRef')">
<el-switch v-model="publishPreferenceSettingForm.ignoreBlockRef"></el-switch>
</el-form-item>

<el-divider border-style="dashed" class="psd" />

<el-form-item :label="t('preference.setting.allowChangeSlug')">
<el-switch v-model="publishPreferenceSettingForm.allowChangeSlug" :before-change="onBeforeChange"></el-switch>
</el-form-item>
</div>
</el-form>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { DYNAMIC_CONFIG_KEY } from "~/src/utils/constants.ts"
import { DateUtil, JsonUtil, StrUtil } from "zhi-common"
import { markRaw, onMounted, reactive, ref } from "vue"
import { SypConfig } from "~/syp.config.ts"
import _ from "lodash-es"
import * as _ from "lodash-es"
import { pre } from "~/src/platforms/pre.ts"
import { usePublishSettingStore } from "~/src/stores/usePublishSettingStore.ts"
import { createAppLogger } from "~/src/utils/appLogger.ts"
Expand Down
2 changes: 1 addition & 1 deletion src/composables/usePublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { IPublishCfg } from "~/src/types/IPublishCfg.ts"
import { usePublishConfig } from "~/src/composables/usePublishConfig.ts"
import { ElMessage } from "element-plus"
import { SiyuanAttr } from "zhi-siyuan-api"
import _ from "lodash-es"
import * as _ from "lodash-es"
import Adaptors from "~/src/adaptors"
import { usePlatformMetadataStore } from "~/src/stores/usePlatformMetadataStore.ts"

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 @@ -655,6 +655,8 @@ export default {
"Note: In merge mode, the title and abstract changes are not valid, and the labels and categories are merged with the selected platform data.",
"preference.setting.keepTitle": "Do not update the original title",
"preference.setting.ignoreBlockRef": "Ignore block ref",
"preference.setting.allowChangeSlug": "Allow changing slug",
"preference.setting.allowChangeSlug.tips": "Warning, the slug is the unique identifier for publishing articles across platforms. If you allow changes, please ensure its uniqueness to avoid publication failure. If you are unsure about this feature, use the default auto-generated slug",

"setting.blog.gitlab.url.tip": "GitLab homepage, e.g., http://localhost:8002",
"setting.blog.type.gitlab.user.tip": "Username for GitLab",
Expand Down
6 changes: 5 additions & 1 deletion src/locales/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ export default {
"setting.blog.type.github.site": "作者主页",
"setting.blog.type.github.site.tip": "作者主页,如果为空默认为:[GitHub地址]/[用户名]",
"setting.blog.type.github.dyn.yaml": "YAML预设配置",
"setting.blog.type.github.dyn.yaml.tip": "YAML预设配置,如果您不了解是干什么的请不要配置,JSON格式,例如:{\"sidebar\": false}。这个配置会覆盖当前平台的默认配置。如果需要使用默认的就留空即可。",
"setting.blog.type.github.dyn.yaml.tip":
'YAML预设配置,如果您不了解是干什么的请不要配置,JSON格式,例如:{"sidebar": false}。这个配置会覆盖当前平台的默认配置。如果需要使用默认的就留空即可。',
"setting.blog.url": "博客网址",
"setting.blog.github.url.tip": "Github首页地址",
"setting.blog.username": "账号",
Expand Down Expand Up @@ -648,6 +649,9 @@ export default {
"preference.setting.showExtendMenu": "显示扩展菜单",
"preference.setting.showArticleManageMenu": "显示文章管理菜单",
"preference.setting.ignoreBlockRef": "忽略块引用",
"preference.setting.allowChangeSlug": "允许修改别名",
"preference.setting.allowChangeSlug.tips":
"警告,别名是文章的唯一标记,如果允许修改,请自行保证唯一性,否则文章会发布失败。如果你不清楚此功能,请使用默认的自动生成的别名",

"message.publish.notShared": "文章尚未分享,无法在外部查看。请分享文章或者在PC 客户端内部通过插件菜单进行预览。",

Expand Down
3 changes: 3 additions & 0 deletions src/models/publishPreferenceCfg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class PublishPreferenceCfg extends PreferenceConfig {

// 是否忽略块引用
public ignoreBlockRef?: boolean
// 是否允许修改别名
public allowChangeSlug?: boolean

constructor() {
super()
Expand All @@ -107,6 +109,7 @@ class PublishPreferenceCfg extends PreferenceConfig {

this.showArticleManageMenu = true
this.ignoreBlockRef = false
this.allowChangeSlug = false
}
}

Expand Down
Loading

0 comments on commit 16c0c16

Please sign in to comment.