Created
          July 31, 2022 19:32 
        
      - 
      
- 
        Save GitMurf/fa9043565ca83ee94cf1783008ad7be5 to your computer and use it in GitHub Desktop. 
Revisions
- 
        GitMurf created this gist Jul 31, 2022 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ <%* // v0.1 /* START OF USER DEFINED SETTINGS */ // template to use const templateFolder = "templates"; const templateName = "template_anthony.md"; // creating the new file const newFileFolder = "test/meetings"; const openNewFile = false; const replaceWithLink = true; const embedLink = false; // other settings const newFileNamePrefix = `${tp.date.now('YYYY-MM-DD')} `; /* END OF USER DEFINED SETTINGS */ // replace trailing and leading slashes const cleanTemplateFolder = templateFolder.replace(/^\//, "").replace(/\/$/, ""); const templateLocation = `${cleanTemplateFolder}/${templateName}`; const foundFile = app.vault.getAbstractFileByPath(templateLocation); if(!foundFile) { new Notice(`Could not find the Template: ${templateLocation}`, 5000); return; } // replace trailing and leading slashes const cleanNewFolder = newFileFolder.replace(/^\//, "").replace(/\/$/, ""); const foundFolder = app.vault.getAbstractFileByPath(cleanNewFolder); if(!foundFolder) { new Notice(`Could not find the Folder: ${cleanNewFolder}`, 5000); return; } const cmEditorAct = app.workspace.activeLeaf.view.editor; // if nothing is selected then select the current active line and use it if(tp.file.selection() === "") { const curLine = cmEditorAct.getCursor().line; cmEditorAct.setSelection({ line: curLine, ch: 0 }, { line: curLine, ch: cmEditorAct.getLine(curLine).length }); } let selectedContent = newFileNamePrefix + tp.file.selection(); let newFileName = await tp.system.prompt("Name of new note", selectedContent); newFileName = newFileName.replace(/[\.#\*""\/\\<>\:\|\[\]\?]/gim, '').slice(0, 255); if(replaceWithLink) { tR = `[` + `[${newFileName}]]`; if(embedLink) { tR = `!${tR}` } } else { tR = selectedContent; } tp.file.create_new(foundFile, newFileName, openNewFile, foundFolder); %>