Skip to content

Commit

Permalink
Refactor the GitInfo into the date handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Mar 11, 2018
1 parent 68bf151 commit 1f087a2
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions hugolib/gitinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,47 @@ import (
"strings"

"github.com/bep/gitmap"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/helpers"
)

type gitInfo struct {
contentDir string
repo *gitmap.GitRepo
}

func (g *gitInfo) forPage(p *Page) *gitmap.GitInfo {
name := path.Join(g.contentDir, filepath.ToSlash(p.Path()))
return g.repo[filename]
}

func newGitInfo(cfg config.Provider) (*gitInfo, error) {
var (
workingDir = cfg.GetString("workingDir")
contentDir = cfg.GetString("contentDir")
)

gitRepo, err := gitmap.Map(workingDir, "")
if err != nil {
return 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.Files}
}

func (h *HugoSites) assembleGitInfo() {
// TODO(bep) gitinfo remove this
if true {
return
}
if !h.Cfg.GetBool("enableGitInfo") {
return
}
Expand Down

0 comments on commit 1f087a2

Please sign in to comment.