feat(export/zip): load script as well

This commit is contained in:
Elian Doran
2025-06-14 01:23:02 +03:00
parent d3115e834a
commit 01beebf660
3 changed files with 20 additions and 5 deletions

View File

@@ -562,6 +562,7 @@ ${markdownContent}`;
const assets = [ const assets = [
"style.css", "style.css",
"script.js",
"boxicons.css", "boxicons.css",
"boxicons.eot", "boxicons.eot",
"boxicons.woff2", "boxicons.woff2",
@@ -654,6 +655,8 @@ function getShareThemeAssets(nameWithExtension: string) {
// Rename share.css to style.css. // Rename share.css to style.css.
if (nameWithExtension === "style.css") { if (nameWithExtension === "style.css") {
nameWithExtension = "share.css"; nameWithExtension = "share.css";
} else if (nameWithExtension === "script.js") {
nameWithExtension = "share.js";
} }
let path: string | undefined; let path: string | undefined;

View File

@@ -17,6 +17,7 @@ import { join } from "path";
import { readFileSync } from "fs"; import { readFileSync } from "fs";
const shareAdjustedAssetPath = isDev ? assetPath : `../${assetPath}`; const shareAdjustedAssetPath = isDev ? assetPath : `../${assetPath}`;
const shareAdjustedAppPath = isDev ? app_path : `../${app_path}`;
/** /**
* Represents the output of the content renderer. * Represents the output of the content renderer.
@@ -73,6 +74,9 @@ export function renderNoteForExport(note: BNote, parentBranch: BBranch, basePath
`${basePath}style.css`, `${basePath}style.css`,
`${basePath}boxicons.css` `${basePath}boxicons.css`
], ],
jsToLoad: [
`${basePath}script.js`
],
logoUrl: `${basePath}icon-color.svg` logoUrl: `${basePath}icon-color.svg`
}); });
} }
@@ -86,12 +90,18 @@ export function renderNoteContent(note: SNote) {
cssToLoad.push(`${shareAdjustedAssetPath}/src/share.css`); cssToLoad.push(`${shareAdjustedAssetPath}/src/share.css`);
cssToLoad.push(`${shareAdjustedAssetPath}/src/boxicons.css`); cssToLoad.push(`${shareAdjustedAssetPath}/src/boxicons.css`);
} }
// Support custom CSS too.
for (const cssRelation of note.getRelations("shareCss")) { for (const cssRelation of note.getRelations("shareCss")) {
cssToLoad.push(`api/notes/${cssRelation.value}/download`); 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 customLogoId = note.getRelation("shareLogo")?.value;
const logoUrl = customLogoId ? `api/images/${customLogoId}/image.png` : `../${assetUrlFragment}/images/icon-color.svg`; const logoUrl = customLogoId ? `api/images/${customLogoId}/image.png` : `../${assetUrlFragment}/images/icon-color.svg`;
@@ -99,6 +109,7 @@ export function renderNoteContent(note: SNote) {
subRoot, subRoot,
rootNoteId: "_share", rootNoteId: "_share",
cssToLoad, cssToLoad,
jsToLoad,
logoUrl logoUrl
}); });
} }
@@ -107,6 +118,7 @@ interface RenderArgs {
subRoot: Subroot; subRoot: Subroot;
rootNoteId: string; rootNoteId: string;
cssToLoad: string[]; cssToLoad: string[];
jsToLoad: string[];
logoUrl: string; logoUrl: string;
} }
@@ -120,7 +132,7 @@ function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs)
isEmpty, isEmpty,
assetPath: shareAdjustedAssetPath, assetPath: shareAdjustedAssetPath,
assetUrlFragment, assetUrlFragment,
appPath: isDev ? app_path : `../${app_path}`, appPath: shareAdjustedAppPath,
showLoginInShareTheme, showLoginInShareTheme,
t, t,
isDev, isDev,

View File

@@ -9,8 +9,8 @@
<% for (const url of cssToLoad) { %> <% for (const url of cssToLoad) { %>
<link href="<%= url %>" rel="stylesheet"> <link href="<%= url %>" rel="stylesheet">
<% } %> <% } %>
<% for (const jsRelation of note.getRelations("shareJs")) { %> <% for (const url of jsToLoad) { %>
<script type="module" src="api/notes/<%= jsRelation.value %>/download"></script> <script type="module" src="<%= url %>"></script>
<% } %> <% } %>
<% if (note.hasLabel("shareDisallowRobotIndexing")) { %> <% if (note.hasLabel("shareDisallowRobotIndexing")) { %>
<meta name="robots" content="noindex,follow" /> <meta name="robots" content="noindex,follow" />