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:
parent
012e45b32b
commit
ee533006da
3 changed files with 35 additions and 60 deletions
|
@ -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
59
repo.go
|
@ -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)
|
||||
}
|
27
repo_test.go
27
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue