mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-22 13:33:50 +00:00
Fix Appveyor Windows build and GitInfo path issue on Windows
This commit is contained in:
parent
6e0f326b9d
commit
09a0af94f5
6 changed files with 62 additions and 6 deletions
29
appveyor.yml
Normal file
29
appveyor.yml
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
image: WMF 5
|
||||||
|
clone_folder: c:\GOPATH\src\github.com\spf13\hugo
|
||||||
|
init:
|
||||||
|
- cmd: >-
|
||||||
|
set PATH=%PATH%;C:\MinGW\bin;C:\GOPATH\bin
|
||||||
|
|
||||||
|
copy c:\MinGW\bin\mingw32-make.exe c:\MinGW\bin\make.exe
|
||||||
|
environment:
|
||||||
|
GOPATH: c:\GOPATH
|
||||||
|
install:
|
||||||
|
- cmd: >-
|
||||||
|
gem install asciidoctor
|
||||||
|
|
||||||
|
pip install docutils
|
||||||
|
build_script:
|
||||||
|
- cmd: make govendor
|
||||||
|
test_script:
|
||||||
|
- cmd: >-
|
||||||
|
make check
|
||||||
|
|
||||||
|
REM Test 64-bit alignment on 32-bit builds
|
||||||
|
|
||||||
|
set "GOARCH=386" & make test & set GOARCH=
|
||||||
|
|
||||||
|
go build -race
|
||||||
|
|
||||||
|
hugo -s docs/
|
||||||
|
|
||||||
|
hugo --renderToMemory -s docs/
|
|
@ -571,7 +571,7 @@ func getAsciidocContent(ctx *RenderingContext) []byte {
|
||||||
jww.ERROR.Printf("%s rendering %s: %v", path, ctx.DocumentName, err)
|
jww.ERROR.Printf("%s rendering %s: %v", path, ctx.DocumentName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return out.Bytes()
|
return normalizeExternalHelperLineFeeds(out.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasRst returns whether rst2html is installed on this computer.
|
// HasRst returns whether rst2html is installed on this computer.
|
||||||
|
@ -590,12 +590,24 @@ func getRstExecPath() string {
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getPythonExecPath() string {
|
||||||
|
path, err := exec.LookPath("python")
|
||||||
|
if err != nil {
|
||||||
|
path, err = exec.LookPath("python.exe")
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
// getRstContent calls the Python script rst2html as an external helper
|
// getRstContent calls the Python script rst2html as an external helper
|
||||||
// to convert reStructuredText content to HTML.
|
// to convert reStructuredText content to HTML.
|
||||||
func getRstContent(ctx *RenderingContext) []byte {
|
func getRstContent(ctx *RenderingContext) []byte {
|
||||||
content := ctx.Content
|
content := ctx.Content
|
||||||
cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)
|
cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)
|
||||||
|
|
||||||
|
python := getPythonExecPath()
|
||||||
path := getRstExecPath()
|
path := getRstExecPath()
|
||||||
|
|
||||||
if path == "" {
|
if path == "" {
|
||||||
|
@ -606,7 +618,7 @@ func getRstContent(ctx *RenderingContext) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
jww.INFO.Println("Rendering", ctx.DocumentName, "with", path, "...")
|
jww.INFO.Println("Rendering", ctx.DocumentName, "with", path, "...")
|
||||||
cmd := exec.Command(path, "--leave-comments")
|
cmd := exec.Command(python, path, "--leave-comments")
|
||||||
cmd.Stdin = bytes.NewReader(cleanContent)
|
cmd.Stdin = bytes.NewReader(cleanContent)
|
||||||
var out, cmderr bytes.Buffer
|
var out, cmderr bytes.Buffer
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
|
@ -624,11 +636,21 @@ func getRstContent(ctx *RenderingContext) []byte {
|
||||||
jww.ERROR.Printf("%s rendering %s: %v", path, ctx.DocumentName, err)
|
jww.ERROR.Printf("%s rendering %s: %v", path, ctx.DocumentName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
result := out.Bytes()
|
result := normalizeExternalHelperLineFeeds(out.Bytes())
|
||||||
|
|
||||||
// TODO(bep) check if rst2html has a body only option.
|
// TODO(bep) check if rst2html has a body only option.
|
||||||
bodyStart := bytes.Index(result, []byte("<body>\n"))
|
bodyStart := bytes.Index(result, []byte("<body>\n"))
|
||||||
|
if bodyStart < 0 {
|
||||||
|
bodyStart = -7 //compensate for length
|
||||||
|
}
|
||||||
|
|
||||||
bodyEnd := bytes.Index(result, []byte("\n</body>"))
|
bodyEnd := bytes.Index(result, []byte("\n</body>"))
|
||||||
|
if bodyEnd < 0 || bodyEnd >= len(result) {
|
||||||
|
bodyEnd = len(result) - 1
|
||||||
|
if bodyEnd < 0 {
|
||||||
|
bodyEnd = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result[bodyStart+7 : bodyEnd]
|
return result[bodyStart+7 : bodyEnd]
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,11 @@ import (
|
||||||
// FilePathSeparator as defined by os.Separator.
|
// FilePathSeparator as defined by os.Separator.
|
||||||
const FilePathSeparator = string(filepath.Separator)
|
const FilePathSeparator = string(filepath.Separator)
|
||||||
|
|
||||||
|
// Strips carriage returns from third-party / external processes (useful for Windows)
|
||||||
|
func normalizeExternalHelperLineFeeds(content []byte) []byte {
|
||||||
|
return bytes.Replace(content, []byte("\r"), []byte(""), -1)
|
||||||
|
}
|
||||||
|
|
||||||
// FindAvailablePort returns an available and valid TCP port.
|
// FindAvailablePort returns an available and valid TCP port.
|
||||||
func FindAvailablePort() (*net.TCPAddr, error) {
|
func FindAvailablePort() (*net.TCPAddr, error) {
|
||||||
l, err := net.Listen("tcp", ":0")
|
l, err := net.Listen("tcp", ":0")
|
||||||
|
|
|
@ -112,7 +112,7 @@ func Highlight(code, lang, optsStr string) string {
|
||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|
||||||
str := out.String()
|
str := string(normalizeExternalHelperLineFeeds([]byte(out.String())))
|
||||||
|
|
||||||
// inject code tag into Pygments output
|
// inject code tag into Pygments output
|
||||||
if lang != "" && strings.Contains(str, "<pre>") {
|
if lang != "" && strings.Contains(str, "<pre>") {
|
||||||
|
|
|
@ -57,7 +57,7 @@ func (h *HugoSites) assembleGitInfo() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Git normalizes file paths on this form:
|
// Git normalizes file paths on this form:
|
||||||
filename := path.Join(contentRoot, contentDir, filepath.ToSlash(p.Path()))
|
filename := path.Join(filepath.ToSlash(contentRoot), contentDir, filepath.ToSlash(p.Path()))
|
||||||
g, ok := gitMap[filename]
|
g, ok := gitMap[filename]
|
||||||
if !ok {
|
if !ok {
|
||||||
jww.ERROR.Printf("Failed to find GitInfo for %q", filename)
|
jww.ERROR.Printf("Failed to find GitInfo for %q", filename)
|
||||||
|
|
|
@ -324,7 +324,7 @@ void do();
|
||||||
}
|
}
|
||||||
|
|
||||||
if !matched {
|
if !matched {
|
||||||
t.Error("Hightlight mismatch, got\n", output)
|
t.Errorf("Hightlight mismatch, got (escaped to see invisible chars)\n%+q", output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue