mirror of
https://github.com/avelino/awesome-go.git
synced 2025-01-31 04:48:53 +00:00
move html generate func to scripts
will be used in the generation of htmls from the sub-category focus on SEO Signed-off-by: Avelino <avelinorun@gmail.com>
This commit is contained in:
parent
f181e73636
commit
62b6fe1c9f
23
repo_test.go
23
repo_test.go
@ -2,21 +2,14 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
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()
|
||||||
|
|
||||||
@ -76,7 +69,7 @@ func TestSeparator(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
func TestGenerateHTML(t *testing.T) {
|
func TestGenerateHTML(t *testing.T) {
|
||||||
err := generateHTML()
|
err := GenerateHTML()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("html generate error '%s'", err.Error())
|
t.Errorf("html generate error '%s'", err.Error())
|
||||||
}
|
}
|
||||||
@ -113,17 +106,3 @@ 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
|
|
||||||
}
|
|
||||||
|
26
scripts.go
26
scripts.go
@ -4,8 +4,12 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
|
"github.com/gomarkdown/markdown"
|
||||||
|
"github.com/gomarkdown/markdown/parser"
|
||||||
"github.com/russross/blackfriday"
|
"github.com/russross/blackfriday"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,3 +31,25 @@ func startQuery() *goquery.Document {
|
|||||||
}
|
}
|
||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type content struct {
|
||||||
|
Body string
|
||||||
|
}
|
||||||
|
|
||||||
|
func GenerateHTML() (err error) {
|
||||||
|
// options
|
||||||
|
readmePath := "./README.md"
|
||||||
|
tplPath := "tmpl/tmpl.html"
|
||||||
|
idxPath := "tmpl/index.html"
|
||||||
|
input, _ := ioutil.ReadFile(readmePath)
|
||||||
|
extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.LaxHTMLBlocks
|
||||||
|
parser := parser.NewWithExtensions(extensions)
|
||||||
|
|
||||||
|
body := string(markdown.ToHTML(input, parser, nil))
|
||||||
|
// 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 New Issue
Block a user