aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib/gitinfo.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2018-08-11 16:37:00 +0200
committerBjørn Erik Pedersen <[email protected]>2018-08-11 19:51:19 +0200
commit2182ecfd34a24521bf0e3c939627a55327eb1e19 (patch)
tree795cc59d12ff289e3b1c92976613f4e9bd3a1e34 /hugolib/gitinfo.go
parente85833d868a902840c5ed1c90713256153b2548b (diff)
downloadhugo-2182ecfd34a24521bf0e3c939627a55327eb1e19.tar.gz
hugo-2182ecfd34a24521bf0e3c939627a55327eb1e19.zip
hugolib: Fix GitInfo when multiple content dirs
Fixes #5054
Diffstat (limited to 'hugolib/gitinfo.go')
-rw-r--r--hugolib/gitinfo.go22
1 files changed, 6 insertions, 16 deletions
diff --git a/hugolib/gitinfo.go b/hugolib/gitinfo.go
index affa9cea8..d356fcf07 100644
--- a/hugolib/gitinfo.go
+++ b/hugolib/gitinfo.go
@@ -14,13 +14,11 @@
package hugolib
import (
- "path"
"path/filepath"
"strings"
"github.com/bep/gitmap"
"github.com/gohugoio/hugo/config"
- "github.com/gohugoio/hugo/helpers"
)
type gitInfo struct {
@@ -32,28 +30,20 @@ func (g *gitInfo) forPage(p *Page) (*gitmap.GitInfo, bool) {
if g == nil {
return nil, false
}
- name := path.Join(g.contentDir, filepath.ToSlash(p.Path()))
+
+ name := strings.TrimPrefix(filepath.ToSlash(p.Filename()), g.contentDir)
+ name = strings.TrimPrefix(name, "/")
+
return g.repo.Files[name], true
}
func newGitInfo(cfg config.Provider) (*gitInfo, error) {
- var (
- workingDir = cfg.GetString("workingDir")
- contentDir = cfg.GetString("contentDir")
- )
+ workingDir := cfg.GetString("workingDir")
gitRepo, err := gitmap.Map(workingDir, "")
if err != nil {
return nil, err
}
- repoPath := filepath.FromSlash(gitRepo.TopLevelAbsPath)
- // The Hugo site may be placed in a sub folder in the Git repo,
- // one example being the Hugo docs.
- // We have to find the root folder to the Hugo site below the Git root.
- contentRoot := strings.TrimPrefix(workingDir, repoPath)
- contentRoot = strings.TrimPrefix(contentRoot, helpers.FilePathSeparator)
- contentDir = path.Join(filepath.ToSlash(contentRoot), contentDir)
-
- return &gitInfo{contentDir: contentDir, repo: gitRepo}, nil
+ return &gitInfo{contentDir: gitRepo.TopLevelAbsPath, repo: gitRepo}, nil
}