()
| 844 | |
| 845 | // Create a new note |
| 846 | function createNewNote() { |
| 847 | const name = newNoteName.value.trim(); |
| 848 | |
| 849 | if (!name) { |
| 850 | alert('Please enter a name for the new note.'); |
| 851 | return; |
| 852 | } |
| 853 | |
| 854 | // Add .md extension if not present |
| 855 | const fileName = name.endsWith('.md') ? name : `${name}.md`; |
| 856 | |
| 857 | // Get category and tags |
| 858 | const category = newNoteCategory.value.trim(); |
| 859 | const tagsInput = newNoteTags.value.trim(); |
| 860 | const tags = tagsInput ? tagsInput.split(',').map(tag => tag.trim()).filter(tag => tag) : []; |
| 861 | |
| 862 | // Generate frontmatter if we have category or tags |
| 863 | let frontmatter = ''; |
| 864 | if (category || tags.length > 0) { |
| 865 | frontmatter = '---\n'; |
| 866 | if (category) { |
| 867 | frontmatter += `category: ${category}\n`; |
| 868 | } |
| 869 | if (tags.length > 0) { |
| 870 | frontmatter += `tags: [${tags.join(', ')}]\n`; |
| 871 | } |
| 872 | frontmatter += '---\n\n'; |
| 873 | } |
| 874 | |
| 875 | // Create content with frontmatter |
| 876 | const content = frontmatter + '# ' + name + '\n\nStart writing your markdown here...'; |
| 877 | |
| 878 | // Create the file |
| 879 | fetch('/api/files', { |
| 880 | method: 'POST', |
| 881 | headers: { |
| 882 | 'Content-Type': 'application/json' |
| 883 | }, |
| 884 | body: JSON.stringify({ |
| 885 | name: fileName, |
| 886 | content: content |
| 887 | }) |
| 888 | }) |
| 889 | .then(response => response.json()) |
| 890 | .then(data => { |
| 891 | if (data.status === 'success') { |
| 892 | // Close the modal |
| 893 | hideNewNoteModal(); |
| 894 | |
| 895 | // Refresh file list |
| 896 | loadFiles(); |
| 897 | |
| 898 | // Load the new file |
| 899 | setTimeout(() => { |
| 900 | loadFile(data.data); |
| 901 | |
| 902 | // Switch to edit mode for new files |
| 903 | setViewMode('split'); |
no test coverage detected