Refactor the GitInfo into the date handlers

Fixes #4495
This commit is contained in:
Bjørn Erik Pedersen
2018-03-11 18:59:11 +01:00
parent 95d62004a0
commit ce6e4310fe
8 changed files with 147 additions and 88 deletions

View File

@@ -18,6 +18,7 @@ import (
"fmt"
"html/template"
"os"
"path/filepath"
"reflect"
"sort"
@@ -25,6 +26,11 @@ import (
"testing"
"time"
"github.com/gohugoio/hugo/hugofs"
"github.com/spf13/afero"
"github.com/spf13/viper"
"github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/helpers"
"github.com/spf13/cast"
@@ -904,6 +910,32 @@ func TestPageWithDate(t *testing.T) {
checkPageDate(t, p, d)
}
func TestPageWithLastmodFromGitInfo(t *testing.T) {
assrt := require.New(t)
// We need to use the OS fs for this.
cfg := viper.New()
fs := hugofs.NewFrom(hugofs.Os, cfg)
fs.Destination = &afero.MemMapFs{}
cfg.Set("frontmatter", map[string]interface{}{
"lastmod": []string{":git", "lastmod"},
})
cfg.Set("enableGitInfo", true)
assrt.NoError(loadDefaultSettingsFor(cfg))
wd, err := os.Getwd()
assrt.NoError(err)
cfg.Set("workingDir", filepath.Join(wd, "testsite"))
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true})
assrt.Len(s.RegularPages, 1)
assrt.Equal("2018-02-28", s.RegularPages[0].Lastmod.Format("2006-01-02"))
}
func TestPageWithFrontMatterConfig(t *testing.T) {
t.Parallel()