Netlify hosting (#2441)

* site deploy on netlify

Signed-off-by: Avelino <t@avelino.xxx>

* after test success html deploy to netlify

Signed-off-by: Avelino <t@avelino.xxx>
This commit is contained in:
Avelino 2019-03-23 07:33:11 -03:00 committed by GitHub
parent 012e45b32b
commit ee533006da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 60 deletions

View File

@ -2,8 +2,15 @@ language: go
go: go:
- 1.x - 1.x
sudo: false sudo: false
install: install:
- go get -t -v ./... - go get -t -v ./...
- npm install netlify-cli -g
deploy:
provider: script
script: netlify deploy --dir=tmpl --prod
on:
branch: master

59
repo.go
View File

@ -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)
}

View File

@ -3,15 +3,22 @@ package main
import ( import (
"bytes" "bytes"
"io/ioutil" "io/ioutil"
"os"
"regexp" "regexp"
"sort" "sort"
"strings" "strings"
"testing" "testing"
"text/template"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"github.com/russross/blackfriday" "github.com/russross/blackfriday"
gfm "github.com/shurcooL/github_flavored_markdown"
) )
type content struct {
Body string
}
func TestAlpha(t *testing.T) { func TestAlpha(t *testing.T) {
query := startQuery() 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) { func testList(t *testing.T, list *goquery.Selection) {
list.Find("ul").Each(func(_ int, items *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")) 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
}