From 6de5e8b19fe75c676be57b6b208bc54bb017613e Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlev Date: Sun, 26 Feb 2023 00:26:55 +0100 Subject: [PATCH] renderIndex moved to main.go --- main.go | 34 ++++++++++++++++++++++++++++++++++ scripts.go | 41 ----------------------------------------- 2 files changed, 34 insertions(+), 41 deletions(-) delete mode 100644 scripts.go diff --git a/main.go b/main.go index 000e94ac..12c627d6 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,9 @@ import ( "bytes" "errors" "fmt" + "github.com/avelino/awesome-go/pkg/markdown" cp "github.com/otiai10/copy" + template2 "html/template" "net/url" "os" "path/filepath" @@ -324,3 +326,35 @@ func rewriteLinksInIndex(doc *goquery.Document, categories map[string]Category) return nil } + +// renderIndex generate site html (index.html) from markdown file +func renderIndex(srcFilename, outFilename string) error { + input, err := os.ReadFile(srcFilename) + if err != nil { + return err + } + + body, err := markdown.ToHTML(input) + if err != nil { + return err + } + + f, err := os.Create(outFilename) + if err != nil { + return err + } + + fmt.Printf("Write Index file: %s\n", outIndexFile) + data := map[string]interface{}{ + "Body": template2.HTML(body), + } + if err := tplIndex.Execute(f, data); err != nil { + return err + } + + if err := f.Close(); err != nil { + return fmt.Errorf("close index file: %w", err) + } + + return nil +} diff --git a/scripts.go b/scripts.go deleted file mode 100644 index 3d101eb1..00000000 --- a/scripts.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "fmt" - "html/template" - "os" - - "github.com/avelino/awesome-go/pkg/markdown" -) - -// renderIndex generate site html (index.html) from markdown file -func renderIndex(srcFilename, outFilename string) error { - input, err := os.ReadFile(srcFilename) - if err != nil { - return err - } - - body, err := markdown.ToHTML(input) - if err != nil { - return err - } - - f, err := os.Create(outFilename) - if err != nil { - return err - } - - fmt.Printf("Write Index file: %s\n", outIndexFile) - data := map[string]interface{}{ - "Body": template.HTML(body), - } - if err := tplIndex.Execute(f, data); err != nil { - return err - } - - if err := f.Close(); err != nil { - return fmt.Errorf("close index file: %w", err) - } - - return nil -}