hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

content_factory_test.go (1813B)

    1 package hugolib
    2 
    3 import (
    4 	"bytes"
    5 	"path/filepath"
    6 	"testing"
    7 
    8 	qt "github.com/frankban/quicktest"
    9 )
   10 
   11 func TestContentFactory(t *testing.T) {
   12 	t.Parallel()
   13 
   14 	c := qt.New(t)
   15 
   16 	c.Run("Simple", func(c *qt.C) {
   17 		workingDir := "/my/work"
   18 		b := newTestSitesBuilder(c)
   19 		b.WithWorkingDir(workingDir).WithConfigFile("toml", `
   20 
   21 workingDir="/my/work"
   22 
   23 [module]
   24 [[module.mounts]]
   25 source = 'mcontent/en'
   26 target = 'content'
   27 lang  = 'en'
   28 [[module.mounts]]
   29 source = 'archetypes'
   30 target = 'archetypes'
   31 	
   32 `)
   33 
   34 		b.WithSourceFile(filepath.Join("mcontent/en/bundle", "index.md"), "")
   35 
   36 		b.WithSourceFile(filepath.Join("archetypes", "post.md"), `---
   37 title: "{{ replace .Name "-" " " | title }}"
   38 date: {{ .Date }}
   39 draft: true
   40 ---
   41 
   42 Hello World.
   43 `)
   44 		b.CreateSites()
   45 		cf := NewContentFactory(b.H)
   46 		abs, err := cf.CreateContentPlaceHolder(filepath.FromSlash("mcontent/en/blog/mypage.md"))
   47 		b.Assert(err, qt.IsNil)
   48 		b.Assert(abs, qt.Equals, filepath.FromSlash("/my/work/mcontent/en/blog/mypage.md"))
   49 		b.Build(BuildCfg{SkipRender: true})
   50 
   51 		p := b.H.GetContentPage(abs)
   52 		b.Assert(p, qt.Not(qt.IsNil))
   53 
   54 		var buf bytes.Buffer
   55 		b.Assert(cf.ApplyArchetypeFilename(&buf, p, "", "post.md"), qt.IsNil)
   56 
   57 		b.Assert(buf.String(), qt.Contains, `title: "Mypage"`)
   58 	})
   59 
   60 	// Issue #9129
   61 	c.Run("Content in both project and theme", func(c *qt.C) {
   62 		b := newTestSitesBuilder(c)
   63 		b.WithConfigFile("toml", `
   64 theme = 'ipsum'		
   65 `)
   66 
   67 		themeDir := filepath.Join("themes", "ipsum")
   68 		b.WithSourceFile("content/posts/foo.txt", `Hello.`)
   69 		b.WithSourceFile(filepath.Join(themeDir, "content/posts/foo.txt"), `Hello.`)
   70 		b.CreateSites()
   71 		cf := NewContentFactory(b.H)
   72 		abs, err := cf.CreateContentPlaceHolder(filepath.FromSlash("posts/test.md"))
   73 		b.Assert(err, qt.IsNil)
   74 		b.Assert(abs, qt.Equals, filepath.FromSlash("content/posts/test.md"))
   75 
   76 	})
   77 
   78 }