1
0
Fork 0
mirror of https://github.com/avelino/awesome-go.git synced 2024-11-13 11:14:37 -05:00

renderIndex moved to main.go

This commit is contained in:
Kirill Zhuravlev 2023-02-26 00:26:55 +01:00 committed by Avelino
parent 0fe344a1a9
commit 6de5e8b19f
No known key found for this signature in database
GPG key ID: B345B4D52E98180A
2 changed files with 34 additions and 41 deletions

34
main.go
View file

@ -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
}

View file

@ -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
}