2024-12-19 22:20:57 +02:00

35 lines
903 B
TypeScript

import server from "./server.js";
import bundleService from "./bundle.js";
import FNote from "../entities/fnote.js";
interface Bundle {
html: string;
}
async function render(note: FNote, $el: JQuery<HTMLElement>) {
const relations = note.getRelations('renderNote');
const renderNoteIds = relations
.map(rel => rel.value)
.filter(noteId => noteId);
$el.empty().toggle(renderNoteIds.length > 0);
for (const renderNoteId of renderNoteIds) {
const bundle = await server.post<Bundle>(`script/bundle/${renderNoteId}`);
const $scriptContainer = $('<div>');
$el.append($scriptContainer);
$scriptContainer.append(bundle.html);
// async so that scripts cannot block trilium execution
bundleService.executeBundle(bundle, note, $scriptContainer);
}
return renderNoteIds.length > 0;
}
export default {
render
}