Open History to see the last commit
1/**
2 * "Try it" opens the app on the screen a guide section is about. If the app is
3 * already on that screen, or on a screen pushed on top of it (a note opened
4 * from that folder), we leave it there, so the app picks up where the reader
5 * left it.
6 */
7export function isOnScreen(pathname: string, screenPathname: string): boolean {
8 const current = withoutTrailingSlash(pathname);
9 const screen = withoutTrailingSlash(screenPathname);
10 if (current === screen) return true;
11 // Every path is "below" the root (Folders), so the root only matches itself.
12 if (screen === "/") return false;
13 return current.startsWith(`${screen}/`);
14}
15
16function withoutTrailingSlash(pathname: string): string {
17 return pathname.length > 1 && pathname.endsWith("/") ? pathname.slice(0, -1) : pathname;
18}