From a7ed566645862ece56b58915edcb38813ea40d5c Mon Sep 17 00:00:00 2001 From: Zerebos Date: Sat, 8 Jun 2024 14:31:40 -0400 Subject: [PATCH] Improve page performance and rendering - Moves expanding the tree navigation to the template so the rendering is already done before page load - Adds a way to explicitly set the logo size to prevent the page moving after it loads in --- src/scripts/modules/expanders.ts | 22 +++++++++++----------- src/templates/page.ejs | 20 ++++++++++++++++---- src/templates/tree_item.ejs | 8 ++++++-- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/scripts/modules/expanders.ts b/src/scripts/modules/expanders.ts index 276f34507..a1dc6c5d7 100644 --- a/src/scripts/modules/expanders.ts +++ b/src/scripts/modules/expanders.ts @@ -1,15 +1,15 @@ // In case a linked article lead to a new tree -const activeLink = document.querySelector("#menu a.active"); -if (activeLink) { - let parent = activeLink.parentElement; - const mainMenu = document.getElementById("#menu"); - while (parent && parent !== mainMenu) { - if (parent.matches(".submenu-item") && !parent.classList.contains("expanded")) { - parent.classList.add("expanded"); - } - parent = parent.parentElement; - } -} +// const activeLink = document.querySelector("#menu a.active"); +// if (activeLink) { +// let parent = activeLink.parentElement; +// const mainMenu = document.getElementById("#menu"); +// while (parent && parent !== mainMenu) { +// if (parent.matches(".submenu-item") && !parent.classList.contains("expanded")) { +// parent.classList.add("expanded"); +// } +// parent = parent.parentElement; +// } +// } export default function setupExpanders() { const expanders = Array.from(document.querySelectorAll("#menu .submenu-item")); diff --git a/src/templates/page.ejs b/src/templates/page.ejs index 4b9f92bad..e41146228 100644 --- a/src/templates/page.ejs +++ b/src/templates/page.ejs @@ -67,7 +67,7 @@ const customServerYml = `- url: "{protocol}://{domain}:{port}/etapi" let openGraphImage = subRoot.note.getLabelValue("shareOpenGraphImage"); // Relation takes priority and requires some altering if (subRoot.note.hasRelation("shareOpenGraphImage")) { - openGraphImage = `api/images/${subRoot.note.getRelation("shareOpenGraphImage").value}/download`; + openGraphImage = `api/images/${subRoot.note.getRelation("shareOpenGraphImage").value}/image.png`; } %> <%= pageTitle %> @@ -90,6 +90,9 @@ const customServerYml = `- url: "{protocol}://{domain}:{port}/etapi" <% +const logoWidth = subRoot.note.getLabelValue("shareLogoWidth"); +const logoHeight = subRoot.note.getLabelValue("shareLogoHeight"); +const mobileLogoHeight = logoHeight && logoWidth ? 32 / (logoWidth / logoHeight) : ""; const shareRootLink = subRoot.note.hasLabel("shareRootLink") ? subRoot.note.getLabelValue("shareRootLink") : `./${subRoot.note.noteId}`; const currentTheme = note.getLabel("shareTheme") === "light" ? "light" : "dark"; const themeClass = currentTheme === "light" ? " theme-light" : " theme-dark"; @@ -105,7 +108,7 @@ content = content.replaceAll(headingRe, (...match) => {
<% if (subRoot.note.hasRelation("shareLogo")) { %> - /download" alt="Logo" /> + /image.png" width="<%= logoWidth %>" height="<%= mobileLogoHeight %>" alt="Logo" /> <% } %> <%= subRoot.note.title %> @@ -117,7 +120,7 @@ content = content.replaceAll(headingRe, (...match) => { <% if (subRoot.note.hasVisibleChildren()) { %> <% } %>
diff --git a/src/templates/tree_item.ejs b/src/templates/tree_item.ejs index 127c0a364..f39d0d14e 100644 --- a/src/templates/tree_item.ejs +++ b/src/templates/tree_item.ejs @@ -16,8 +16,12 @@ const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : " <% if (note.hasVisibleChildren()) { %>