mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 11:26:15 +01:00
refactor(share): use a string cache for templates
This commit is contained in:
@@ -51,9 +51,11 @@ export default class ShareThemeExportProvider extends ZipExportProvider {
|
|||||||
|
|
||||||
if (note) {
|
if (note) {
|
||||||
content = renderNoteForExport(note, branch, basePath, noteMeta.notePath.slice(0, -1));
|
content = renderNoteForExport(note, branch, basePath, noteMeta.notePath.slice(0, -1));
|
||||||
|
if (typeof content === "string") {
|
||||||
content = content.replace(/href="[^"]*\.\/([a-zA-Z0-9_\/]{12})[^"]*"/g, "href=\"#root/$1\"");
|
content = content.replace(/href="[^"]*\.\/([a-zA-Z0-9_\/]{12})[^"]*"/g, "href=\"#root/$1\"");
|
||||||
content = this.rewriteFn(content, noteMeta);
|
content = this.rewriteFn(content, noteMeta);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import { readFileSync } from "fs";
|
|||||||
|
|
||||||
const shareAdjustedAssetPath = isDev ? assetPath : `../${assetPath}`;
|
const shareAdjustedAssetPath = isDev ? assetPath : `../${assetPath}`;
|
||||||
const shareAdjustedAppPath = isDev ? app_path : `../${app_path}`;
|
const shareAdjustedAppPath = isDev ? app_path : `../${app_path}`;
|
||||||
|
const templateCache: Map<string, string> = new Map();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the output of the content renderer.
|
* Represents the output of the content renderer.
|
||||||
@@ -194,7 +195,14 @@ function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
function readTemplate(path: string) {
|
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) {
|
function getContent(note: SNote | BNote) {
|
||||||
|
|||||||
Reference in New Issue
Block a user