mirror of
https://github.com/avelino/awesome-go.git
synced 2024-11-13 11:14:37 -05: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
2 changed files with 27 additions and 22 deletions
23
repo_test.go
23
repo_test.go
|
@ -2,21 +2,14 @@ package main
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"text/template"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
gfm "github.com/shurcooL/github_flavored_markdown"
|
||||
)
|
||||
|
||||
type content struct {
|
||||
Body string
|
||||
}
|
||||
|
||||
func TestAlpha(t *testing.T) {
|
||||
query := startQuery()
|
||||
|
||||
|
@ -76,7 +69,7 @@ func TestSeparator(t *testing.T) {
|
|||
}
|
||||
}
|
||||
func TestGenerateHTML(t *testing.T) {
|
||||
err := generateHTML()
|
||||
err := GenerateHTML()
|
||||
if err != nil {
|
||||
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"))
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"text/template"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/gomarkdown/markdown"
|
||||
"github.com/gomarkdown/markdown/parser"
|
||||
"github.com/russross/blackfriday"
|
||||
)
|
||||
|
||||
|
@ -27,3 +31,25 @@ func startQuery() *goquery.Document {
|
|||
}
|
||||
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 a new issue