gohxs / httpServe

Serve local folder content, parses markdown, live reload
0 stars 1 forks source link

request: filewatcher on not-yet-existing files #1

Open timhemel opened 4 years ago

timhemel commented 4 years ago

If I create a markdown link and click on it in the server html content, I get a page with the message "Not Found\r\n". I would like the server to detect when I create that file and show it.

timhemel commented 4 years ago

The attached patch fixed this more or less for me. Without any previous knowledge of Go, it may not be the most elegant or efficient solution. In short:

  1. I handle a non-existing file with a special handler, that renders the text File not found in the markdown template, which includes the livereload code.
  2. If a file does not exist when watching, try to watch its parent. If that does not exist, try to watch the parent's parent, etc.

patch.txt

timhemel commented 4 years ago

I've restricted the not-found handler to markdown files only, see PR #2.