diff --git a/.travis.yml b/.travis.yml index d1552489..ba9b7b31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,15 @@ language: go go: - 1.x - + sudo: false install: - go get -t -v ./... + - npm install netlify-cli -g + +deploy: + provider: script + script: netlify deploy --dir=tmpl --prod + on: + branch: master diff --git a/repo.go b/repo.go deleted file mode 100644 index d04831cc..00000000 --- a/repo.go +++ /dev/null @@ -1,59 +0,0 @@ -package main - -import ( - "io/ioutil" - "net/http" - "os" - "os/exec" - "text/template" - - "github.com/gorilla/mux" - gfm "github.com/shurcooL/github_flavored_markdown" -) - -// memory usage optimizations -const ( - emtyStr = "" - git = "git" - checkout = "checkout" - force = "-f" - pull = "pull" - - // options - readmePath = "./README.md" - tplPath = "tmpl/tmpl.html" - idxPath = "tmpl/index.html" -) - -var ( - doneResp = []byte("Done!\n") -) - -type content struct { - Body string -} - -func generateHTML() { - // Update repo - exec.Command(git, checkout, force).Output() - exec.Command(git, pull).Output() - - input, _ := ioutil.ReadFile(readmePath) - body := string(gfm.Markdown(input)) - c := &content{Body: body} - - t := template.Must(template.ParseFiles(tplPath)) - f, _ := os.Create(idxPath) - t.Execute(f, c) -} - -func hookHandler(w http.ResponseWriter, r *http.Request) { - go generateHTML() - w.Write(doneResp) -} - -func main() { - r := mux.NewRouter() - r.HandleFunc("/hook", hookHandler) - http.ListenAndServe(":9000", r) -} diff --git a/repo_test.go b/repo_test.go index 8314ee47..fe3fe499 100644 --- a/repo_test.go +++ b/repo_test.go @@ -3,15 +3,22 @@ package main import ( "bytes" "io/ioutil" + "os" "regexp" "sort" "strings" "testing" + "text/template" "github.com/PuerkitoBio/goquery" "github.com/russross/blackfriday" + gfm "github.com/shurcooL/github_flavored_markdown" ) +type content struct { + Body string +} + func TestAlpha(t *testing.T) { query := startQuery() @@ -70,6 +77,12 @@ func TestSeparator(t *testing.T) { } } } +func TestGenerateHTML(t *testing.T) { + err := generateHTML() + if err != nil { + t.Errorf("html generate error '%s'", err.Error()) + } +} func testList(t *testing.T, list *goquery.Selection) { list.Find("ul").Each(func(_ int, items *goquery.Selection) { @@ -122,3 +135,17 @@ func checkAlphabeticOrder(t *testing.T, s *goquery.Selection) { t.Logf("expected order is:\n%s", strings.Join(sorted, "\n")) } } + +func generateHTML() (err error) { + // options + readmePath := "./README.md" + tplPath := "tmpl/tmpl.html" + idxPath := "tmpl/index.html" + input, _ := ioutil.ReadFile(readmePath) + body := string(gfm.Markdown(input)) + c := &content{Body: body} + t := template.Must(template.ParseFiles(tplPath)) + f, err := os.Create(idxPath) + t.Execute(f, c) + return +}