1
0
Fork 0
mirror of https://github.com/avelino/awesome-go.git synced 2024-11-13 11:14:37 -05:00

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

@ -7,3 +7,10 @@ sudo: false
install:
- 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 (
"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
}