From ad590803079efb9e0421cfc3b202b414742d5156 Mon Sep 17 00:00:00 2001 From: Zack Rauen Date: Sat, 23 Sep 2023 22:39:38 -0400 Subject: [PATCH] Some more finishing touches --- src/main/index.ts | 16 +++++++++++++-- src/main/navigation/toc.ts | 9 +++++++++ src/main/other/opengraph.ts | 40 ------------------------------------- src/styles/mobile.css | 9 +++++++++ src/styles/sidebar.css | 8 ++++++++ 5 files changed, 40 insertions(+), 42 deletions(-) delete mode 100644 src/main/other/opengraph.ts diff --git a/src/main/index.ts b/src/main/index.ts index 33a8966da..88879347b 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -8,13 +8,13 @@ import generateTOC from "./navigation/toc"; import addExternalLinks from "./fixes/externallinks"; import injectSwagger from "./other/swagger"; import makeMobileMenu from "./other/mobile"; -import addOpenGraphMeta from "./other/opengraph"; const ETAPI_REF_NOTE_ID = "pPIXi0uwF5GX"; const HIDDEN_SUBMENUS = ["blog"]; const EXTERNAL_LINKS = { EGFtX8Uw96FQ: "https://github.com/zadam/trilium", + dXAKFE0fJtom: "https://discord.gg/eTaTXUgcBr" }; const ALIASES = { WqBnya4Ye8rS: "", @@ -58,4 +58,16 @@ $try(generateTOC); $try(highlight); $try(injectSwagger, ETAPI_REF_NOTE_ID); $try(makeMobileMenu); -$try(addOpenGraphMeta); + +/** + * This was removed because both the title change and the opengraph + * additions are now handled by a traefik plugin that rewrites + * the body of the http request, that way the change does not + * require client-side JS. This is important for sites wishing + * to display that information. + * + * TODO: Determine how reasonable it would be to move more + * of these modules over to a traefik rewrite plugin. This gives + * a better experience to end users, SEO, etc. + */ +// $try(addOpenGraphMeta); diff --git a/src/main/navigation/toc.ts b/src/main/navigation/toc.ts index 89f46bfa9..052da9583 100644 --- a/src/main/navigation/toc.ts +++ b/src/main/navigation/toc.ts @@ -14,6 +14,15 @@ const buildItem = (heading: Element) => { const link = document.createElement("a"); link.setAttribute("href", `#${slug}`); link.textContent = heading.textContent; + link.addEventListener("click", e => { + const target = document.querySelector(`#${slug}`); + if (!target) return; + + e.preventDefault(); + e.stopPropagation(); + + target.scrollIntoView({behavior: "smooth"}); + }); heading.append(anchor); diff --git a/src/main/other/opengraph.ts b/src/main/other/opengraph.ts deleted file mode 100644 index c9fb88844..000000000 --- a/src/main/other/opengraph.ts +++ /dev/null @@ -1,40 +0,0 @@ -// TODO: move to common location -const parseHTML = (html: string, fragment = false) => { - const template = document.createElement("template"); - template.innerHTML = html; - const node = template.content.cloneNode(true); - if (fragment) return node; - return node.childNodes.length > 1 ? node.childNodes : node.childNodes[0]; -}; - - -// TODO: See if there's a way to inject this without client-side js -const metaString = ` - - - - - - - - - - - - - - - - - -`; - - -export default function addOpenGraphMeta() { - const currentTitle = document.querySelector("title")!; - currentTitle.textContent = currentTitle.textContent === "Trilium Rocks" ? "Trilium Rocks - Home" : `Trilium Rocks - ${currentTitle.textContent}`; - const nodes = parseHTML(metaString.replaceAll("{{title}}", currentTitle.textContent)) as NodeListOf; - for (const node of nodes) { - document.head.append(node); - } -} \ No newline at end of file diff --git a/src/styles/mobile.css b/src/styles/mobile.css index 408d677b6..967ee166a 100644 --- a/src/styles/mobile.css +++ b/src/styles/mobile.css @@ -145,4 +145,13 @@ button.expand { #menu > ul:not(#sidebar) ul { margin-left: 20px; } + + #menu > ul:not(#sidebar) ul { + margin-left: 20px; + } + + #menu > ul:not(#sidebar) a.active { + background: var(--accent-color); + border-radius: 6px; + } } \ No newline at end of file diff --git a/src/styles/sidebar.css b/src/styles/sidebar.css index 3a2b099ba..acf97f222 100644 --- a/src/styles/sidebar.css +++ b/src/styles/sidebar.css @@ -55,4 +55,12 @@ #sidebar > li > ul.hasSubmenu, #sidebar > li > ul > li.submenu-item + li.submenu-item { margin-top: 20px; +} + +#sidebar a.active, +#sidebar > li > ul > li.submenu-item > p > a.active { + background: var(--accent-color); + /* background: rgba(255, 255, 255, 0.1); */ + color: var(--text-heading); + font-weight: 700; } \ No newline at end of file