zettel icon indicating copy to clipboard operation
zettel copied to clipboard

Add live reloading in dev mode

Open iamd3vil opened this issue 5 years ago • 1 comments

Currently zettel only build a static site but while writing notes it would be a much better experience if we reload when a change is made by the user.

iamd3vil avatar Sep 15 '20 16:09 iamd3vil

Would actually love this . Currently I use air to build and restart the server with this config in a file called .air.conf

# .air.conf

# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "."
tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "zettel build && go build -o ./tmp/main ."
# Binary file yields from `cmd`.
bin = "tmp/main"
# Customize binary.
full_bin = "APP_ENV=dev APP_USER=air ./tmp/main"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl","md"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
# Watch these directories if you specified.
include_dir = []
# Exclude files.
exclude_file = []
# This log file places in your tmp_dir.
log = "air.log"
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
# Stop running old binary when build errors occur.
stop_on_error = true
# Send Interrupt signal before killing process (windows does not support this feature)
send_interrupt = false
# Delay after sending Interrupt signal
kill_delay = 500 # ms

[log]
# Show log time
time = false

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# Delete tmp directory on exit
clean_on_exit = true

This is a modified version of the example conf of temp with the zettel build command and a lookout for changes in .md files and not a look on html files.

This runs with a go file too, so hacked up a small go file with a file server

// run.go
package main

import "net/http"

func main() {
	fs := http.FileServer(http.Dir("./dist"))
	http.Handle("/", fs)
	err := http.ListenAndServe(":8000", nil)
	if err != nil {
		log.Fatal(err)
	}
}

Just pasted all this for any other users having a hardtime manually building and running zettel

athul avatar Sep 15 '20 17:09 athul