mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-27 21:53:55 +08:00
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
This commit is contained in:
parent
2485f20d5c
commit
a7ed566645
@ -1,15 +1,15 @@
|
|||||||
// In case a linked article lead to a new tree
|
// In case a linked article lead to a new tree
|
||||||
const activeLink = document.querySelector("#menu a.active");
|
// const activeLink = document.querySelector("#menu a.active");
|
||||||
if (activeLink) {
|
// if (activeLink) {
|
||||||
let parent = activeLink.parentElement;
|
// let parent = activeLink.parentElement;
|
||||||
const mainMenu = document.getElementById("#menu");
|
// const mainMenu = document.getElementById("#menu");
|
||||||
while (parent && parent !== mainMenu) {
|
// while (parent && parent !== mainMenu) {
|
||||||
if (parent.matches(".submenu-item") && !parent.classList.contains("expanded")) {
|
// if (parent.matches(".submenu-item") && !parent.classList.contains("expanded")) {
|
||||||
parent.classList.add("expanded");
|
// parent.classList.add("expanded");
|
||||||
}
|
// }
|
||||||
parent = parent.parentElement;
|
// parent = parent.parentElement;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
export default function setupExpanders() {
|
export default function setupExpanders() {
|
||||||
const expanders = Array.from(document.querySelectorAll("#menu .submenu-item"));
|
const expanders = Array.from(document.querySelectorAll("#menu .submenu-item"));
|
||||||
|
@ -67,7 +67,7 @@ const customServerYml = `- url: "{protocol}://{domain}:{port}/etapi"
|
|||||||
let openGraphImage = subRoot.note.getLabelValue("shareOpenGraphImage");
|
let openGraphImage = subRoot.note.getLabelValue("shareOpenGraphImage");
|
||||||
// Relation takes priority and requires some altering
|
// Relation takes priority and requires some altering
|
||||||
if (subRoot.note.hasRelation("shareOpenGraphImage")) {
|
if (subRoot.note.hasRelation("shareOpenGraphImage")) {
|
||||||
openGraphImage = `api/images/${subRoot.note.getRelation("shareOpenGraphImage").value}/download`;
|
openGraphImage = `api/images/${subRoot.note.getRelation("shareOpenGraphImage").value}/image.png`;
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
<title><%= pageTitle %></title>
|
<title><%= pageTitle %></title>
|
||||||
@ -90,6 +90,9 @@ const customServerYml = `- url: "{protocol}://{domain}:{port}/etapi"
|
|||||||
<meta name="theme-color" content="<%= openGraphColor %>">
|
<meta name="theme-color" content="<%= openGraphColor %>">
|
||||||
</head>
|
</head>
|
||||||
<%
|
<%
|
||||||
|
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 shareRootLink = subRoot.note.hasLabel("shareRootLink") ? subRoot.note.getLabelValue("shareRootLink") : `./${subRoot.note.noteId}`;
|
||||||
const currentTheme = note.getLabel("shareTheme") === "light" ? "light" : "dark";
|
const currentTheme = note.getLabel("shareTheme") === "light" ? "light" : "dark";
|
||||||
const themeClass = currentTheme === "light" ? " theme-light" : " theme-dark";
|
const themeClass = currentTheme === "light" ? " theme-light" : " theme-dark";
|
||||||
@ -105,7 +108,7 @@ content = content.replaceAll(headingRe, (...match) => {
|
|||||||
<div id="mobile-header">
|
<div id="mobile-header">
|
||||||
<a href="<%= shareRootLink %>">
|
<a href="<%= shareRootLink %>">
|
||||||
<% if (subRoot.note.hasRelation("shareLogo")) { %>
|
<% if (subRoot.note.hasRelation("shareLogo")) { %>
|
||||||
<img src="api/images/<%= subRoot.note.getRelation("shareLogo").value %>/download" alt="Logo" />
|
<img src="api/images/<%= subRoot.note.getRelation("shareLogo").value %>/image.png" width="<%= logoWidth %>" height="<%= mobileLogoHeight %>" alt="Logo" />
|
||||||
<% } %>
|
<% } %>
|
||||||
<%= subRoot.note.title %>
|
<%= subRoot.note.title %>
|
||||||
</a>
|
</a>
|
||||||
@ -117,7 +120,7 @@ content = content.replaceAll(headingRe, (...match) => {
|
|||||||
<div id="site-header">
|
<div id="site-header">
|
||||||
<a href="<%= shareRootLink %>">
|
<a href="<%= shareRootLink %>">
|
||||||
<% if (subRoot.note.hasRelation("shareLogo")) { %>
|
<% if (subRoot.note.hasRelation("shareLogo")) { %>
|
||||||
<img src="api/images/<%= subRoot.note.getRelation("shareLogo").value %>/download" alt="Logo" />
|
<img src="api/images/<%= subRoot.note.getRelation("shareLogo").value %>/image.png" width="<%= logoWidth %>" height="<%= logoHeight %>" alt="Logo" />
|
||||||
<% } %>
|
<% } %>
|
||||||
<%= subRoot.note.title %>
|
<%= subRoot.note.title %>
|
||||||
</a>
|
</a>
|
||||||
@ -137,7 +140,16 @@ content = content.replaceAll(headingRe, (...match) => {
|
|||||||
</div>
|
</div>
|
||||||
<% if (subRoot.note.hasVisibleChildren()) { %>
|
<% if (subRoot.note.hasVisibleChildren()) { %>
|
||||||
<nav id="menu">
|
<nav id="menu">
|
||||||
<%- include("tree_item", {note: subRoot.note, activeNote: note, subRoot: subRoot}) %>
|
<%
|
||||||
|
const ancestors = [];
|
||||||
|
let notePointer = note;
|
||||||
|
while (notePointer.parents[0].noteId !== "_share") {
|
||||||
|
const pointerParent = notePointer.parents[0];
|
||||||
|
ancestors.push(pointerParent.noteId);
|
||||||
|
notePointer = pointerParent;
|
||||||
|
}
|
||||||
|
%>
|
||||||
|
<%- include("tree_item", {note: subRoot.note, activeNote: note, subRoot: subRoot, ancestors: ancestors}) %>
|
||||||
</nav>
|
</nav>
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
@ -16,8 +16,12 @@ const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : "
|
|||||||
<% if (note.hasVisibleChildren()) { %>
|
<% if (note.hasVisibleChildren()) { %>
|
||||||
<ul>
|
<ul>
|
||||||
<% note.getVisibleChildNotes().forEach(function (childNote) { %>
|
<% note.getVisibleChildNotes().forEach(function (childNote) { %>
|
||||||
<% const hasChildren = childNote.hasVisibleChildren(); %>
|
<%
|
||||||
<li class="<% if (hasChildren) { %>submenu-<% } %>item">
|
const hasChildren = childNote.hasVisibleChildren();
|
||||||
|
const isAncestorOfActive = ancestors.some(p => p === childNote.noteId);
|
||||||
|
const expandedClass = isAncestorOfActive ? " expanded" : "";
|
||||||
|
%>
|
||||||
|
<li class="<% if (hasChildren) { %>submenu-<% } %>item<%= expandedClass %>">
|
||||||
<%- include('tree_item', {note: childNote, subRoot: subRoot}) %>
|
<%- include('tree_item', {note: childNote, subRoot: subRoot}) %>
|
||||||
</li>
|
</li>
|
||||||
<% }) %>
|
<% }) %>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user