Reload index when diagrams change

This commit is contained in:
Daniel Flanagan 2024-06-07 15:30:29 -05:00
parent c5b433ac79
commit 8cf51b3a2a

11
mod.ts
View file

@ -23,7 +23,7 @@ const command = new Command()
.description('A server to facilitate editing of Mermaid diagrams') .description('A server to facilitate editing of Mermaid diagrams')
.version('v1.0.0') .version('v1.0.0')
.option( .option(
'-i, --input <input_directory:path>', '-i, --input <input_directory:string>',
'The directory containing .mmd files to compile.', 'The directory containing .mmd files to compile.',
{ {
default: './', default: './',
@ -117,6 +117,10 @@ async function runMermaidFileWatcher(args: Args) {
sockets.forEach((s) => sockets.forEach((s) =>
s.send(JSON.stringify({ type: 'mermaid', contents })) s.send(JSON.stringify({ type: 'mermaid', contents }))
) )
} else if (p.endsWith('.mmd') && kind == 'remove') {
sockets.forEach((s) =>
s.send(JSON.stringify({ type: 'mermaid', contents: '' }))
)
} }
// TODO: handle removals? // TODO: handle removals?
} }
@ -254,6 +258,11 @@ async function handleMessage({ data }) {
async function handleStructuredMessage(data) { async function handleStructuredMessage(data) {
switch (data.type) { switch (data.type) {
case 'mermaid': { case 'mermaid': {
if (window.location.pathname == '/') {
window.location.reload()
return
}
if (rendering) return if (rendering) return
rendering = true rendering = true