[템플레이터(Templater)]퀵 메모를 데일리 노트에 두는 코드

알림
|
X

페이지 정보

작성자 Oops 118.♡.199.12
작성일 2024.06.29 14:16
191 조회
0 추천
글쓰기

본문

네이버 카페에서 보고 Copilot을 사용해서 수정한 코드입니다

전 코드 짤줄 몰라요

템플레이터(Templater)에 단축키 지정해서 사용하면 편리합니다

<%*
// 필요한 변수들을 설정합니다.
let firstOrLastLine = 'last';
let qcFileName = tp.date.now("YYYY-MM-DD(ddd)");
let sectionName = '## 📒 Memo';
let folderOverride = '20_Planner/21_Daily';

// 현재 날짜와 시간을 설정합니다.
let curDateFormat = tp.date.now("YYYY-MM-DD(ddd)");
let finalTimestamp = curDateFormat;
let curTimeFormat = tp.date.now("hh:mm A");
if(curTimeFormat != '') {
finalTimestamp = finalTimestamp + ' ' + curTimeFormat;
}

// 폴더 위치를 설정합니다.
let qcFolderLocation;
if(folderOverride) {
qcFolderLocation = folderOverride;
} else {
if(this.app.vault.config.newFileLocation != 'current') {
qcFolderLocation = this.app.fileManager.getNewFileParent().path;
} else {
qcFolderLocation = '/';
}
}
if(qcFolderLocation != '') {
qcFolderLocation = qcFolderLocation + '/';
}
qcFolderLocation = qcFolderLocation.replace(/\/\//g,'/');
if(qcFolderLocation == '/') {
qcFolderLocation = '';
}
if(qcFolderLocation.startsWith('/')) {
qcFolderLocation = qcFolderLocation.substring(1);
}

// 파일 경로를 설정하고, 파일이 있다면 노트를 추가합니다.
let qcFilePath = qcFolderLocation + qcFileName + '.md';
let qcFile = this.app.vault.getAbstractFileByPath(qcFilePath);

if(qcFile) {
let qcNote = await tp.system.prompt("Enter a Quick Capture note");
let isTodo = qcNote.startsWith('!');
let finalNote = '- ' + (isTodo ? '- [ ] ' : '') + finalTimestamp + ' - ' + (isTodo ? qcNote.substring(1) : qcNote);
let curContent = await this.app.vault.read(qcFile);
let newContents;
if(curContent.includes(sectionName)){
let sectionIndex = curContent.indexOf(sectionName) + sectionName.length;
if(curContent.charAt(sectionIndex + 1) === '\n'){
newContents = curContent.slice(0, sectionIndex + 2) + finalNote + '\n' + curContent.slice(sectionIndex + 1);
} else {
newContents = curContent.slice(0, sectionIndex) + '\n\n' + finalNote + curContent.slice(sectionIndex);
}
} else {
newContents = curContent + '\n' + sectionName + '\n\n' + finalNote;
}
this.app.vault.modify(qcFile, newContents);
}
%>


댓글 0
글쓰기
홈으로 전체메뉴 마이메뉴 새글/새댓글
전체 검색