Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(share): drop the header and the pane toggles on wide screens
Elian Doran28e5e6505ec3
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing.htmlindex 1824396a2a..9cff7c87ae 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing.html@@ -444,8 +444,8 @@ class="admonition note"></table></figure><h3>Customizing logo</h3>-<p>It's possible to adjust the logo which is displayed at the start of the- header.</p>+<p>It's possible to adjust the logo which is displayed above the navigation+ tree (in the header, on a narrow screen).</p><figure class="table"><table><thead>@@ -459,8 +459,8 @@ class="admonition note"><td><code>~shareLogo</code></td><td>Relation set to an image to use as logo. The image must be part of the- share tree (it can be hidden if needed). Without it, the header shows the- icon of the shared root note.</td>+ share tree (it can be hidden if needed). Without it, the logo is the icon+ of the shared root note.</td></tr><tr><td><code>#shareLogoWidth</code>diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.htmlindex ad85ec5143..9c733d91a1 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.html@@ -75,11 +75,11 @@<tr><td><code>logo</code></td>- <td>The site logo in the header: <code>href</code> (<code>#shareRootLink</code>,- otherwise the site's root page), <code>image</code> (the <code>~shareLogo</code> image,- or <code>null</code>), <code>icon</code> (the icon classes of the site's root- note, shown when there is no <code>image</code>), and <code>width</code> and <code>height</code> for- the image.</td>+ <td>The site logo above the navigation tree and, on a narrow screen, in the+ header: <code>href</code> (<code>#shareRootLink</code>, otherwise the site's+ root page), <code>image</code> (the <code>~shareLogo</code> image, or <code>null</code>), <code>icon</code> (the+ icon classes of the site's root note, shown when there is no <code>image</code>),+ and <code>width</code> and <code>height</code> for the image.</td></tr><tr><td><code>navigation</code>diff --git a/apps/standalone/src/lightweight/share_provider.ts b/apps/standalone/src/lightweight/share_provider.tsindex bd48b70615..223428c24a 100644--- a/apps/standalone/src/lightweight/share_provider.ts+++ b/apps/standalone/src/lightweight/share_provider.ts@@ -4,6 +4,7 @@ import template404 from "@triliumnext/share-theme/templates/404.ejs?raw";import templateBootScript from "@triliumnext/share-theme/templates/boot_script.ejs?raw";import templatePage from "@triliumnext/share-theme/templates/page.ejs?raw";import templatePrevNext from "@triliumnext/share-theme/templates/prev_next.ejs?raw";+import templateSiteLogo from "@triliumnext/share-theme/templates/site_logo.ejs?raw";import templateTocItem from "@triliumnext/share-theme/templates/toc_item.ejs?raw";import templateTreeItem from "@triliumnext/share-theme/templates/tree_item.ejs?raw";@@ -16,6 +17,7 @@ const TEMPLATES: Record<string, string> = {boot_script: templateBootScript,page: templatePage,prev_next: templatePrevNext,+ site_logo: templateSiteLogo,toc_item: templateTocItem,tree_item: templateTreeItem};diff --git a/docs/User Guide/User Guide/Advanced Usage/Sharing.md b/docs/User Guide/User Guide/Advanced Usage/Sharing.mdindex 45d4eb6bf0..183efc5d2a 100644--- a/docs/User Guide/User Guide/Advanced Usage/Sharing.md+++ b/docs/User Guide/User Guide/Advanced Usage/Sharing.md@@ -293,11 +293,11 @@ The URL must be absolute and include the scheme (e.g. `https://`).### Customizing logo-It's possible to adjust the logo which is displayed at the start of the header.+It's possible to adjust the logo which is displayed above the navigation tree (in the header, on a narrow screen).| Attribute | Description || --- | --- |-| `~shareLogo` | Relation set to an image to use as logo. The image must be part of the share tree (it can be hidden if needed). Without it, the header shows the icon of the shared root note. |+| `~shareLogo` | Relation set to an image to use as logo. The image must be part of the share tree (it can be hidden if needed). Without it, the logo is the icon of the shared root note. || `#shareLogoWidth` | The width of the logo, as a number without unit. With `#shareLogoHeight`, it sets the proportions of the logo, which is shown 32 pixels wide. Default is `53`. || `#shareLogoHeight` | The height of the logo, as a number without unit. With `#shareLogoWidth`, it sets the proportions of the logo. Default is `40`. || `#shareRootLink` | URL to navigate to when the logo is pressed. |diff --git a/docs/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.md b/docs/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.mdindex 25bfdd4fa6..db4c1ffc1a 100644--- a/docs/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.md+++ b/docs/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.md@@ -31,7 +31,7 @@ Your template is rendered with a context object exposing the note and its render| `header` | Extra HTML to place in the document head for this note (used by some note types). || `isEmpty` | `true` when the note has no content of its own. || `head` | The values of the page's `<head>`: `title` (the note's title, followed by the site's), `description` (`#shareDescription`), `noIndex` (`#shareDisallowRobotIndexing`) and `openGraph` with `url`, `domain`, `image`, `color` and `card` (`summary_large_image` with an image, `summary` without). A value whose label is not set is `null`. `metaTags` lists the description, OpenGraph and Twitter `<meta>` tags of the values that are set, each with `attribute` (`name` or `property`), `key` and `content`. |-| `logo` | The site logo in the header: `href` (`#shareRootLink`, otherwise the site's root page), `image` (the `~shareLogo` image, or `null`), `icon` (the icon classes of the site's root note, shown when there is no `image`), and `width` and `height` for the image. |+| `logo` | The site logo above the navigation tree and, on a narrow screen, in the header: `href` (`#shareRootLink`, otherwise the site's root page), `image` (the `~shareLogo` image, or `null`), `icon` (the icon classes of the site's root note, shown when there is no `image`), and `width` and `height` for the image. || `navigation` | The navigation tree of the site: its visible pages, each with `title`, `href`, `isExternal`, `type`, `icon`, `isActive` (the page being shown), `isExpanded` (that page or one of its ancestors) and `children`. || `contentClasses` | The classes of the content element: `type-<note type>`, `ck-content` for text and Markdown notes, and `no-content` when the note has no content of its own. || `childLinks` | The links to the note's visible children, each with `title`, `href`, `isExternal` and `type`. |diff --git a/packages/share-theme/src/content/mermaid.spec.ts b/packages/share-theme/src/content/mermaid.spec.tsindex ba1eee3e14..043b410aa7 100644--- a/packages/share-theme/src/content/mermaid.spec.ts+++ b/packages/share-theme/src/content/mermaid.spec.ts@@ -51,7 +51,7 @@ describe("setupMermaid", () => {expect(fakeMermaid.render).toHaveBeenLastCalledWith(firstId, "graph TD; A-->B");// A class change that leaves the theme alone does not draw the diagrams again.- document.documentElement.classList.add("left-pane-collapsed");+ document.documentElement.classList.add("menu-open");await Promise.resolve();expect(fakeMermaid.render).toHaveBeenCalledTimes(1);diff --git a/packages/share-theme/src/page/header.css b/packages/share-theme/src/page/header.cssindex c7266b95f0..bffa8ed336 100644--- a/packages/share-theme/src/page/header.css+++ b/packages/share-theme/src/page/header.css@@ -1,24 +1,27 @@#header {background: var(--background-secondary);- display: flex;+ display: none;justify-content: space-between;align-items: center;- padding: 6px calc(var(--page-gutter) + 12px);+ padding: 6px 12px;border-bottom: 1px solid var(--background-highlight);}-#header-logo {+#header-logo,+#site-logo {display: flex;align-items: center;gap: 5px;font-weight: bold;}-#header-logo img {+#header-logo img,+#site-logo img {max-width: 32px;}-#header-logo .tn-icon {+#header-logo .tn-icon,+#site-logo .tn-icon {font-size: 24px;}@@ -37,7 +40,7 @@}.header-button .tn-icon {- font-size: 24px;+ font-size: 32px;}.header-button:hover {@@ -49,7 +52,11 @@}@media (max-width: 48em) {- #header .header-button .tn-icon {- font-size: 32px;+ #header {+ display: flex;+ }++ #site-logo {+ display: none;}}diff --git a/packages/share-theme/src/page/layout.css b/packages/share-theme/src/page/layout.cssindex 1fd7cb0612..8443824326 100644--- a/packages/share-theme/src/page/layout.css+++ b/packages/share-theme/src/page/layout.css@@ -7,12 +7,6 @@ body {flex-direction: column;}-/* `#header` uses the same gutter, so both resolve `100%` against the width of `body`. */-html {- --page-max-width: 90rem;- --page-gutter: max(0px, (100% - var(--page-max-width)) / 2);-}-#split-pane {display: flex;flex-direction: row;@@ -20,7 +14,7 @@ html {flex: 1;overflow-x: hidden;overflow-y: auto;- padding-inline: var(--page-gutter);+ padding-inline: max(0px, (100% - 90rem) / 2);}#left-pane {@@ -34,12 +28,6 @@ html {top: 0;overflow-y: auto;flex-shrink: 0;- transition: width 0.3s ease;-}--.left-pane-collapsed #left-pane {- width: 0;- overflow: hidden;}#right-pane {diff --git a/packages/share-theme/src/page/layout.spec.ts b/packages/share-theme/src/page/layout.spec.tsindex 30a09fdc82..b01220a127 100644--- a/packages/share-theme/src/page/layout.spec.ts+++ b/packages/share-theme/src/page/layout.spec.ts@@ -1,5 +1,5 @@// @vitest-environment happy-dom-import { afterEach, describe, expect, it, vi } from "vitest";+import { afterEach, describe, expect, it } from "vitest";import setupLayout from "./layout.js";@@ -7,35 +7,18 @@ describe("setupLayout", () => {afterEach(() => {document.body.innerHTML = "";document.body.className = "";- document.documentElement.className = "";- localStorage.clear();- vi.unstubAllGlobals();});- it("collapses a pane on a wide screen and remembers it", () => {- vi.stubGlobal("innerWidth", 1024);- renderPage();-- click("left-pane-toggle-button");- expect(document.documentElement.classList.contains("left-pane-collapsed")).toBe(true);- expect(localStorage.getItem("left-pane-collapsed")).toBe("true");-- click("toc-pane-toggle-button");- click("left-pane-toggle-button");- expect(document.documentElement.className).toBe("toc-pane-collapsed");- expect(localStorage.getItem("left-pane-collapsed")).toBe("false");- expect(localStorage.getItem("toc-pane-collapsed")).toBe("true");- });-- it("opens one pane at a time on a narrow screen, closed by the backdrop or a return", () => {- vi.stubGlobal("innerWidth", 768);+ it("opens one pane at a time, closed by the backdrop or a return", () => {renderPage();click("left-pane-toggle-button");expect(document.body.className).toBe("menu-open");click("toc-pane-toggle-button");expect(document.body.className).toBe("toc-open");- expect(localStorage.length).toBe(0);+ click("toc-pane-toggle-button");+ expect(document.body.className).toBe("");+ click("toc-pane-toggle-button");click("mobile-backdrop");expect(document.body.className).toBe("");diff --git a/packages/share-theme/src/page/layout.ts b/packages/share-theme/src/page/layout.tsindex de063f2da6..350fb259c7 100644--- a/packages/share-theme/src/page/layout.ts+++ b/packages/share-theme/src/page/layout.ts@@ -1,10 +1,8 @@import "./layout.css";-const MOBILE_BREAKPOINT = 768; // 48em-export default function setupLayout() {- setupToggle("left-pane-toggle-button", "left-pane-collapsed", "menu-open", "toc-open");- setupToggle("toc-pane-toggle-button", "toc-pane-collapsed", "toc-open", "menu-open");+ setupToggle("left-pane-toggle-button", "menu-open", "toc-open");+ setupToggle("toc-pane-toggle-button", "toc-open", "menu-open");// A listener on the backdrop itself, not on `window`: iOS Safari dispatches no `click` for a// tap on an element it does not consider clickable, and `window` listeners do not count.@@ -22,18 +20,10 @@ export function closeMobileMenus() {document.body.classList.remove("toc-open");}-function setupToggle(buttonId: string, className: string, mobileClass: string, otherMobileClass: string) {- const button = document.getElementById(buttonId);- if (!button) return;-- button.addEventListener("click", () => {- const isMobile = window.innerWidth <= MOBILE_BREAKPOINT;- if (isMobile) {- document.body.classList.toggle(mobileClass);- document.body.classList.remove(otherMobileClass);- } else {- const isCollapsed = document.documentElement.classList.toggle(className);- localStorage.setItem(className, String(isCollapsed));- }+/** Makes a header button, shown on narrow screens only, slide its pane in or out. */+function setupToggle(buttonId: string, openClass: string, otherOpenClass: string) {+ document.getElementById(buttonId)?.addEventListener("click", () => {+ document.body.classList.toggle(openClass);+ document.body.classList.remove(otherOpenClass);});}diff --git a/packages/share-theme/src/page/toc.css b/packages/share-theme/src/page/toc.cssindex 20899d4187..14d489aa72 100644--- a/packages/share-theme/src/page/toc.css+++ b/packages/share-theme/src/page/toc.css@@ -5,7 +5,6 @@position: sticky;top: 0;order: 3;- transition: width 0.3s ease, margin-right 0.3s ease;width: 250px;flex-shrink: 0;max-height: 100vh;@@ -15,16 +14,6 @@background: var(--background-primary);}-.toc-pane-collapsed #toc-pane {- width: 0;- overflow: hidden;-}--.toc-pane-collapsed #toc-pane h3,-.toc-pane-collapsed #toc-pane #toc {- display: none;-}-#toc-pane h3 {text-transform: uppercase;}@@ -135,11 +124,6 @@overflow-y: auto;}- #toc-pane h3,- #toc-pane #toc {- display: block;- }-.toc-open #toc-pane {transform: translateX(0);}diff --git a/packages/share-theme/src/templates/boot_script.ejs b/packages/share-theme/src/templates/boot_script.ejsindex 8a512cfd71..ad9605bfd8 100644--- a/packages/share-theme/src/templates/boot_script.ejs+++ b/packages/share-theme/src/templates/boot_script.ejs@@ -1,5 +1,5 @@<script>- // Applies the theme and the collapsed panes before the first paint, to avoid color flashes. The+ // Applies the theme before the first paint, to avoid color flashes. The// function keeps its names out of the global scope, which `~shareHtml` snippets share.(function () {function read(key) {@@ -19,8 +19,5 @@isStatic: <%= !!isStatic %>,theme};-- if (read("left-pane-collapsed") === "true") root.classList.add("left-pane-collapsed");- if (read("toc-pane-collapsed") === "true") root.classList.add("toc-pane-collapsed");})();</script>diff --git a/packages/share-theme/src/templates/boot_script.spec.ts b/packages/share-theme/src/templates/boot_script.spec.tsindex 7ec5329132..fc3b923f0e 100644--- a/packages/share-theme/src/templates/boot_script.spec.ts+++ b/packages/share-theme/src/templates/boot_script.spec.ts@@ -5,13 +5,12 @@ import { createContext, runInContext } from "node:vm";import { describe, expect, it } from "vitest";describe("boot_script.ejs", () => {- it("applies the stored theme and panes without leaving global names behind", () => {+ it("applies the stored theme without leaving global names behind", () => {const { context, classes } = runBootScript({- "theme": "dark",- "left-pane-collapsed": "true"+ "theme": "dark"});- expect([ ...classes ]).toStrictEqual([ "theme-dark", "left-pane-collapsed" ]);+ expect([ ...classes ]).toStrictEqual([ "theme-dark" ]);expect(context.glob).toEqual({ isStatic: true, theme: "dark" });expect(() => runInContext(`const el = 1; let theme = 2; let root = 3;`, context)).not.toThrow();});diff --git a/packages/share-theme/src/templates/page.ejs b/packages/share-theme/src/templates/page.ejsindex cad2828e50..c0fbcb500b 100644--- a/packages/share-theme/src/templates/page.ejs+++ b/packages/share-theme/src/templates/page.ejs@@ -29,14 +29,7 @@<%- snippets["body:start"] %><div id="header"><button aria-label="<%= t("share_theme.toggle-navigation") %>" id="left-pane-toggle-button" class="header-button"><span class="tn-icon bx bx-menu" aria-hidden="true"></span></button>- <a href="<%= logo.href %>" id="header-logo" class="no-arrow">- <% if (logo.image) { %>- <img src="<%= logo.image %>" width="<%= logo.width %>" height="<%= logo.height %>" alt="<%= t("share_theme.logo-alt") %>" />- <% } else { %>- <span class="tn-icon <%= logo.icon %>" aria-hidden="true"></span>- <% } %>- <%= subRoot.note.title %>- </a>+ <%- include("site_logo", { id: "header-logo" }) %><% if (headings.length > 1) { %><button aria-label="<%= t("share_theme.toggle-toc") %>" id="toc-pane-toggle-button" class="header-button"><span class="tn-icon bx bx-list-ul" aria-hidden="true"></span></button><% } else { %>@@ -47,6 +40,7 @@<div id="left-pane"><div id="navigation"><div id="site-header">+ <%- include("site_logo", { id: "site-logo" }) %><div class="theme-selection"><span id="sitetheme"><%= t("share_theme.site-theme") %></span><label class="switch">diff --git a/packages/share-theme/src/templates/site_logo.ejs b/packages/share-theme/src/templates/site_logo.ejsnew file mode 100644index 0000000000..18971736f0--- /dev/null+++ b/packages/share-theme/src/templates/site_logo.ejs@@ -0,0 +1,8 @@+<a href="<%= logo.href %>" id="<%= id %>" class="site-logo no-arrow">+ <% if (logo.image) { %>+ <img src="<%= logo.image %>" width="<%= logo.width %>" height="<%= logo.height %>" alt="<%= t("share_theme.logo-alt") %>" />+ <% } else { %>+ <span class="tn-icon <%= logo.icon %>" aria-hidden="true"></span>+ <% } %>+ <%= subRoot.note.title %>+</a>diff --git a/packages/trilium-core/src/share/content_renderer.spec.ts b/packages/trilium-core/src/share/content_renderer.spec.tsindex dfe285d42a..3bd8c49f72 100644--- a/packages/trilium-core/src/share/content_renderer.spec.ts+++ b/packages/trilium-core/src/share/content_renderer.spec.ts@@ -1387,6 +1387,7 @@ describe("content_renderer pages", () => {expect(page.querySelector("body")?.getAttribute("data-ancestor-note-id")).toBe(shareRoot.SHARE_ROOT_NOTE_ID);expect(page.querySelector("#header-logo")?.text.trim()).toBe("Everything shared");+ expect(page.querySelector("#site-logo")?.text.trim()).toBe("Everything shared");expect(page.querySelector("#content p")?.text).toBe("Index");});