Files
RawMark/web/src/app/templates.ts
T
eezd a716794e41 feat(ui): improve readability and fix workspace regressions
Separate interface typography from document text and enlarge controls across the workspace and public reader. Keep tree menus within the viewport and make constrained dialogs scrollable.

Preserve nested image references, escape moved link paths, synchronize note creation and daily-note opening, and hydrate shared headings. Add regression coverage for settings and workspace behavior.
2026-10-23 10:55:53 +08:00

28 lines
1.2 KiB
TypeScript

import { localDate, renderTemplate } from '../markdown/template'
import { api } from './api'
import { joinPath } from './paths'
import { settings } from './settings'
import { createNoteAt, openNote, toast, ws } from './workspace'
export async function createFromTemplate(path: string, template: string) {
if (ws.entries.some(entry => entry.path === path)) { toast('目标笔记已存在'); return false }
const content = template ? renderTemplate((await api.readFile(template)).content, template, path) : ''
const created = await createNoteAt(path, content)
if (created) ws.sidebarOpen = false
return created
}
let openingDaily = false
export async function openDailyNote() {
// 模板读取也属于打开日记的过程,此时尚未加入乐观目录。
if (openingDaily) return
openingDaily = true
try {
const path = joinPath(settings.dailyFolder, localDate() + '.md')
if (ws.entries.some(entry => !entry.dir && entry.path === path)) { await openNote(path); return }
await createFromTemplate(path, settings.dailyTemplate)
}
catch (error) { toast('创建日记失败:' + (error instanceof Error ? error.message : '网络错误')) }
finally { openingDaily = false }
}