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
refactor(share): move the page's startup script into a partial
Elian Doran0c38b9f20929
diff --git a/apps/standalone/src/lightweight/share_provider.ts b/apps/standalone/src/lightweight/share_provider.tsindex 2d530dd71a..bd48b70615 100644--- a/apps/standalone/src/lightweight/share_provider.ts+++ b/apps/standalone/src/lightweight/share_provider.ts@@ -1,6 +1,7 @@import { getSql } from "@triliumnext/core";import { initShare } from "@triliumnext/core/src/share/index.js";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 templateTocItem from "@triliumnext/share-theme/templates/toc_item.ejs?raw";@@ -12,6 +13,7 @@ import templateTreeItem from "@triliumnext/share-theme/templates/tree_item.ejs?r*/const TEMPLATES: Record<string, string> = {"404": template404,+ boot_script: templateBootScript,page: templatePage,prev_next: templatePrevNext,toc_item: templateTocItem,diff --git a/packages/share-theme/src/templates/boot_script.ejs b/packages/share-theme/src/templates/boot_script.ejsnew file mode 100644index 0000000000..2c68a89001--- /dev/null+++ b/packages/share-theme/src/templates/boot_script.ejs@@ -0,0 +1,20 @@+<script>+ // Load dark/light theme as soon as possible to avoid color flashes.+ let theme = localStorage.getItem("theme");+ if (!theme) {+ theme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? "dark" : "light";+ }+ document.documentElement.classList.add(`theme-${theme}`);++ window.glob = {+ isStatic: <%= !!isStatic %>,+ theme+ };++ (function() {+ const leftCollapsed = localStorage.getItem("left-pane-collapsed") === "true";+ const tocCollapsed = localStorage.getItem("toc-pane-collapsed") === "true";+ if (leftCollapsed) document.documentElement.classList.add("left-pane-collapsed");+ if (tocCollapsed) document.documentElement.classList.add("toc-pane-collapsed");+ })();+</script>diff --git a/packages/share-theme/src/templates/page.ejs b/packages/share-theme/src/templates/page.ejsindex fe3963360f..c7233953e7 100644--- a/packages/share-theme/src/templates/page.ejs+++ b/packages/share-theme/src/templates/page.ejs@@ -17,26 +17,7 @@<meta name="robots" content="noindex,follow" /><% } %><title><%= head.title %></title>- <script>- // Load dark/light theme as soon as possible to avoid color flashes.- let theme = localStorage.getItem("theme");- if (!theme) {- theme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? "dark" : "light";- }- document.documentElement.classList.add(`theme-${theme}`);-- window.glob = {- isStatic: <%= !!isStatic %>,- theme- };-- (function() {- const leftCollapsed = localStorage.getItem("left-pane-collapsed") === "true";- const tocCollapsed = localStorage.getItem("toc-pane-collapsed") === "true";- if (leftCollapsed) document.documentElement.classList.add("left-pane-collapsed");- if (tocCollapsed) document.documentElement.classList.add("toc-pane-collapsed");- })();- </script>+ <%- include("boot_script") %><!-- HTML Meta Tags --><meta name="description" content="<%= head.description %>"><!-- Facebook Meta Tags -->