mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2024-11-04 13:33:41 +00:00
ingore gitbook data-revision
This commit is contained in:
parent
42abf3c76a
commit
71260d56fa
2
Makefile
2
Makefile
@ -15,6 +15,7 @@
|
|||||||
default:
|
default:
|
||||||
go run update_version.go
|
go run update_version.go
|
||||||
gitbook build
|
gitbook build
|
||||||
|
go run fix-data-revision.go
|
||||||
|
|
||||||
zh2tw:
|
zh2tw:
|
||||||
go run zh2tw.go . .md$$
|
go run zh2tw.go . .md$$
|
||||||
@ -31,6 +32,7 @@ review:
|
|||||||
go run zh2tw.go . .md$$ tw2zh
|
go run zh2tw.go . .md$$ tw2zh
|
||||||
gitbook build
|
gitbook build
|
||||||
go run zh2tw.go . .md$$ zh2tw
|
go run zh2tw.go . .md$$ zh2tw
|
||||||
|
go run fix-data-revision.go
|
||||||
|
|
||||||
qrcode:
|
qrcode:
|
||||||
go run ./tools/mkqrcode.go
|
go run ./tools/mkqrcode.go
|
||||||
|
82
fix-data-revision.go
Normal file
82
fix-data-revision.go
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
// Copyright 2015 <chaishushan{AT}gmail.com>. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build ingore
|
||||||
|
|
||||||
|
// 修复Gitbook生成html的时间戳.
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
"unicode/utf8"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 输出目录
|
||||||
|
const dir = "_book"
|
||||||
|
|
||||||
|
var (
|
||||||
|
// data-revision="Mon Feb 01 2016 10:18:48 GMT+0800 (中国标准时间)"
|
||||||
|
reDataRevision = regexp.MustCompile(`data\-revision\=\"[^"]+\"`)
|
||||||
|
goldenDataRevision = `data-revision="Mon Jan 2 15:04:05 -0700 MST 2006"`
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
total := 0
|
||||||
|
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("filepath.Walk: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if info.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
relpath, err := filepath.Rel(dir, path)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("filepath.Rel: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.HasSuffix(relpath, ".html") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if changed := convertFile(path); changed {
|
||||||
|
fmt.Printf("%s\n", relpath)
|
||||||
|
total++
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
fmt.Printf("total %d\n", total)
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertFile(path string) (changed bool) {
|
||||||
|
abspath, err := filepath.Abs(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("convertFile: filepath.Abs:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
oldData, err := ioutil.ReadFile(abspath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("convertFile: ioutil.ReadFile:", err)
|
||||||
|
}
|
||||||
|
if !utf8.Valid(oldData) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
newData := reDataRevision.ReplaceAll(oldData, []byte(goldenDataRevision))
|
||||||
|
if string(newData) == string(oldData) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
err = ioutil.WriteFile(abspath, newData, 0666)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("convertFile: ioutil.WriteFile:", err)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user