-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderer.js
More file actions
28 lines (24 loc) · 854 Bytes
/
Copy pathrenderer.js
File metadata and controls
28 lines (24 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const fs = require('fs');
const path = require('path');
const marked = require('marked');
function saveEntry() {
const text = document.getElementById("entry").value;
const date = new Date().toISOString().slice(0, 10); // YYYY-MM-DD
const filePath = path.join(__dirname, 'entries');
const fileName = `${date}.md`;
// Ensure the entries directory exists
if (!fs.existsSync(filePath)) {
fs.mkdirSync(filePath);
}
fs.writeFile(path.join(filePath, fileName), text, (err) => {
if (err) {
alert('Error saving entry: ' + err.message);
} else {
alert('Entry saved!');
}
});
}
document.getElementById("entry").addEventListener("input", function() {
const markdownText = this.value;
document.getElementById("preview").innerHTML = marked.parse(markdownText);
});