mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 20:12:09 -05:00
9185e11eff
The old implementation had some issues, mostly related to the context (e.g. name, file paths) passed to the template. This new implementation is using the exact same code path for evaluating the pages as in a regular build. This also makes it more robust and easier to reason about in a multilingual setup. Now, if you are explicit about the target path, Hugo will now always pick the correct mount and language: ```bash hugo new content/en/posts/my-first-post.md ``` Fixes #9032 Fixes #7589 Fixes #9043 Fixes #9046 Fixes #9047
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
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"))
|
|
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.AppplyArchetypeFilename(&buf, p, "", "post.md"), qt.IsNil)
|
|
|
|
b.Assert(buf.String(), qt.Contains, `title: "Mypage"`)
|
|
})
|
|
|
|
}
|