Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

first commit 根据url里的id打开特定块 (#7086)

iamqiz77560d6601b5
diff --git a/app/src/util/onGetConfig.ts b/app/src/util/onGetConfig.ts
index 1071bbfe4a..46be67a64e 100644
--- a/app/src/util/onGetConfig.ts
+++ b/app/src/util/onGetConfig.ts
@@ -105,7 +105,16 @@ export const setProxy = () => {
});
/// #endif
};
-
+// 获取 location.search 里特定参数,失败返回false
+function getUrlArg(arg_name: string) {
+ var query = window.location.search.substring(1);
+ var vars = query.split("&");
+ for (var i=0;i<vars.length;i++) {
+ var pair = vars[i].split("=");
+ if(pair[0] == arg_name){return pair[1];}
+ }
+ return false;
+}
export const onGetConfig = (isStart: boolean) => {
const matchKeymap1 = matchKeymap(Constants.SIYUAN_KEYMAP.general, "general");
const matchKeymap2 = matchKeymap(Constants.SIYUAN_KEYMAP.editor.general, "editor", "general");
@@ -179,6 +188,18 @@ export const onGetConfig = (isStart: boolean) => {
mountHelp();
}
addGA();
+ //根据url里的id参数打开相应的块,用于浏览器访问
+ let url_doc_id=getUrlArg("id")
+ if (url_doc_id) {
+ fetchPost("/api/block/getBlockInfo", {id: url_doc_id}, response => {
+ if (response.code === 0 && typeof url_doc_id === "string") {
+ openFileById({
+ id: url_doc_id,
+ action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT,]
+ })
+ }
+ })
+ }
};
const initBar = () => {