mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	inclusion of scripts based on script environment
This commit is contained in:
		| @@ -60,7 +60,7 @@ async function getRenderScript(note) { | ||||
|         + bundle.html; | ||||
| } | ||||
|  | ||||
| async function getScriptBundle(note, includedNoteIds = []) { | ||||
| async function getScriptBundle(note, scriptEnv, includedNoteIds = []) { | ||||
|     if (!note.isJavaScript() && !note.isHtml() && note.type !== 'render') { | ||||
|         return; | ||||
|     } | ||||
| @@ -69,6 +69,10 @@ async function getScriptBundle(note, includedNoteIds = []) { | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     if (!scriptEnv) { | ||||
|         scriptEnv = note.getScriptEnv(); | ||||
|     } | ||||
|  | ||||
|     const bundle = { | ||||
|         note: note, | ||||
|         script: '', | ||||
| @@ -82,10 +86,16 @@ async function getScriptBundle(note, includedNoteIds = []) { | ||||
|  | ||||
|     includedNoteIds.push(note.noteId); | ||||
|  | ||||
|     bundle.script = `api.__modules['${note.noteId}'] = { __noteId: '${note.noteId}', __env: '${note.getScriptEnv()}'};`; | ||||
|  | ||||
|     if (note.type !== 'file' && scriptEnv !== note.getScriptEnv()) { | ||||
|         return bundle; | ||||
|     } | ||||
|  | ||||
|     const modules = []; | ||||
|  | ||||
|     for (const child of await note.getChildren()) { | ||||
|         const childBundle = await getScriptBundle(child, includedNoteIds); | ||||
|         const childBundle = await getScriptBundle(child, scriptEnv, includedNoteIds); | ||||
|  | ||||
|         if (childBundle) { | ||||
|             modules.push(childBundle.note); | ||||
| @@ -97,7 +107,6 @@ async function getScriptBundle(note, includedNoteIds = []) { | ||||
|  | ||||
|     if (note.isJavaScript()) { | ||||
|         bundle.script += ` | ||||
| api.__modules['${note.noteId}'] = {}; | ||||
| await (async function(exports, module, api, startNote, currentNote` + (modules.length > 0 ? ', ' : '') + | ||||
|             modules.map(child => child.title).join(', ') + `) { | ||||
| ${note.content} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user