Skip to content

Commit

Permalink
Work
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Jan 11, 2019
1 parent 82db8aa commit 5b01424
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 27 deletions.
7 changes: 4 additions & 3 deletions hugolib/hugo_sites.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,14 +642,15 @@ func (h *HugoSites) setupTranslations() {
pp := p.(*Page)
if p.Kind() == kindUnknown {
pp.kind = pp.kindFromSections()

}

if !pp.s.isEnabled(p.Kind()) {
continue
}

shouldBuild := pp.shouldBuild()
s.updateBuildStats(pp)
shouldBuild := s.shouldBuild(p)
s.updateBuildStats(p)
if shouldBuild {
if pp.headless {
s.headlessPages = append(s.headlessPages, p)
Expand Down Expand Up @@ -724,7 +725,7 @@ func handleShortcodes(p *PageWithoutContent, rawContentCopy []byte) ([]byte, err
return rawContentCopy, nil
}

func (s *Site) updateBuildStats(page *Page) {
func (s *Site) updateBuildStats(page page.Page) {
if page.IsDraft() {
s.draftCount++
}
Expand Down
6 changes: 3 additions & 3 deletions hugolib/hugo_sites_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,11 @@ func assertShouldNotBuild(t *testing.T, sites *HugoSites) {
for _, p := range s.rawAllPages {
pp := p.(*Page)
// No HTML when not processed
require.Equal(t, pp.shouldBuild(), bytes.Contains(pp.workContent, []byte("</")), pp.File().BaseFileName()+": "+string(pp.workContent))
require.Equal(t, s.shouldBuild(p), bytes.Contains(pp.workContent, []byte("</")), pp.File().BaseFileName()+": "+string(pp.workContent))

require.Equal(t, pp.shouldBuild(), pp.content() != "", fmt.Sprintf("%v:%v", pp.content(), pp.shouldBuild()))
require.Equal(t, s.shouldBuild(p), content(p) != "", fmt.Sprintf("%v:%v", content(p), s.shouldBuild(p)))

require.Equal(t, pp.shouldBuild(), pp.content() != "", pp.File().BaseFileName())
require.Equal(t, s.shouldBuild(p), content(p) != "", pp.File().BaseFileName())

}
}
Expand Down
19 changes: 0 additions & 19 deletions hugolib/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,25 +996,6 @@ func (p *Page) LinkTitle() string {
return p.title
}

func (p *Page) shouldBuild() bool {
return shouldBuild(p.s.BuildFuture, p.s.BuildExpired,
p.s.BuildDrafts, p.Draft, p.PublishDate(), p.ExpiryDate())
}

func shouldBuild(buildFuture bool, buildExpired bool, buildDrafts bool, Draft bool,
publishDate time.Time, expiryDate time.Time) bool {
if !(buildDrafts || !Draft) {
return false
}
if !buildFuture && !publishDate.IsZero() && publishDate.After(time.Now()) {
return false
}
if !buildExpired && !expiryDate.IsZero() && expiryDate.Before(time.Now()) {
return false
}
return true
}

func (p *Page) IsDraft() bool {
return p.Draft
}
Expand Down
2 changes: 1 addition & 1 deletion hugolib/page_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Loop:
p.source.posMainContent = next.Pos
}

if !p.shouldBuild() {
if !p.s.shouldBuild(p) {
// Nothing more to do.
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion hugolib/pagebundler_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (c *contentHandlers) parsePage(h contentHandler) contentHandler {
return handlerResult{err: err}
}

if !p.shouldBuild() {
if !c.s.shouldBuild(p) {
if !ctx.doNotAddToSiteCollections {
ctx.pages <- p
}
Expand Down
19 changes: 19 additions & 0 deletions hugolib/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -1870,3 +1870,22 @@ func (s *Site) newTaxonomyTermsPage(plural string) *Page {
p.title = s.titleFunc(plural)
return p
}

func (s *Site) shouldBuild(p page.Page) bool {
return shouldBuild(s.BuildFuture, s.BuildExpired,
s.BuildDrafts, p.IsDraft(), p.PublishDate(), p.ExpiryDate())
}

func shouldBuild(buildFuture bool, buildExpired bool, buildDrafts bool, Draft bool,
publishDate time.Time, expiryDate time.Time) bool {
if !(buildDrafts || !Draft) {
return false
}
if !buildFuture && !publishDate.IsZero() && publishDate.After(time.Now()) {
return false
}
if !buildExpired && !expiryDate.IsZero() && expiryDate.Before(time.Now()) {
return false
}
return true
}
6 changes: 6 additions & 0 deletions resources/page/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ type pageAddons6 interface {
File() source.File

deprecatedPageMethods

pageAddons7
}

type pageAddons7 interface {
IsDraft() bool
}

type deprecatedPageMethods interface {
Expand Down

0 comments on commit 5b01424

Please sign in to comment.