refactor(share): use a string cache for templates

This commit is contained in:
Elian Doran
2025-06-24 18:08:29 +03:00
parent bc4643fed2
commit 3a55490bbf
2 changed files with 13 additions and 3 deletions

View File

@@ -51,8 +51,10 @@ export default class ShareThemeExportProvider extends ZipExportProvider {
if (note) {
content = renderNoteForExport(note, branch, basePath, noteMeta.notePath.slice(0, -1));
content = content.replace(/href="[^"]*\.\/([a-zA-Z0-9_\/]{12})[^"]*"/g, "href=\"#root/$1\"");
content = this.rewriteFn(content, noteMeta);
if (typeof content === "string") {
content = content.replace(/href="[^"]*\.\/([a-zA-Z0-9_\/]{12})[^"]*"/g, "href=\"#root/$1\"");
content = this.rewriteFn(content, noteMeta);
}
}
return content;

View File

@@ -18,6 +18,7 @@ import { readFileSync } from "fs";
const shareAdjustedAssetPath = isDev ? assetPath : `../${assetPath}`;
const shareAdjustedAppPath = isDev ? app_path : `../${app_path}`;
const templateCache: Map<string, string> = new Map();
/**
* Represents the output of the content renderer.
@@ -194,7 +195,14 @@ function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs)
}
function readTemplate(path: string) {
return readFileSync(path, "utf-8");
const cachedTemplate = templateCache.get(path);
if (cachedTemplate) {
return cachedTemplate;
}
const templateString = readFileSync(path, "utf-8");
templateCache.set(path, templateString);
return templateString;
}
function getContent(note: SNote | BNote) {