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