diff --git a/apps/server/src/services/export/zip.ts b/apps/server/src/services/export/zip.ts index 046b7369c..7034f8e18 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.ts index 346d9743e..041e5cc17 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.ejs index 8b4609020..243f788a1 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) { %> <% } %> - <% for (const jsRelation of note.getRelations("shareJs")) { %> - + <% for (const url of jsToLoad) { %> + <% } %> <% if (note.hasLabel("shareDisallowRobotIndexing")) { %>