mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-30 03:32:26 +08:00
fix(link): search from URL not working (closes #1335)
This commit is contained in:
parent
1ba6104e36
commit
79cc1cbf17
9
src/public/app/services/link.spec.ts
Normal file
9
src/public/app/services/link.spec.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { parseNavigationStateFromUrl } from "./link.js";
|
||||||
|
|
||||||
|
describe("Link", () => {
|
||||||
|
it("parses plain searchString", () => {
|
||||||
|
const output = parseNavigationStateFromUrl("http://localhost:8080/#?searchString=hello");
|
||||||
|
expect(output).toMatchObject({ searchString: "hello" });
|
||||||
|
});
|
||||||
|
});
|
@ -198,7 +198,7 @@ function calculateHash({ notePath, ntxId, hoistedNoteId, viewScope = {} }: NoteC
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseNavigationStateFromUrl(url: string | undefined) {
|
export function parseNavigationStateFromUrl(url: string | undefined) {
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -209,11 +209,7 @@ function parseNavigationStateFromUrl(url: string | undefined) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const hash = url.substr(hashIdx + 1); // strip also the initial '#'
|
const hash = url.substr(hashIdx + 1); // strip also the initial '#'
|
||||||
const [notePath, paramString] = hash.split("?");
|
let [notePath, paramString] = hash.split("?");
|
||||||
|
|
||||||
if (!notePath.match(/^[_a-z0-9]{4,}(\/[_a-z0-9]{4,})*$/i)) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
const viewScope: ViewScope = {
|
const viewScope: ViewScope = {
|
||||||
viewMode: "default"
|
viewMode: "default"
|
||||||
@ -242,6 +238,10 @@ function parseNavigationStateFromUrl(url: string | undefined) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!notePath.match(/^[_a-z0-9]{4,}(\/[_a-z0-9]{4,})*$/i)) {
|
||||||
|
return { searchString }
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
notePath,
|
notePath,
|
||||||
noteId: treeService.getNoteIdFromUrl(notePath),
|
noteId: treeService.getNoteIdFromUrl(notePath),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user