Skip to content

Commit 07be79c

Browse files
committed
🎨 #17843
1 parent 2f54aef commit 07be79c

6 files changed

Lines changed: 33 additions & 49 deletions

File tree

app/src/block/popover.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {BlockPanel} from "./Panel";
22
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName,} from "../protyle/util/hasClosest";
33
import {fetchPost, fetchSyncPost} from "../util/fetch";
44
import {hideTooltip, showTooltip, tooltipTargetElement} from "../dialog/tooltip";
5-
import {getIdFromSYProtocol, isLocalPath} from "../util/pathName";
5+
import {isLocalPath, parseSiYuanUriInfo} from "../util/pathName";
66
import {App} from "../index";
77
import {Constants} from "../constants";
88
import {getCellText} from "../protyle/render/av/cell";
@@ -459,10 +459,10 @@ export const showPopover = async (app: App, showRef = false) => {
459459
}
460460
} else if (popoverTargetElement.getAttribute("data-type")?.split(" ").includes("a")) {
461461
// 以思源协议开头的链接
462-
refDefs = [{refID: getIdFromSYProtocol(popoverTargetElement.getAttribute("data-href"))}];
462+
refDefs = [{refID: parseSiYuanUriInfo(popoverTargetElement.getAttribute("data-href"))?.id ?? ""}];
463463
} else if (popoverTargetElement.dataset.type === "url") {
464464
// 在 database 的 url 列中以思源协议开头的链接
465-
refDefs = [{refID: getIdFromSYProtocol(popoverTargetElement.textContent.trim())}];
465+
refDefs = [{refID: parseSiYuanUriInfo(popoverTargetElement.textContent.trim())?.id ?? ""}];
466466
} else if (popoverTargetElement.dataset.popoverUrl) {
467467
// 镜像数据库
468468
const postResponse = await fetchSyncPost(popoverTargetElement.dataset.popoverUrl, {avID: popoverTargetElement.dataset.avId});

app/src/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import {fetchGet, fetchPost} from "./util/fetch";
1010
import {
1111
addBaseURL,
1212
getDocDisplayName,
13-
getIdFromSYProtocol,
14-
isSYProtocol,
13+
parseSiYuanUriInfo,
1514
redirectToCheckAuth,
1615
setNoteBook
1716
} from "./util/pathName";
@@ -31,7 +30,7 @@ import {
3130
import {initMessage, showMessage} from "./dialog/message";
3231
import {getAllModels, getAllTabs} from "./layout/getAll";
3332
import {getLocalStorage, isChromeBrowser, isInMobileApp} from "./protyle/util/compatibility";
34-
import {getSearch, isBrowser} from "./util/functions";
33+
import {isBrowser} from "./util/functions";
3534
import {checkPublishServiceClosed} from "./util/processMessage";
3635
import {hideAllElements} from "./protyle/ui/hideElements";
3736
import {loadPlugins, reloadPlugin} from "./plugin/loader";
@@ -276,13 +275,13 @@ export class App {
276275
const siyuanApp = new App();
277276

278277
window.openFileByURL = (openURL) => {
279-
if (openURL && isSYProtocol(openURL)) {
280-
const isZoomIn = getSearch("focus", openURL) === "1";
278+
const blockInfo = parseSiYuanUriInfo(openURL);
279+
if (blockInfo != null) {
281280
openFileById({
282281
app: siyuanApp,
283-
id: getIdFromSYProtocol(openURL),
284-
action: isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
285-
zoomIn: isZoomIn
282+
id: blockInfo.id,
283+
action: blockInfo.focus ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
284+
zoomIn: blockInfo.focus
286285
});
287286
return true;
288287
}

app/src/layout/util.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {Backlink} from "./dock/Backlink";
2222
import {openFileById} from "../editor/util";
2323
import {isWindow} from "../util/functions";
2424
import {showMessage} from "../dialog/message";
25-
import {getIdZoomInByPath} from "../util/pathName";
25+
import {parseUriInfo} from "../util/pathName";
2626
import {Custom} from "./dock/Custom";
2727
import {newCardModel} from "../card/newCardTab";
2828
import {App} from "../index";
@@ -494,13 +494,13 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
494494
}
495495
});
496496

497-
const idZoomIn = getIdZoomInByPath();
498-
if (idZoomIn.id) {
497+
const info = parseUriInfo();
498+
if (info.id) {
499499
openFileById({
500500
app,
501-
id: idZoomIn.id,
502-
action: idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
503-
zoomIn: idZoomIn.isZoomIn,
501+
id: info.id,
502+
action: info.focus ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
503+
zoomIn: info.focus,
504504
});
505505
} else {
506506
let latestTabHeaderElement: HTMLElement;

app/src/mobile/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import {Model} from "../layout/Model";
1212
import "../assets/scss/mobile.scss";
1313
import {Menus} from "../menus";
14-
import {addBaseURL, getIdFromSYProtocol, isSYProtocol, setNoteBook} from "../util/pathName";
14+
import {addBaseURL, parseSiYuanUriInfo, setNoteBook} from "../util/pathName";
1515
import {handleTouchEnd, handleTouchMove, handleTouchStart} from "./util/touch";
1616
import {fetchGet, fetchPost} from "../util/fetch";
1717
import {initFramework} from "./util/initFramework";
@@ -22,7 +22,6 @@ import {goBack} from "./util/MobileBackFoward";
2222
import {activeBlur, hideKeyboardToolbar, showKeyboardToolbar} from "./util/keyboardToolbar";
2323
import {getLocalStorage, isChromeBrowser, isInMobileApp, writeText} from "../protyle/util/compatibility";
2424
import {getCurrentEditor, openMobileFileById} from "./editor";
25-
import {getSearch} from "../util/functions";
2625
import {checkPublishServiceClosed} from "../util/processMessage";
2726
import {initRightMenu} from "./menu";
2827
import {openChangelog} from "../boot/openChangelog";
@@ -244,9 +243,10 @@ window.processIOSPurchaseResponse = processIOSPurchaseResponse;
244243
window.showKeyboardToolbar = showKeyboardToolbar;
245244
window.hideKeyboardToolbar = hideKeyboardToolbar;
246245
window.openFileByURL = (openURL) => {
247-
if (openURL && isSYProtocol(openURL)) {
248-
openMobileFileById(siyuanApp, getIdFromSYProtocol(openURL),
249-
getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
246+
const blockInfo = parseSiYuanUriInfo(openURL);
247+
if (blockInfo != null) {
248+
openMobileFileById(siyuanApp, blockInfo.id,
249+
blockInfo.focus ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
250250
return true;
251251
}
252252
return false;

app/src/mobile/util/initFramework.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {fetchPost} from "../../util/fetch";
77
import {setInlineStyle} from "../../util/assets";
88
import {renderSnippet} from "../../config/util/snippets";
99
import {setEmpty} from "./setEmpty";
10-
import {getIdZoomInByPath, getOpenNotebookCount} from "../../util/pathName";
10+
import {getOpenNotebookCount, parseUriInfo} from "../../util/pathName";
1111
import {popMenu} from "../menu";
1212
import {MobileFiles} from "../dock/MobileFiles";
1313
import {MobileOutline} from "../dock/MobileOutline";
@@ -183,10 +183,10 @@ export const initFramework = (app: App, isStart: boolean) => {
183183
if (window.JSAndroid && window.openFileByURL(window.JSAndroid.getBlockURL())) {
184184
return;
185185
}
186-
const idZoomIn = getIdZoomInByPath();
187-
if (idZoomIn.id) {
188-
openMobileFileById(app, idZoomIn.id,
189-
idZoomIn.isZoomIn ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
186+
const info = parseUriInfo();
187+
if (info.id) {
188+
openMobileFileById(app, info.id,
189+
info.focus ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
190190
return;
191191
}
192192
if (window.siyuan.config.fileTree.closeTabsOnStart && isStart) {

app/src/util/pathName.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,46 +70,31 @@ export const parseSiYuanUriInfo = (uri: URL | string | null | undefined): ISiYua
7070
}
7171
};
7272

73-
export const getIdZoomInByPath = () => {
73+
export const parseUriInfo = () => {
7474
const searchParams = new URLSearchParams(window.location.search);
75-
const data = {
76-
id: "",
77-
isZoomIn: false,
78-
};
7975
const PWAURL = searchParams.get("url");
8076
if (/^web\+siyuan:\/\/blocks\/\d{14}-\w{7}/.test(PWAURL)) {
8177
const dataInfo = parseSiYuanUriInfo(PWAURL);
8278
if (dataInfo != null) {
83-
data.id = dataInfo.id;
84-
data.isZoomIn = dataInfo.focus;
8579
window.siyuan.editorIsFullscreen = dataInfo.fullscreen;
86-
return data;
80+
return dataInfo;
8781
}
8882
}
8983

9084
if (window.JSAndroid) {
9185
const dataInfo = parseSiYuanUriInfo(window.JSAndroid.getBlockURL());
9286
if (dataInfo != null) {
93-
data.id = dataInfo.id;
94-
data.isZoomIn = dataInfo.focus;
9587
window.siyuan.editorIsFullscreen = dataInfo.fullscreen;
96-
return data;
88+
return dataInfo;
9789
}
9890
}
9991

10092
// 支持通过 URL 查询字符串参数 `id` 和 `focus` 跳转到 Web 端指定块 https://github.com/siyuan-note/siyuan/pull/7086
101-
data.id = searchParams.get("id") ?? "";
102-
data.isZoomIn = searchParams.get("focus") === "1";
10393
window.siyuan.editorIsFullscreen = searchParams.get("fullscreen") === "1";
104-
return data;
105-
};
106-
107-
export const isSYProtocol = (url: string) => {
108-
return /^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
109-
};
110-
111-
export const getIdFromSYProtocol = (url: string) => {
112-
return url.substring(16, 16 + 22);
94+
return {
95+
id: searchParams.get("id") ?? "",
96+
focus: searchParams.get("focus") === "1"
97+
};
11398
};
11499

115100
/* redirect to auth page */

0 commit comments

Comments
 (0)