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 8065d24 commit ab69ea5
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 25 deletions.
8 changes: 4 additions & 4 deletions hugolib/hugo_sites_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,13 +621,13 @@ func assertShouldNotBuild(t *testing.T, sites *HugoSites) {
s := sites.Sites[0]

for _, p := range s.rawAllPages {
pp := p.(*Page)
pp := p.p
// No HTML when not processed
require.Equal(t, s.shouldBuild(p), bytes.Contains(pp.workContent, []byte("</")), pp.File().BaseFileName()+": "+string(pp.workContent))
require.Equal(t, s.shouldBuild(pp), bytes.Contains(pp.workContent, []byte("</")), pp.File().BaseFileName()+": "+string(pp.workContent))

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

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

}
}
Expand Down
12 changes: 9 additions & 3 deletions hugolib/page_buildstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (

// TODO(bep) page name etc.
type pageState struct {
s *Site
//s *Site
p *Page

workContent []byte
//workContent []byte

forceRender bool
//forceRender bool
}

func (p *pageState) contentMarkupType() string {
Expand All @@ -39,6 +39,12 @@ func (p *pageState) contentMarkupType() string {

type pageStatePages []*pageState

// Implement sorting.
func (ps pageStatePages) Len() int { return len(ps) }
func (ps pageStatePages) Swap(i, j int) { ps[i], ps[j] = ps[j], ps[i] }

func (ps pageStatePages) Less(i, j int) bool { return page.DefaultPageSort(ps[i].p, ps[j].p) }

func (ps pageStatePages) findPagePosByFilename(filename string) int {
for i, x := range ps {
if x.p.File().Filename() == filename {
Expand Down
12 changes: 6 additions & 6 deletions hugolib/pagebundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import (
"fmt"
"math"
"runtime"

"github.com/gohugoio/hugo/resources/page"
"sort"

_errors "github.com/pkg/errors"

Expand Down Expand Up @@ -107,12 +106,12 @@ func (s *siteContentProcessor) process(ctx context.Context) error {
// There can be only one of these per site.
g1.Go(func() error {
for p := range s.pagesChan {
if p.s != s.site {
panic(fmt.Sprintf("invalid page site: %v vs %v", p.s, s))
if p.p.s != s.site {
panic(fmt.Sprintf("invalid page site: %v vs %v", p.p.s, s))
}

if s.partialBuild {
p.forceRender = true
p.p.forceRender = true
s.site.replacePage(p)
} else {
s.site.addPage(p)
Expand Down Expand Up @@ -194,7 +193,8 @@ func (s *siteContentProcessor) process(ctx context.Context) error {
return err
}

page.SortByDefault(s.site.rawAllPages)
// Apply default sort order.
sort.Stable(s.site.rawAllPages)

return nil

Expand Down
3 changes: 2 additions & 1 deletion hugolib/pagebundler_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func (c *contentHandlers) parsePage(h contentHandler) contentHandler {
// TODO(bep) page
resv.p.resourcePath = filepath.ToSlash(childCtx.target)
resv.p.parent = resv.p
p.resources = append(p.resources, resv.p)
case resource.Resource:
p.resources = append(p.resources, resv)
}
Expand Down Expand Up @@ -296,7 +297,7 @@ func (c *contentHandlers) handlePageContent() contentHandler {

// TODO(bep) page

p.p.workContent = p.p.renderContent(p.workContent)
p.p.workContent = p.p.renderContent(p.p.workContent)

tmpContent, tmpTableOfContents := helpers.ExtractTOC(p.p.workContent)
p.p.TableOfContents = helpers.BytesToHTML(tmpTableOfContents)
Expand Down
4 changes: 2 additions & 2 deletions hugolib/pagebundler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,10 @@ func TestMultilingualDisableLanguage(t *testing.T) {
// No nn pages
assert.Equal(16, len(s.AllPages))
for _, p := range s.rawAllPages {
assert.True(p.(*Page).Language().Lang != "nn")
assert.True(p.p.Language().Lang != "nn")
}
for _, p := range s.AllPages {
assert.True(p.(*Page).Language().Lang != "nn")
assert.True(p.Language().Lang != "nn")
}

}
Expand Down
16 changes: 8 additions & 8 deletions hugolib/pagecollections.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func newPageCollections() *PageCollections {
return &PageCollections{}
}

func newPageCollectionsFromPages(pages page.Pages) *PageCollections {
func newPageCollectionsFromPages(pages pageStatePages) *PageCollections {
return &PageCollections{rawAllPages: pages}
}

Expand Down Expand Up @@ -303,16 +303,16 @@ func (c *PageCollections) addPage(page *pageState) {
}

func (c *PageCollections) removePageFilename(filename string) {
if i := findPagePosByFilename(c.rawAllPages, filename); i >= 0 {
c.clearResourceCacheForPage(c.rawAllPages[i].(*Page))
if i := c.rawAllPages.findPagePosByFilename(filename); i >= 0 {
c.clearResourceCacheForPage(c.rawAllPages[i].p)
c.rawAllPages = append(c.rawAllPages[:i], c.rawAllPages[i+1:]...)
}

}

func (c *PageCollections) removePage(page *Page) {
if i := findPagePos(c.rawAllPages, page); i >= 0 {
c.clearResourceCacheForPage(c.rawAllPages[i].(*Page))
func (c *PageCollections) removePage(page *pageState) {
if i := c.rawAllPages.findPagePos(page.p); i >= 0 {
c.clearResourceCacheForPage(c.rawAllPages[i].p)
c.rawAllPages = append(c.rawAllPages[:i], c.rawAllPages[i+1:]...)
}

Expand All @@ -322,10 +322,10 @@ func (c *PageCollections) findPagesByShortcode(shortcode string) page.Pages {
var pages page.Pages

for _, p := range c.rawAllPages {
pp := p.(*Page)
pp := p.p
if pp.shortcodeState != nil {
if _, ok := pp.shortcodeState.nameSet[shortcode]; ok {
pages = append(pages, p)
pages = append(pages, p.p)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion hugolib/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ func (s *Site) resetBuildState() {
s.expiredCount = 0

for _, p := range s.rawAllPages {
pp := p.(*Page)
pp := p.p
pp.subSections = page.Pages{}
pp.parent = nil
pp.scratch = maps.NewScratch()
Expand Down
4 changes: 4 additions & 0 deletions resources/page/testhelpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ func (p *testPage) IsPage() bool {
panic("not implemented")
}

func (p *testPage) IsDraft() bool {
return false
}

func (p *testPage) AlternativeOutputFormats() (OutputFormats, error) {
panic("not implemented")
}
Expand Down

0 comments on commit ab69ea5

Please sign in to comment.