From 62b6fe1c9f66dafa6497af3b5c831be544873d0c Mon Sep 17 00:00:00 2001 From: Avelino Date: Wed, 22 Dec 2021 10:12:40 -0300 Subject: [PATCH] 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 --- repo_test.go | 23 +---------------------- scripts.go | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/repo_test.go b/repo_test.go index 9b694fa1..858d3561 100644 --- a/repo_test.go +++ b/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 -} diff --git a/scripts.go b/scripts.go index 1d0a260c..eeb6d40c 100644 --- a/scripts.go +++ b/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 +}