mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-08 23:40:40 +02:00
committed by
Bjørn Erik Pedersen
parent
f2946da9e8
commit
e77ca3c105
@@ -20,6 +20,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gohugoio/hugo/common/htime"
|
||||
"github.com/gohugoio/hugo/helpers"
|
||||
|
||||
"github.com/gohugoio/hugo/source"
|
||||
@@ -70,7 +71,7 @@ func (f ContentFactory) ApplyArchetypeTemplate(w io.Writer, p page.Page, archety
|
||||
|
||||
d := &archetypeFileData{
|
||||
Type: archetypeKind,
|
||||
Date: time.Now().Format(time.RFC3339),
|
||||
Date: htime.Now().Format(time.RFC3339),
|
||||
Page: p,
|
||||
File: p.File(),
|
||||
}
|
||||
|
@@ -22,12 +22,14 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/bep/clock"
|
||||
"github.com/gohugoio/hugo/htesting"
|
||||
"github.com/gohugoio/hugo/markup/asciidocext"
|
||||
"github.com/gohugoio/hugo/markup/rst"
|
||||
|
||||
"github.com/gohugoio/hugo/config"
|
||||
|
||||
"github.com/gohugoio/hugo/common/htime"
|
||||
"github.com/gohugoio/hugo/common/loggers"
|
||||
|
||||
"github.com/gohugoio/hugo/hugofs"
|
||||
@@ -1536,7 +1538,6 @@ Content.
|
||||
}
|
||||
|
||||
func TestShouldBuild(t *testing.T) {
|
||||
t.Parallel()
|
||||
past := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
|
||||
future := time.Date(2037, 11, 17, 20, 34, 58, 651387237, time.UTC)
|
||||
zero := time.Time{}
|
||||
@@ -1582,6 +1583,54 @@ func TestShouldBuild(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldBuildWithClock(t *testing.T) {
|
||||
htime.Clock = clock.Start(time.Date(2021, 11, 17, 20, 34, 58, 651387237, time.UTC))
|
||||
t.Cleanup(func() { htime.Clock = clock.Start(time.Now()) })
|
||||
past := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
|
||||
future := time.Date(2037, 11, 17, 20, 34, 58, 651387237, time.UTC)
|
||||
zero := time.Time{}
|
||||
|
||||
publishSettings := []struct {
|
||||
buildFuture bool
|
||||
buildExpired bool
|
||||
buildDrafts bool
|
||||
draft bool
|
||||
publishDate time.Time
|
||||
expiryDate time.Time
|
||||
out bool
|
||||
}{
|
||||
// publishDate and expiryDate
|
||||
{false, false, false, false, zero, zero, true},
|
||||
{false, false, false, false, zero, future, true},
|
||||
{false, false, false, false, past, zero, true},
|
||||
{false, false, false, false, past, future, true},
|
||||
{false, false, false, false, past, past, false},
|
||||
{false, false, false, false, future, future, false},
|
||||
{false, false, false, false, future, past, false},
|
||||
|
||||
// buildFuture and buildExpired
|
||||
{false, true, false, false, past, past, true},
|
||||
{true, true, false, false, past, past, true},
|
||||
{true, false, false, false, past, past, false},
|
||||
{true, false, false, false, future, future, true},
|
||||
{true, true, false, false, future, future, true},
|
||||
{false, true, false, false, future, past, false},
|
||||
|
||||
// buildDrafts and draft
|
||||
{true, true, false, true, past, future, false},
|
||||
{true, true, true, true, past, future, true},
|
||||
{true, true, true, true, past, future, true},
|
||||
}
|
||||
|
||||
for _, ps := range publishSettings {
|
||||
s := shouldBuild(ps.buildFuture, ps.buildExpired, ps.buildDrafts, ps.draft,
|
||||
ps.publishDate, ps.expiryDate)
|
||||
if s != ps.out {
|
||||
t.Errorf("AssertShouldBuildWithClock unexpected output with params: %+v", ps)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// "dot" in path: #1885 and #2110
|
||||
// disablePathToLower regression: #3374
|
||||
func TestPathIssues(t *testing.T) {
|
||||
|
@@ -30,6 +30,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gohugoio/hugo/common/htime"
|
||||
"github.com/gohugoio/hugo/common/hugio"
|
||||
"github.com/gohugoio/hugo/common/types"
|
||||
"github.com/gohugoio/hugo/modules"
|
||||
@@ -1910,10 +1911,11 @@ func shouldBuild(buildFuture bool, buildExpired bool, buildDrafts bool, Draft bo
|
||||
if !(buildDrafts || !Draft) {
|
||||
return false
|
||||
}
|
||||
if !buildFuture && !publishDate.IsZero() && publishDate.After(time.Now()) {
|
||||
hnow := htime.Now()
|
||||
if !buildFuture && !publishDate.IsZero() && publishDate.After(hnow) {
|
||||
return false
|
||||
}
|
||||
if !buildExpired && !expiryDate.IsZero() && expiryDate.Before(time.Now()) {
|
||||
if !buildExpired && !expiryDate.IsZero() && expiryDate.Before(hnow) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
Reference in New Issue
Block a user