package notes

import (
	"fmt"
	"net/http"
)

func (s *Server) notes(w http.ResponseWriter, r *http.Request) {
	p := NewPathFromURL(r.URL.Path)
	if p.IsDir() {
		head(w, r)
		notesHead(w, p)
		notesDir(p, w, r)
		foot(w, r)
	} else if p.IsFile() {
		head(w, r)
		notesHead(w, p)
		notesFile(p, w, r)
		foot(w, r)
	} else {
		http.NotFound(w, r)
	}
}

func notesHead(w http.ResponseWriter, p Path) {
	fmt.Fprintln(w, h2(p.MultiLink()))
}
