@@ -10,22 +10,21 @@ const dv = app.plugins.plugins["dataview"].api;
10
10
let today = moment().format("YYYY-MM-DD");
11
11
let DailyNote = moment(today).format("YYYY-MM-DD");
12
12
let recordNote = DailyNote;
13
- let note = app.vault.getAbstractFileByPath(` ${RECORD_NOTE_FOLDER}/${recordNote}.md ` );
14
13
15
14
// Delay function
16
15
function delay(ms) {
17
16
return new Promise(resolve => setTimeout(resolve, ms));
18
17
}
19
18
20
19
new Notice("Autoupdate scripts are running! ", 3000);
21
- console.log("Autoupdate scripts are running! ");
20
+ console.log("[ Modified File Recorder ] Autoupdate scripts are running! ");
22
21
23
22
// Function to create a new note
24
23
async function createNewNote() {
25
24
await tp.file.create_new("", recordNote, false, RECORD_NOTE_FOLDER);
26
25
new Notice(` Created new note ${recordNote} in folder ${RECORD_NOTE_FOLDER}. ` , 5000);
27
- console.log(` Created new note ${recordNote} in folder ${RECORD_NOTE_FOLDER}. ` );
28
- await delay(500 );
26
+ console.log(` [Modified File Recorder] Created new note ${recordNote} in folder ${RECORD_NOTE_FOLDER}.` );
27
+ await delay(2000 );
29
28
}
30
29
31
30
// Function to fetch query output
@@ -34,7 +33,7 @@ async function fetchQueryOutput() {
34
33
return await dv.queryMarkdown(QUERY_STRING);
35
34
} catch (error) {
36
35
new Notice("⚠️ ERROR querying data: " + error.message, 5000);
37
- console.log(` ⚠️ ERROR: ${error} ` );
36
+ console.log(` [Modified File Recorder] ⚠️ ERROR: ${error}` );
38
37
throw error; // Rethrow to handle in the calling function
39
38
}
40
39
}
@@ -46,21 +45,21 @@ function processQueryOutput(queryOutput) {
46
45
}
47
46
48
47
// Function to read note content
49
- async function readDailyNoteContent() {
48
+ async function readDailyNoteContent(note ) {
50
49
return await app.vault.read(note);
51
50
}
52
51
53
52
// Function to update the note
54
- async function updateNoteContent(content, recordData) {
53
+ async function updateNoteContent(content, recordData, note ) {
55
54
const regex = new RegExp(` ${START_POSITION}[\\s\\S]*?(?=${END_POSITION}) ` );
56
55
if (regex.test(content)) {
57
56
const newContent = content.replace(regex, ` ${START_POSITION}\n${recordData}\n ` );
58
57
await app.vault.modify(note, newContent);
59
58
new Notice("Daily note auto updated! ", 2000);
60
- console.log("Daily note auto updated! ");
59
+ console.log("[ Modified File Recorder ] Daily note auto updated! ");
61
60
} else {
62
61
new Notice("⚠️ ERROR updating note: " + recordNote + "! Check console log.", 5000);
63
- console.log(` ⚠️ ERROR: The given pattern "${START_POSITION} ... ${END_POSITION}" is not found in ${recordNote}! ` );
62
+ console.log(` [Modified File Recorder] ⚠️ ERROR: The given pattern "${START_POSITION} ... ${END_POSITION}" is not found in ${recordNote}! ` );
64
63
}
65
64
}
66
65
@@ -70,14 +69,15 @@ async function updateDailyNotes() {
70
69
if (!tp.file.find_tfile(recordNote)) {
71
70
await createNewNote();
72
71
}
73
-
72
+
73
+ let note = app.vault.getAbstractFileByPath(` ${RECORD_NOTE_FOLDER}/${recordNote}.md ` );
74
74
const dvqueryOutput = await fetchQueryOutput();
75
75
const recordData = processQueryOutput(dvqueryOutput.value);
76
- const content = await readDailyNoteContent();
77
- await updateNoteContent(content, recordData);
76
+ const content = await readDailyNoteContent(note );
77
+ await updateNoteContent(content, recordData, note );
78
78
} catch (error) {
79
79
new Notice("⚠️ An unexpected error occurred: " + error.message, 5000);
80
- console.log(`⚠️ ERROR : ${error}`);
80
+ console.log(` [Modified File Recorder] ⚠️ An unexpected error occurred : ${error}` );
81
81
}
82
82
}
83
83
@@ -92,12 +92,12 @@ function debounce(func, wait) {
92
92
93
93
// Set up event listener to run the update function on every file save with debounce
94
94
app.vault.on('modify', debounce(async (file) => {
95
- console.log(` Detected File Change: ${file.name} ` );
95
+ console.log(` [Modified File Recorder] Detected File Change: ${file.name}` );
96
96
if (file.name === ` ${recordNote}.md ` ) {
97
97
await delay(200);
98
98
} else {
99
+ console.log(` [Modified File Recorder] Try updating ${recordNote}.md ` );
99
100
await updateDailyNotes();
100
- console.log(` Try updating ${recordNote}.md ` );
101
101
}
102
102
}, 60000)); // 60 seconds debounce
103
103
0 commit comments