Skip to content

Commit

Permalink
Work
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Jan 26, 2019
1 parent 7e2c4f1 commit bdd299b
Show file tree
Hide file tree
Showing 90 changed files with 3,036 additions and 2,039 deletions.
2 changes: 1 addition & 1 deletion commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestExecute(t *testing.T) {
assert.NoError(resp.Err)
result := resp.Result
assert.True(len(result.Sites) == 1)
assert.True(len(result.Sites[0].RegularPages) == 1)
assert.True(len(result.Sites[0].RegularPages()) == 1)
}

func TestCommandsPersistentFlags(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions commands/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func (cc *convertCmd) convertContents(format metadecoders.Format) error {

site := h.Sites[0]

site.Log.FEEDBACK.Println("processing", len(site.AllPages), "content files")
for _, p := range site.AllPages {
site.Log.FEEDBACK.Println("processing", len(site.AllPages()), "content files")
for _, p := range site.AllPages() {
if err := cc.convertAndSavePage(p.(*hugolib.Page), site, format); err != nil {
return err
}
Expand Down
11 changes: 11 additions & 0 deletions common/hugo/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ type Site interface {
IsServer() bool
Hugo() Info
}

// Sites represents an ordered list of sites (languages).
type Sites []Site

// First is a convenience method to get the first Site, i.e. the main language.
func (s Sites) First() Site {
if len(s) == 0 {
return nil
}
return s[0]
}
6 changes: 3 additions & 3 deletions hugolib/sitemap.go → config/sitemap.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 The Hugo Authors. All rights reserved.
// Copyright 2019 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package hugolib
package config

import (
"github.com/spf13/cast"
Expand All @@ -25,7 +25,7 @@ type Sitemap struct {
Filename string
}

func parseSitemap(input map[string]interface{}) Sitemap {
func ParseSitemap(input map[string]interface{}) Sitemap {
sitemap := Sitemap{Priority: -1, Filename: "sitemap.xml"}

for key, value := range input {
Expand Down
6 changes: 3 additions & 3 deletions helpers/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type ContentSpec struct {
Highlight func(code, lang, optsStr string) (string, error)
defatultPygmentsOpts map[string]string

cfg config.Provider
Cfg config.Provider
}

// NewContentSpec returns a ContentSpec initialized
Expand All @@ -73,7 +73,7 @@ func NewContentSpec(cfg config.Provider) (*ContentSpec, error) {
BuildExpired: cfg.GetBool("buildExpired"),
BuildDrafts: cfg.GetBool("buildDrafts"),

cfg: cfg,
Cfg: cfg,
}

// Highlighting setup
Expand Down Expand Up @@ -376,7 +376,7 @@ func (c *ContentSpec) getMmarkHTMLRenderer(defaultFlags int, ctx *RenderingConte
return &HugoMmarkHTMLRenderer{
cs: c,
Renderer: mmark.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters),
Cfg: c.cfg,
Cfg: c.Cfg,
}
}

Expand Down
4 changes: 2 additions & 2 deletions helpers/content_renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

// Renders a codeblock using Blackfriday
func (c ContentSpec) render(input string) string {
ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx := &RenderingContext{Cfg: c.Cfg, Config: c.BlackFriday}
render := c.getHTMLRenderer(0, ctx)

buf := &bytes.Buffer{}
Expand All @@ -34,7 +34,7 @@ func (c ContentSpec) render(input string) string {

// Renders a codeblock using Mmark
func (c ContentSpec) renderWithMmark(input string) string {
ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx := &RenderingContext{Cfg: c.Cfg, Config: c.BlackFriday}
render := c.getMmarkHTMLRenderer(0, ctx)

buf := &bytes.Buffer{}
Expand Down
22 changes: 11 additions & 11 deletions helpers/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestTruncateWordsByRune(t *testing.T) {

func TestGetHTMLRendererFlags(t *testing.T) {
c := newTestContentSpec()
ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx := &RenderingContext{Cfg: c.Cfg, Config: c.BlackFriday}
renderer := c.getHTMLRenderer(blackfriday.HTML_USE_XHTML, ctx)
flags := renderer.GetFlags()
if flags&blackfriday.HTML_USE_XHTML != blackfriday.HTML_USE_XHTML {
Expand Down Expand Up @@ -210,7 +210,7 @@ func TestGetHTMLRendererAllFlags(t *testing.T) {
{blackfriday.HTML_SMARTYPANTS_LATEX_DASHES},
}
defaultFlags := blackfriday.HTML_USE_XHTML
ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx := &RenderingContext{Cfg: c.Cfg, Config: c.BlackFriday}
ctx.Config.AngledQuotes = true
ctx.Config.Fractions = true
ctx.Config.HrefTargetBlank = true
Expand All @@ -235,7 +235,7 @@ func TestGetHTMLRendererAllFlags(t *testing.T) {

func TestGetHTMLRendererAnchors(t *testing.T) {
c := newTestContentSpec()
ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx := &RenderingContext{Cfg: c.Cfg, Config: c.BlackFriday}
ctx.DocumentID = "testid"
ctx.Config.PlainIDAnchors = false

Expand All @@ -259,7 +259,7 @@ func TestGetHTMLRendererAnchors(t *testing.T) {

func TestGetMmarkHTMLRenderer(t *testing.T) {
c := newTestContentSpec()
ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx := &RenderingContext{Cfg: c.Cfg, Config: c.BlackFriday}
ctx.DocumentID = "testid"
ctx.Config.PlainIDAnchors = false
actualRenderer := c.getMmarkHTMLRenderer(0, ctx)
Expand All @@ -283,7 +283,7 @@ func TestGetMmarkHTMLRenderer(t *testing.T) {

func TestGetMarkdownExtensionsMasksAreRemovedFromExtensions(t *testing.T) {
c := newTestContentSpec()
ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx := &RenderingContext{Cfg: c.Cfg, Config: c.BlackFriday}
ctx.Config.Extensions = []string{"headerId"}
ctx.Config.ExtensionsMask = []string{"noIntraEmphasis"}

Expand All @@ -298,7 +298,7 @@ func TestGetMarkdownExtensionsByDefaultAllExtensionsAreEnabled(t *testing.T) {
testFlag int
}
c := newTestContentSpec()
ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx := &RenderingContext{Cfg: c.Cfg, Config: c.BlackFriday}
ctx.Config.Extensions = []string{""}
ctx.Config.ExtensionsMask = []string{""}
allExtensions := []data{
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestGetMarkdownExtensionsByDefaultAllExtensionsAreEnabled(t *testing.T) {

func TestGetMarkdownExtensionsAddingFlagsThroughRenderingContext(t *testing.T) {
c := newTestContentSpec()
ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx := &RenderingContext{Cfg: c.Cfg, Config: c.BlackFriday}
ctx.Config.Extensions = []string{"definitionLists"}
ctx.Config.ExtensionsMask = []string{""}

Expand All @@ -342,7 +342,7 @@ func TestGetMarkdownExtensionsAddingFlagsThroughRenderingContext(t *testing.T) {

func TestGetMarkdownRenderer(t *testing.T) {
c := newTestContentSpec()
ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx := &RenderingContext{Cfg: c.Cfg, Config: c.BlackFriday}
ctx.Content = []byte("testContent")
actualRenderedMarkdown := c.markdownRender(ctx)
expectedRenderedMarkdown := []byte("<p>testContent</p>\n")
Expand All @@ -353,7 +353,7 @@ func TestGetMarkdownRenderer(t *testing.T) {

func TestGetMarkdownRendererWithTOC(t *testing.T) {
c := newTestContentSpec()
ctx := &RenderingContext{RenderTOC: true, Cfg: c.cfg, Config: c.BlackFriday}
ctx := &RenderingContext{RenderTOC: true, Cfg: c.Cfg, Config: c.BlackFriday}
ctx.Content = []byte("testContent")
actualRenderedMarkdown := c.markdownRender(ctx)
expectedRenderedMarkdown := []byte("<nav>\n</nav>\n\n<p>testContent</p>\n")
Expand All @@ -368,7 +368,7 @@ func TestGetMmarkExtensions(t *testing.T) {
testFlag int
}
c := newTestContentSpec()
ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx := &RenderingContext{Cfg: c.Cfg, Config: c.BlackFriday}
ctx.Config.Extensions = []string{"tables"}
ctx.Config.ExtensionsMask = []string{""}
allExtensions := []data{
Expand Down Expand Up @@ -397,7 +397,7 @@ func TestGetMmarkExtensions(t *testing.T) {

func TestMmarkRender(t *testing.T) {
c := newTestContentSpec()
ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx := &RenderingContext{Cfg: c.Cfg, Config: c.BlackFriday}
ctx.Content = []byte("testContent")
actualRenderedMarkdown := c.mmarkRender(ctx)
expectedRenderedMarkdown := []byte("<p>testContent</p>\n")
Expand Down
2 changes: 1 addition & 1 deletion helpers/pygments.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type highlighters struct {
}

func newHiglighters(cs *ContentSpec) highlighters {
return highlighters{cs: cs, ignoreCache: cs.cfg.GetBool("ignoreCache"), cacheDir: cs.cfg.GetString("cacheDir")}
return highlighters{cs: cs, ignoreCache: cs.Cfg.GetBool("ignoreCache"), cacheDir: cs.Cfg.GetString("cacheDir")}
}

func (h highlighters) chromaHighlight(code, lang, optsStr string) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion hugolib/404_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

func Test404(t *testing.T) {
t.Parallel()
parallel(t)

b := newTestSitesBuilder(t)
b.WithSimpleConfigFile().WithTemplatesAdded("404.html", "<html><body>Not Found!</body></html>")
Expand Down
11 changes: 6 additions & 5 deletions hugolib/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/gohugoio/hugo/output"
"github.com/gohugoio/hugo/publisher"
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/tpl"

"github.com/gohugoio/hugo/helpers"
Expand Down Expand Up @@ -55,7 +56,7 @@ func newAliasHandler(t tpl.TemplateFinder, l *loggers.Logger, allowRoot bool) al
return aliasHandler{t, l, allowRoot}
}

func (a aliasHandler) renderAlias(isXHTML bool, permalink string, page *Page) (io.Reader, error) {
func (a aliasHandler) renderAlias(isXHTML bool, permalink string, p page.Page) (io.Reader, error) {
t := "alias"
if isXHTML {
t = "alias-xhtml"
Expand All @@ -77,10 +78,10 @@ func (a aliasHandler) renderAlias(isXHTML bool, permalink string, page *Page) (i
}
data := struct {
Permalink string
Page *Page
Page page.Page
}{
permalink,
page,
p,
}

buffer := new(bytes.Buffer)
Expand All @@ -91,11 +92,11 @@ func (a aliasHandler) renderAlias(isXHTML bool, permalink string, page *Page) (i
return buffer, nil
}

func (s *Site) writeDestAlias(path, permalink string, outputFormat output.Format, p *Page) (err error) {
func (s *Site) writeDestAlias(path, permalink string, outputFormat output.Format, p page.Page) (err error) {
return s.publishDestAlias(false, path, permalink, outputFormat, p)
}

func (s *Site) publishDestAlias(allowRoot bool, path, permalink string, outputFormat output.Format, p *Page) (err error) {
func (s *Site) publishDestAlias(allowRoot bool, path, permalink string, outputFormat output.Format, p page.Page) (err error) {
handler := newAliasHandler(s.Tmpl, s.Log, allowRoot)

isXHTML := strings.HasSuffix(path, ".xhtml")
Expand Down
8 changes: 4 additions & 4 deletions hugolib/alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ const basicTemplate = "<html><body>{{.Content}}</body></html>"
const aliasTemplate = "<html><body>ALIASTEMPLATE</body></html>"

func TestAlias(t *testing.T) {
t.Parallel()
parallel(t)
assert := require.New(t)

b := newTestSitesBuilder(t)
b.WithSimpleConfigFile().WithContent("page.md", pageWithAlias)
b.CreateSites().Build(BuildCfg{})

assert.Equal(1, len(b.H.Sites))
require.Len(t, b.H.Sites[0].RegularPages, 1)
require.Len(t, b.H.Sites[0].RegularPages(), 1)

// the real page
b.AssertFileContent("public/page/index.html", "For some moments the old man")
Expand All @@ -59,7 +59,7 @@ func TestAlias(t *testing.T) {
}

func TestAliasMultipleOutputFormats(t *testing.T) {
t.Parallel()
parallel(t)

assert := require.New(t)

Expand All @@ -85,7 +85,7 @@ func TestAliasMultipleOutputFormats(t *testing.T) {
}

func TestAliasTemplate(t *testing.T) {
t.Parallel()
parallel(t)

b := newTestSitesBuilder(t)
b.WithSimpleConfigFile().WithContent("page.md", pageWithAlias).WithTemplatesAdded("alias.html", aliasTemplate)
Expand Down
4 changes: 2 additions & 2 deletions hugolib/case_insensitive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Partial Site Global: {{ site.Params.COLOR }}|{{ site.Params.COLORS.YELLOW }}
}

func TestCaseInsensitiveConfigurationVariations(t *testing.T) {
t.Parallel()
parallel(t)

// See issues 2615, 1129, 2590 and maybe some others
// Also see 2598
Expand Down Expand Up @@ -227,7 +227,7 @@ Site Colors: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
}

func TestCaseInsensitiveConfigurationForAllTemplateEngines(t *testing.T) {
t.Parallel()
parallel(t)

noOp := func(s string) string {
return s
Expand Down
25 changes: 24 additions & 1 deletion hugolib/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

var (
// TODO(bep) page move
// TODO(bep) page move/remove
_ collections.Grouper = (*Page)(nil)
_ collections.Slicer = (*Page)(nil)
_ collections.Slicer = page.PageGroup{}
Expand Down Expand Up @@ -50,3 +50,26 @@ func (p *Page) Group(key interface{}, in interface{}) (interface{}, error) {
}
return page.PageGroup{Key: key, Pages: pages}, nil
}

// collections.Slicer implementations below. We keep these bridge implementations
// here as it makes it easier to get an idea of "type coverage". These
// implementations have no value on their own.

// Slice is not meant to be used externally. It's a bridge function
// for the template functions. See collections.Slice.
func (p *pageState) Slice(items interface{}) (interface{}, error) {
return page.ToPages(items)
}

// collections.Grouper implementations below

// Group creates a PageGroup from a key and a Pages object
// This method is not meant for external use. It got its non-typed arguments to satisfy
// a very generic interface in the tpl package.
func (p *pageState) Group(key interface{}, in interface{}) (interface{}, error) {
pages, err := page.ToPages(in)
if err != nil {
return nil, err
}
return page.PageGroup{Key: key, Pages: pages}, nil
}
6 changes: 3 additions & 3 deletions hugolib/collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ title: "Page"
b.CreateSites().Build(BuildCfg{})

assert.Equal(1, len(b.H.Sites))
require.Len(t, b.H.Sites[0].RegularPages, 2)
require.Len(t, b.H.Sites[0].RegularPages(), 2)

b.AssertFileContent("public/index.html", "cool: 2")
}
Expand Down Expand Up @@ -79,7 +79,7 @@ tags_weight: %d
b.CreateSites().Build(BuildCfg{})

assert.Equal(1, len(b.H.Sites))
require.Len(t, b.H.Sites[0].RegularPages, 2)
require.Len(t, b.H.Sites[0].RegularPages(), 2)

b.AssertFileContent("public/index.html",
"pages:2:page.Pages:Page(/page1.md)/Page(/page2.md)",
Expand Down Expand Up @@ -129,7 +129,7 @@ tags_weight: %d
b.CreateSites().Build(BuildCfg{})

assert.Equal(1, len(b.H.Sites))
require.Len(t, b.H.Sites[0].RegularPages, 2)
require.Len(t, b.H.Sites[0].RegularPages(), 2)

b.AssertFileContent("public/index.html",
"pages:2:page.Pages:Page(/page2.md)/Page(/page1.md)",
Expand Down
2 changes: 1 addition & 1 deletion hugolib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ func loadDefaultSettingsFor(v *viper.Viper) error {
v.SetDefault("titleCaseStyle", "AP")
v.SetDefault("taxonomies", map[string]string{"tag": "tags", "category": "categories"})
v.SetDefault("permalinks", make(PermalinkOverrides, 0))
v.SetDefault("sitemap", Sitemap{Priority: -1, Filename: "sitemap.xml"})
v.SetDefault("sitemap", config.Sitemap{Priority: -1, Filename: "sitemap.xml"})
v.SetDefault("pygmentsStyle", "monokai")
v.SetDefault("pygmentsUseClasses", false)
v.SetDefault("pygmentsCodeFences", false)
Expand Down
Loading

0 comments on commit bdd299b

Please sign in to comment.