feat(share): Render JS Frontend files as-is with extension .js (#8172)

This commit is contained in:
Elian Doran 2025-12-29 20:41:46 +02:00 committed by GitHub
commit 59bbd902fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View File

@ -74,6 +74,7 @@ export default class ShareThemeExportProvider extends ZipExportProvider {
whitespaceCharacters: "\t\r\n\f\u200b\u00a0\u2002"
}) : "";
// TODO: This will probably never match, but should it be exclude from running on code/jsFrontend notes?
content = renderNoteForExport(note, branch, basePath, noteMeta.notePath.slice(0, -1), this.iconPacks);
if (typeof content === "string") {
// Rewrite attachment download links
@ -130,6 +131,10 @@ export default class ShareThemeExportProvider extends ZipExportProvider {
return null;
}
if (mime.startsWith("application/javascript")) {
return "js";
}
// Don't add .html if the file already has .zip extension (for attachments).
if (existingExtension === ".zip") {
return null;

View File

@ -165,6 +165,15 @@ interface RenderArgs {
}
function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs) {
// When rendering static share, non-protected JavaScript notes should be rendered as-is.
if (renderArgs.isStatic && note.mime.startsWith("application/javascript")) {
if (note.isProtected) {
return `console.log("Protected note cannot be exported.");`;
}
return note.getContent() ?? "";
}
const { header, content, isEmpty } = getContent(note);
const showLoginInShareTheme = options.getOption("showLoginInShareTheme");
const opts = {