From: Sergey Matveev Date: Sun, 12 Jan 2020 15:31:51 +0000 (+0300) Subject: Fix working with initial commit X-Git-Tag: v0.0.2^0 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=6bdf29e2d457bb3d67237901e5892fcb91c435c3;p=sgblog.git Fix working with initial commit --- diff --git a/cmd/sgblog/main.go b/cmd/sgblog/main.go index 39641ab..0987bac 100644 --- a/cmd/sgblog/main.go +++ b/cmd/sgblog/main.go @@ -49,8 +49,8 @@ const ( ) var ( - Version = "0.0.1" - ETagVersion = []byte("1") + Version = "0.0.2" + ETagVersion = []byte("2") sha1DigestRe = regexp.MustCompilePOSIX("([0-9a-f]{40,40})") defaultLinks = []string{} repo *git.Repository @@ -445,15 +445,23 @@ func main() { title := lines[0] when := commit.Author.When.Format(WhenFmt) os.Stdout.Write([]byte(startHeader(etagHash, gzipWriter != nil))) - parent := commit.ParentHashes[0].String() - out.Write([]byte(startHTML(fmt.Sprintf("%s (%s)", title, when), []string{ - fmt.Sprintf(``, "/"+parent), - }))) - out.Write([]byte(fmt.Sprintf( - "[%s] [%s]\n
\n", - makeA(urlPrefix+"/"+parent, "older"), - when, - ))) + links := []string{} + var parent string + if len(commit.ParentHashes) > 0 { + parent = commit.ParentHashes[0].String() + links = append(links, fmt.Sprintf( + ``, + urlPrefix+"/"+parent, + )) + } + out.Write([]byte(startHTML(fmt.Sprintf("%s (%s)", title, when), links))) + if parent != "" { + out.Write([]byte(fmt.Sprintf( + "[%s] [%s]\n
\n", + makeA(urlPrefix+"/"+parent, "older"), + when, + ))) + } out.Write([]byte(fmt.Sprintf("

%s

\n
\n", title)))
 		for _, line := range lines[2:] {
 			line = strings.ReplaceAll(line, "&", "&")