Skip to content

Commit 0e3448e

Browse files
committed
渲染 index.html 页面
1 parent 9bc8703 commit 0e3448e

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

pkg/render/page_home.go

+28-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,37 @@
55
package render
66

77
import (
8+
"bytes"
89
"os"
910
"path/filepath"
11+
12+
"github.com/yuin/goldmark"
13+
"github.com/yuin/goldmark/extension"
1014
)
1115

1216
func (p *BookRendor) renderHomepage() error {
13-
return os.WriteFile(filepath.Join(p.Book.Root, "book", "index.html"), []byte("hello wabook"), 0666)
17+
markdown := goldmark.New(
18+
goldmark.WithExtensions(extension.GFM),
19+
)
20+
21+
// 读取首页
22+
page_Content, err := os.ReadFile(filepath.Join(p.Book.Root, "index.md"))
23+
if err != nil {
24+
page_Content, err = os.ReadFile(filepath.Join(p.Book.Root, "readme.md"))
25+
if err != nil {
26+
page_Content, err = os.ReadFile(filepath.Join(p.Book.Root, "README.md"))
27+
}
28+
err = nil
29+
}
30+
31+
var buf bytes.Buffer
32+
if err := markdown.Convert([]byte(page_Content), &buf); err != nil {
33+
return err
34+
}
35+
36+
return os.WriteFile(
37+
filepath.Join(p.Book.Root, "book", "index.html"),
38+
buf.Bytes(),
39+
0666,
40+
)
1441
}

0 commit comments

Comments
 (0)