Skip to content

Commit

Permalink
Move Pages to resources/page
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Feb 2, 2019
1 parent eb802f8 commit b651a69
Show file tree
Hide file tree
Showing 129 changed files with 6,927 additions and 3,697 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
12 changes: 6 additions & 6 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 All @@ -141,16 +141,16 @@ func (cc *convertCmd) convertAndSavePage(p *hugolib.Page, site *hugolib.Site, ta
}
}

if p.Filename() == "" {
if p.File().Filename() == "" {
// No content file.
return nil
}

errMsg := fmt.Errorf("Error processing file %q", p.Path())

site.Log.INFO.Println("Attempting to convert", p.LogicalName())
site.Log.INFO.Println("Attempting to convert", p.File().Filename())

f, _ := p.File.(src.ReadableFile)
f, _ := p.File().(src.ReadableFile)
file, err := f.Open()
if err != nil {
site.Log.ERROR.Println(errMsg)
Expand Down Expand Up @@ -186,7 +186,7 @@ func (cc *convertCmd) convertAndSavePage(p *hugolib.Page, site *hugolib.Site, ta

newContent.Write(pf.content)

newFilename := p.Filename()
newFilename := p.File().Filename()

if cc.outputDir != "" {
contentDir := strings.TrimSuffix(newFilename, p.Path())
Expand Down
6 changes: 3 additions & 3 deletions commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ List requires a subcommand, e.g. ` + "`hugo list drafts`.",
for _, p := range sites.Pages() {
pp := p.(*hugolib.Page)
if pp.IsDraft() {
jww.FEEDBACK.Println(filepath.Join(pp.File.Dir(), pp.File.LogicalName()))
jww.FEEDBACK.Println(filepath.Join(pp.File().Dir(), pp.File().LogicalName()))
}

}
Expand Down Expand Up @@ -106,7 +106,7 @@ posted in the future.`,
for _, p := range sites.Pages() {
if resource.IsFuture(p) {
pp := p.(*hugolib.Page)
jww.FEEDBACK.Println(filepath.Join(pp.File.Dir(), pp.File.LogicalName()))
jww.FEEDBACK.Println(filepath.Join(pp.File().Dir(), pp.File().LogicalName()))
}

}
Expand Down Expand Up @@ -143,7 +143,7 @@ expired.`,
for _, p := range sites.Pages() {
if resource.IsExpired(p) {
pp := p.(*hugolib.Page)
jww.FEEDBACK.Println(filepath.Join(pp.File.Dir(), pp.File.LogicalName()))
jww.FEEDBACK.Println(filepath.Join(pp.File().Dir(), pp.File().LogicalName()))
}

}
Expand Down
1 change: 1 addition & 0 deletions common/hugio/readers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ReadSeekCloser interface {
}

// ReadSeekerNoOpCloser implements ReadSeekCloser by doing nothing in Close.
// TODO(bep) rename this and simila to ReadSeekerNopCloser, naming used in stdlib, which kind of makes sense.
type ReadSeekerNoOpCloser struct {
ReadSeeker
}
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]
}
12 changes: 12 additions & 0 deletions config/configProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ func GetStringSlicePreserveString(cfg Provider, key string) []string {
}
return cast.ToStringSlice(sd)
}

// SetBaseTestDefaults provides some common config defaults used in tests.
func SetBaseTestDefaults(cfg Provider) {
cfg.Set("resourceDir", "resources")
cfg.Set("contentDir", "content")
cfg.Set("dataDir", "data")
cfg.Set("i18nDir", "i18n")
cfg.Set("layoutDir", "layouts")
cfg.Set("assetDir", "assets")
cfg.Set("archetypeDir", "archetypes")
cfg.Set("publishDir", "public")
}
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
15 changes: 4 additions & 11 deletions docs/content/en/variables/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ See [`.Scratch`](/functions/scratch/) for page-scoped, writable variables.
: the page's *kind*. Possible return values are `page`, `home`, `section`, `taxonomy`, or `taxonomyTerm`. Note that there are also `RSS`, `sitemap`, `robotsTXT`, and `404` kinds, but these are only available during the rendering of each of these respective page's kind and therefore *not* available in any of the `Pages` collections.

.Language
: a language object that points to the language's definition in the site
`config`.
: a language object that points to the language's definition in the site `config`. `.Language.Lang` gives you the language code.

.Lastmod
: the date the content was last modified. `.Lastmod` pulls from the `lastmod` field in a content's front matter.
Expand All @@ -93,10 +92,7 @@ See also `.ExpiryDate`, `.Date`, `.PublishDate`, and [`.GitInfo`][gitinfo].
.LinkTitle
: access when creating links to the content. If set, Hugo will use the `linktitle` from the front matter before `title`.

.Next (deprecated)
: In older Hugo versions this pointer went the wrong direction. Please use `.PrevPage` instead.

.NextPage
.Next
: Pointer to the next [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight-date-linktitle-filepath)). Example: `{{if .NextPage}}{{.NextPage.Permalink}}{{end}}`.

.NextInSection
Expand All @@ -119,9 +115,6 @@ See also `.ExpiryDate`, `.Date`, `.PublishDate`, and [`.GitInfo`][gitinfo].
: the Page content stripped of HTML as a `[]string` using Go's [`strings.Fields`](https://golang.org/pkg/strings/#Fields) to split `.Plain` into a slice.

.Prev (deprecated)
: In older Hugo versions this pointer went the wrong direction. Please use `.NextPage` instead.

.PrevPage
: Pointer to the previous [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight-date-linktitle-filepath)). Example: `{{if .PrevPage}}{{.PrevPage.Permalink}}{{end}}`.

.PrevInSection
Expand All @@ -130,8 +123,8 @@ See also `.ExpiryDate`, `.Date`, `.PublishDate`, and [`.GitInfo`][gitinfo].
.PublishDate
: the date on which the content was or will be published; `.Publishdate` pulls from the `publishdate` field in a content's front matter. See also `.ExpiryDate`, `.Date`, and `.Lastmod`.

.RSSLink
: link to the taxonomies' RSS link.
.RSSLink (deprecated)
: link to the page's RSS feed. This is deprecated. You should instead do something like this: `{{ with .OutputFormats.Get "RSS" }}{{ . RelPermalink }}{{ end }}`.

.RawContent
: raw markdown content without the front matter. Useful with [remarkjs.com](
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
Loading

0 comments on commit b651a69

Please sign in to comment.