trilium/src/public/javascripts/services/render.js

29 lines
799 B
JavaScript
Raw Normal View History

2019-10-05 16:55:29 +08:00
import server from "./server.js";
import bundleService from "./bundle.js";
async function render(note, $el, ctx) {
2020-02-03 04:16:20 +08:00
const relations = await note.getRelations('renderNote');
const renderNoteIds = relations
.map(rel => rel.value)
.filter(noteId => noteId);
2019-10-05 16:55:29 +08:00
$el.empty().toggle(renderNoteIds.length > 0);
for (const renderNoteId of renderNoteIds) {
const bundle = await server.get('script/bundle/' + renderNoteId);
const $scriptContainer = $('<div>');
$el.append($scriptContainer);
$scriptContainer.append(bundle.html);
2020-02-03 04:16:20 +08:00
// async so that scripts cannot block trilium execution
bundleService.executeBundle(bundle, note, ctx, $scriptContainer);
2019-10-05 16:55:29 +08:00
}
return renderNoteIds.length > 0;
}
export default {
render
}