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(export/zip): load script as well
Elian Doran01beebf660c8
diff --git a/apps/server/src/services/export/zip.ts b/apps/server/src/services/export/zip.tsindex 046b7369c5..7034f8e185 100644--- a/apps/server/src/services/export/zip.ts+++ b/apps/server/src/services/export/zip.ts@@ -562,6 +562,7 @@ ${markdownContent}`;const assets = ["style.css",+ "script.js","boxicons.css","boxicons.eot","boxicons.woff2",@@ -654,6 +655,8 @@ function getShareThemeAssets(nameWithExtension: string) {// Rename share.css to style.css.if (nameWithExtension === "style.css") {nameWithExtension = "share.css";+ } else if (nameWithExtension === "script.js") {+ nameWithExtension = "share.js";}let path: string | undefined;diff --git a/apps/server/src/share/content_renderer.ts b/apps/server/src/share/content_renderer.tsindex 346d9743eb..041e5cc175 100644--- a/apps/server/src/share/content_renderer.ts+++ b/apps/server/src/share/content_renderer.ts@@ -17,6 +17,7 @@ import { join } from "path";import { readFileSync } from "fs";const shareAdjustedAssetPath = isDev ? assetPath : `../${assetPath}`;+const shareAdjustedAppPath = isDev ? app_path : `../${app_path}`;/*** Represents the output of the content renderer.@@ -73,6 +74,9 @@ export function renderNoteForExport(note: BNote, parentBranch: BBranch, basePath`${basePath}style.css`,`${basePath}boxicons.css`],+ jsToLoad: [+ `${basePath}script.js`+ ],logoUrl: `${basePath}icon-color.svg`});}@@ -86,12 +90,18 @@ export function renderNoteContent(note: SNote) {cssToLoad.push(`${shareAdjustedAssetPath}/src/share.css`);cssToLoad.push(`${shareAdjustedAssetPath}/src/boxicons.css`);}-- // Support custom CSS too.for (const cssRelation of note.getRelations("shareCss")) {cssToLoad.push(`api/notes/${cssRelation.value}/download`);}+ // Determine JS to load.+ const jsToLoad: string[] = [+ `${shareAdjustedAppPath}/share.js`+ ];+ for (const jsRelation of note.getRelations("shareJs")) {+ jsToLoad.push(`api/notes/${jsRelation.value}/download`);+ }+const customLogoId = note.getRelation("shareLogo")?.value;const logoUrl = customLogoId ? `api/images/${customLogoId}/image.png` : `../${assetUrlFragment}/images/icon-color.svg`;@@ -99,6 +109,7 @@ export function renderNoteContent(note: SNote) {subRoot,rootNoteId: "_share",cssToLoad,+ jsToLoad,logoUrl});}@@ -107,6 +118,7 @@ interface RenderArgs {subRoot: Subroot;rootNoteId: string;cssToLoad: string[];+ jsToLoad: string[];logoUrl: string;}@@ -120,7 +132,7 @@ function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs)isEmpty,assetPath: shareAdjustedAssetPath,assetUrlFragment,- appPath: isDev ? app_path : `../${app_path}`,+ appPath: shareAdjustedAppPath,showLoginInShareTheme,t,isDev,diff --git a/packages/share-theme/src/templates/page.ejs b/packages/share-theme/src/templates/page.ejsindex 8b4609020d..243f788a1d 100644--- a/packages/share-theme/src/templates/page.ejs+++ b/packages/share-theme/src/templates/page.ejs@@ -9,8 +9,8 @@<% for (const url of cssToLoad) { %><link href="<%= url %>" rel="stylesheet"><% } %>- <% for (const jsRelation of note.getRelations("shareJs")) { %>- <script type="module" src="api/notes/<%= jsRelation.value %>/download"></script>+ <% for (const url of jsToLoad) { %>+ <script type="module" src="<%= url %>"></script><% } %><% if (note.hasLabel("shareDisallowRobotIndexing")) { %><meta name="robots" content="noindex,follow" />