Skip to content

Commit

Permalink
tpl: Support GitInfo for content folders
Browse files Browse the repository at this point in the history
Add an option to get git metadata from the content dir instead of the
working dir

Fixes gohugoio#5533
  • Loading branch information
asafg6 committed Dec 19, 2019
1 parent e625088 commit c63f9bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/content/en/variables/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ The `GitInfo` object contains the following fields:
If the `.GitInfo` feature is enabled, `.Lastmod` (on `Page`) is fetched from Git i.e. `.GitInfo.AuthorDate`. This behaviour can be changed by adding your own [front matter configuration for dates](/getting-started/configuration/#configure-front-matter).

[configuration]: /getting-started/configuration/

## Using contentDir instead of workingDir

If your content directory is under a subomdule, you can add `useContentDirGitInfo` to `true` to your [site's configuration file][configuration].
Hugo will then get it's content metadata from the content repository (instead of the repository in the working directory).

11 changes: 9 additions & 2 deletions hugolib/gitinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ func (g *gitInfo) forPage(p page.Page) *gitmap.GitInfo {
}

func newGitInfo(cfg config.Provider) (*gitInfo, error) {
workingDir := cfg.GetString("workingDir")
useContentGitInfo := cfg.GetBool("useContentDirGitInfo")
var gitDir string
if useContentGitInfo {
gitDir = cfg.GetString("contentDir")
} else {
gitDir = cfg.GetString("workingDir")

gitRepo, err := gitmap.Map(workingDir, "")
}

gitRepo, err := gitmap.Map(gitDir, "")
if err != nil {
return nil, err
}
Expand Down

0 comments on commit c63f9bf

Please sign in to comment.