mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2024-12-25 14:28:58 +00:00
生成的 html 包含版本信息
This commit is contained in:
parent
9dde0cb185
commit
356d3700c5
5
.gitignore
vendored
5
.gitignore
vendored
@ -13,4 +13,7 @@ _book
|
|||||||
# eBook build output
|
# eBook build output
|
||||||
*.epub
|
*.epub
|
||||||
*.mobi
|
*.mobi
|
||||||
*.pdf
|
*.pdf
|
||||||
|
|
||||||
|
version.md
|
||||||
|
|
||||||
|
2
Makefile
2
Makefile
@ -13,6 +13,7 @@
|
|||||||
# http://www.imagemagick.org/
|
# http://www.imagemagick.org/
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
go run update_version.go
|
||||||
gitbook build
|
gitbook build
|
||||||
|
|
||||||
zh2tw:
|
zh2tw:
|
||||||
@ -26,6 +27,7 @@ loop:
|
|||||||
go run zh2tw.go . .md$$ zh2tw
|
go run zh2tw.go . .md$$ zh2tw
|
||||||
|
|
||||||
review:
|
review:
|
||||||
|
go run update_version.go
|
||||||
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
|
||||||
|
@ -9,6 +9,7 @@ Go語言聖經 [《The Go Programming Language》](http://gopl.io) 中文版本
|
|||||||
- 項目主頁:http://github.com/golang-china/gopl-zh
|
- 項目主頁:http://github.com/golang-china/gopl-zh
|
||||||
- 原版官網:http://gopl.io
|
- 原版官網:http://gopl.io
|
||||||
|
|
||||||
|
{% include "./version.md" %}
|
||||||
|
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
72
update_version.go
Normal file
72
update_version.go
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
// 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
|
||||||
|
|
||||||
|
// 更新版本信息
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
data := makeVersionMarkdown()
|
||||||
|
|
||||||
|
err := ioutil.WriteFile("./version.md", []byte(data), 0666)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("ioutil.WriteFile: err = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("MakeVersionMarkdown Done")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成版本文件
|
||||||
|
func makeVersionMarkdown() string {
|
||||||
|
version := getGitCommitVersion()
|
||||||
|
buildTime := time.Now().Format("2006-01-02")
|
||||||
|
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
<!-- 版本號文件,用於被其它md文件包含 -->
|
||||||
|
|
||||||
|
### 版本信息
|
||||||
|
|
||||||
|
- 仓库版本:[%s](https://github.com/golang-china/gopl-zh/commit/%s)
|
||||||
|
- 构建时间:%s
|
||||||
|
`,
|
||||||
|
version, version,
|
||||||
|
buildTime,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取Git最新的版本号
|
||||||
|
//
|
||||||
|
// git log HEAD -1
|
||||||
|
// commit 0460c1b3bb8fbb7e2fc88961e69aa37f4041d6c1
|
||||||
|
// Merge: b2d582a e826457
|
||||||
|
// Author: chai2010 <chaishushan@gmail.com>
|
||||||
|
// Date: Mon Feb 1 08:04:44 2016 +0800
|
||||||
|
//
|
||||||
|
// Merge pull request #249 from sunclx/patch-3
|
||||||
|
//
|
||||||
|
// fix typo
|
||||||
|
func getGitCommitVersion() (version string) {
|
||||||
|
cmdOut, err := exec.Command(`git`, `log`, `HEAD`, `-1`).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("getGitCommitVersion: err = %s", err)
|
||||||
|
}
|
||||||
|
for _, line := range strings.Split(string(cmdOut), "\n") {
|
||||||
|
line := strings.TrimSpace(line)
|
||||||
|
if strings.HasPrefix(line, "commit") {
|
||||||
|
version = strings.TrimSpace(line[len("commit"):])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "master"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user