1.修改build.go文件:为生成的每个html文件设置UTF-8编码,解决浏览器打开文件乱码问题;
2.增加build.sh文件:封装html生成流程,简化命令操作; 3.增加.gitignore文件:过滤对html、pkg等文件的版本管理。
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
*~
|
||||
pkg/*
|
||||
*.html
|
||||
|
||||
6
build.go
6
build.go
@@ -6,8 +6,8 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 定义一个访问者结构体
|
||||
@@ -37,10 +37,14 @@ func (self *Visitor) visit(path string, f os.FileInfo, err error) error {
|
||||
os.Exit(-1)
|
||||
}
|
||||
defer out.Close()
|
||||
header := "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\"/>\n</head>\n"
|
||||
footer := "</html>\n"
|
||||
out.Write([]byte(header))
|
||||
if _, err = out.Write(output); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error writing output:", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
out.Write([]byte(footer))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user