Skip to content

Commit

Permalink
fix: #1202 add option for outer link
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Dec 13, 2024
1 parent 249bdad commit d8e3366
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/adaptors/base/baseExtendApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,11 @@ class BaseExtendApi extends WebApi implements IBlogApi, IWebApi {
// eslint-disable-next-line no-prototype-builtins
if (!postMeta.hasOwnProperty(posidKey)) {
outerLink = `siyuan://blocks/${id}`
this.logger.error("引用的文档尚未发布,您可以删除此外链再发布,或者先发布外链文章 =>", id)
throw new Error(`引用的文档 ${id} 尚未发布,您可以删除此外链再发布,或者先发布外链文章`)
// 包括未配置和未勾选
if (pref.value.ignoreBlockRef !== true) {
this.logger.error("引用的文档尚未发布,您可以删除此外链再发布,或者先发布外链文章 =>", id)
throw new Error(`引用的文档 ${id} 尚未发布,您可以删除此外链再发布,或者先发布外链文章`)
}
} else {
let previewUrl: string
const postid = postMeta[posidKey]
Expand Down
3 changes: 3 additions & 0 deletions src/components/set/preference/PreferenceSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ const isSiyuanPlugin = isInSiyuanWin() || (isInSiyuanWidget() && StrUtil.isEmpty
<el-form-item :label="t('preference.setting.showArticleManageMenu')">
<el-switch v-model="publishPreferenceSettingForm.showArticleManageMenu"></el-switch>
</el-form-item>
<el-form-item :label="t('preference.setting.ignoreBlockRef')">
<el-switch v-model="publishPreferenceSettingForm.ignoreBlockRef"></el-switch>
</el-form-item>
</div>
</el-form>
</template>
Expand Down
1 change: 1 addition & 0 deletions src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ export default {
"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.",
"preference.setting.keepTitle": "Do not update the original title",
"preference.setting.ignoreBlockRef": "Ignore block ref",

"setting.blog.gitlab.url.tip": "GitLab homepage, e.g., http://localhost:8002",
"setting.blog.type.gitlab.user.tip": "Username for GitLab",
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ export default {
"preference.setting.showAIMenu": "显示AI菜单",
"preference.setting.showExtendMenu": "显示扩展菜单",
"preference.setting.showArticleManageMenu": "显示文章管理菜单",
"preference.setting.ignoreBlockRef": "忽略块引用",

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

Expand Down
4 changes: 4 additions & 0 deletions src/models/publishPreferenceCfg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class PublishPreferenceCfg extends PreferenceConfig {
// 文章管理
public showArticleManageMenu?: boolean

// 是否忽略块引用
public ignoreBlockRef?: boolean

constructor() {
super()
this.experimentalUseSiyuanNoteAIConfig = true
Expand All @@ -103,6 +106,7 @@ class PublishPreferenceCfg extends PreferenceConfig {
this.showExtendMenu = true

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

Expand Down
17 changes: 12 additions & 5 deletions src/stores/useSiyuanSettingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import { SiyuanConfig } from "zhi-siyuan-api"
import { RemovableRef, StorageSerializers } from "@vueuse/core"
import { readonly } from "vue"
import { SiyuanDevice } from "zhi-device"
import { useSiyuanDevice } from "~/src/composables/useSiyuanDevice.ts"
import useCommonLocalStorage from "~/src/stores/common/useCommonLocalStorage.ts"
import { LEGENCY_SHARED_PROXT_MIDDLEWARE } from "~/src/utils/constants.ts"
import { Utils } from "~/src/utils/utils.ts"
import { StrUtil } from "zhi-common"

/**
* 思源笔记设置
Expand Down Expand Up @@ -57,15 +58,21 @@ const useSiyuanSettingStore = () => {
const win = SiyuanDevice.siyuanWindow()
origin = win?.location.origin

const initialValue = new SiyuanConfig(origin ?? baseUrl, token)
// 顺序
// 1、环境变量
// 2、origin
// 3、默认值
const envSiyuanApiUrl = Utils.emptyOrDefault(process.env.VITE_SIYUAN_API_URL, origin)
const siyuanApiUrl = Utils.emptyOrDefault(envSiyuanApiUrl, baseUrl)
const initialValue = new SiyuanConfig(siyuanApiUrl, token)
initialValue.middlewareUrl = middlewareUrl
const siyuanConfig = useCommonLocalStorage<SiyuanConfig>(filePath, storageKey, initialValue, {
serializer: StorageSerializers.object,
})

// 更新apiUrl
if (origin) {
siyuanConfig.value.apiUrl = origin
// 更新apiUrl,兼容旧数据的情况
if (!StrUtil.isEmptyString(siyuanApiUrl)) {
siyuanConfig.value.apiUrl = siyuanApiUrl
}
return siyuanConfig
}
Expand Down

0 comments on commit d8e3366

Please sign in to comment.