Skip to content

Commit

Permalink
disable auto refresh when -w is set to false (close #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
gilliek committed Jan 4, 2015
1 parent f90476d commit 23a0bb5
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions ghmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ pre { background-color: #f8f8f8; border: 1px solid #cccccc; font-size: 13px; lin
pre code, pre tt { background-color: transparent; border: none; }`

const (
doctype = "<!DOCTYPE html>"
head = "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><meta http-equiv=\"refresh\" content=\"2\"></head>"
doctype = "<!DOCTYPE html>"
headFormat = "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">%s</head>"
)

type markdown struct {
Expand Down Expand Up @@ -131,7 +131,7 @@ func createTempFile() *os.File {
return f
}

func render(path string, out *os.File) {
func render(path string, out *os.File, refresh bool) {
md, err := ioutil.ReadFile(path)
if err != nil {
fatal(err)
Expand Down Expand Up @@ -163,6 +163,14 @@ func render(path string, out *os.File) {
fatal(err)
}

var head string

if refresh {
head = fmt.Sprintf(headFormat, "<meta http-equiv=\"refresh\" content=\"2\">")
} else {
head = fmt.Sprintf(headFormat, "")
}

fmt.Fprintln(out, doctype, head, "<body><style>", githubCSS, "</style>")
fmt.Fprintln(out, readBody(resp.Body), "</body>")
}
Expand All @@ -184,7 +192,7 @@ func watch(path string, out *os.File) {
select {
case ev := <-watcher.Events:
if filepath.Base(ev.Name) == fileName && ev.Op == fsnotify.Write {
render(path, out)
render(path, out, true)
}
case err := <-watcher.Errors:
fmt.Fprintln(os.Stderr, "error:", err)
Expand Down Expand Up @@ -274,7 +282,7 @@ func main() {
}
}()

render(path, out)
render(path, out, false)

if runCmdFlag {
runCmd, err := defaultCmd()
Expand Down

0 comments on commit 23a0bb5

Please sign in to comment.