Skip to content

Commit 03d09f0

Browse files
committed
Merge pull request astaxie#144 from guiquanz/master
解决浏览器打开html文件乱码问题等
2 parents 8dd70a7 + 3b38e31 commit 03d09f0

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*~
2+
pkg/*
3+
*.html
4+

build.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"io/ioutil"
77
"os"
88
"path/filepath"
9-
"strings"
109
"regexp"
10+
"strings"
1111
)
1212

1313
// 定义一个访问者结构体
@@ -37,10 +37,14 @@ func (self *Visitor) visit(path string, f os.FileInfo, err error) error {
3737
os.Exit(-1)
3838
}
3939
defer out.Close()
40+
header := "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\"/>\n</head>\n"
41+
footer := "</html>\n"
42+
out.Write([]byte(header))
4043
if _, err = out.Write(output); err != nil {
4144
fmt.Fprintln(os.Stderr, "Error writing output:", err)
4245
os.Exit(-1)
4346
}
47+
out.Write([]byte(footer))
4448
}
4549
}
4650
return nil

build.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/sh
2+
3+
rm -f *.html *~
4+
5+
export GOPATH=`pwd`
6+
7+
go get -u github.com/russross/blackfriday
8+
9+
go run build.go
10+

0 commit comments

Comments
 (0)