fix some naming
This commit is contained in:
parent
7389d26323
commit
8900500b35
1 changed files with 10 additions and 12 deletions
22
livemd.go
22
livemd.go
|
|
@ -2,14 +2,13 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "html/template"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
txttemplate "text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/russross/blackfriday"
|
"github.com/russross/blackfriday"
|
||||||
fsnotify "gopkg.in/fsnotify.v1"
|
fsnotify "gopkg.in/fsnotify.v1"
|
||||||
|
|
@ -18,13 +17,13 @@ import (
|
||||||
var SUFFIXES = [3]string{".md", ".mkd", ".markdown"}
|
var SUFFIXES = [3]string{".md", ".mkd", ".markdown"}
|
||||||
|
|
||||||
var toc []string
|
var toc []string
|
||||||
var toc_mutex sync.Mutex
|
var tocMutex sync.Mutex
|
||||||
var rootTmpl *txttemplate.Template
|
var rootTmpl *template.Template
|
||||||
var path string
|
var path string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
rootTmpl, err = txttemplate.New("root").Parse(rootTemplate)
|
rootTmpl, err = template.New("root").Parse(rootTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -48,9 +47,9 @@ func AddWatch(w *fsnotify.Watcher) filepath.WalkFunc {
|
||||||
w.Add(path)
|
w.Add(path)
|
||||||
} else {
|
} else {
|
||||||
if HasMarkdownSuffix(path) {
|
if HasMarkdownSuffix(path) {
|
||||||
toc_mutex.Lock()
|
tocMutex.Lock()
|
||||||
toc = append(toc, path)
|
toc = append(toc, path)
|
||||||
toc_mutex.Unlock()
|
tocMutex.Unlock()
|
||||||
log.Println("Found", path)
|
log.Println("Found", path)
|
||||||
w.Add(path)
|
w.Add(path)
|
||||||
}
|
}
|
||||||
|
|
@ -76,15 +75,15 @@ func WatcherEventLoop(w *fsnotify.Watcher, done chan bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RootFunc(w http.ResponseWriter, r *http.Request) {
|
func RootFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
toc_mutex.Lock()
|
tocMutex.Lock()
|
||||||
localToc := toc[:]
|
localToc := toc[:]
|
||||||
toc_mutex.Unlock()
|
tocMutex.Unlock()
|
||||||
for i, s := range localToc {
|
for i, s := range localToc {
|
||||||
s = strings.TrimPrefix(s, path)
|
s = strings.TrimPrefix(s, path)
|
||||||
localToc[i] = "* " + s
|
localToc[i] = "* " + s
|
||||||
}
|
}
|
||||||
tocmkd := strings.Join(localToc, "\n")
|
tocMkd := strings.Join(localToc, "\n")
|
||||||
bytes := blackfriday.MarkdownCommon([]byte(tocmkd))
|
bytes := blackfriday.MarkdownCommon([]byte(tocMkd))
|
||||||
rootTmpl.Execute(w, string(bytes))
|
rootTmpl.Execute(w, string(bytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,7 +110,6 @@ func main() {
|
||||||
|
|
||||||
fmt.Println(toc)
|
fmt.Println(toc)
|
||||||
|
|
||||||
fmt.Println(blackfriday.HTML_TOC)
|
|
||||||
http.HandleFunc("/", RootFunc)
|
http.HandleFunc("/", RootFunc)
|
||||||
http.ListenAndServe(":8080", nil)
|
http.ListenAndServe(":8080", nil)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue