Debian Codegraph @

hugofs/hugofs_integration_test.go

raw
1 // Copyright 2025 The Hugo Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package hugofs_test
15
16 import (
17 "strings"
18 "testing"
19
20 qt "github.com/frankban/quicktest"
21
22 "github.com/gohugoio/hugo/hugolib"
23 )
24
25 func TestMountRestrictTheme(t *testing.T) {
26 files := `
27 -- hugo.toml --
28 disableKinds = ["taxonomy", "term", "rss"]
29 theme = "mytheme"
30 [[module.mounts]]
31 source = '../file2.txt'
32 target = 'assets/file2.txt'
33 -- themes/mytheme/hugo.toml --
34 [[module.mounts]]
35 source = '../../file1.txt'
36 target = 'assets/file1.txt'
37 -- file1.txt --
38 file1
39 -- file2.txt --
40 file2
41 -- layouts/all.html --
42 All.
43 `
44 b, err := hugolib.TestE(t, files)
45 b.Assert(err, qt.IsNotNil)
46 b.Assert(err.Error(), qt.Contains, "mount source must be a local path for modules/themes")
47 }
48
49 // Issue 14089.
50 func TestMountNodeMoudulesFromTheme(t *testing.T) {
51 filesTemplate := `
52 -- hugo.toml --
53 disableKinds = ["taxonomy", "term", "rss"]
54 theme = "mytheme"
55 -- node_modules/bootstrap/foo.txt --
56 foo project.
57 -- layouts/all.html --
58 {{ $foo := resources.Get "vendor/bootstrap/foo.txt" }}
59 Foo: {{ with $foo }}{{ .Content }}{{ else }}Fail{{ end }}
60 -- themes/mytheme/hugo.toml --
61 [[module.mounts]]
62 source = 'NODE_MODULES_SOURCE' # tries first in theme, then in project root
63 target = 'assets/vendor/bootstrap'
64
65 `
66 runFiles := func(files string) *hugolib.IntegrationTestBuilder {
67 return hugolib.Test(t, files, hugolib.TestOptOsFs())
68 }
69 files := strings.ReplaceAll(filesTemplate, "NODE_MODULES_SOURCE", "node_modules/bootstrap")
70 b := runFiles(files)
71 b.AssertFileContent("public/index.html", "Foo: foo project.")
72
73 // This is for backwards compatibility. ../../node_modules/bootstrap works exactly the same as node_modules/bootstrap.
74 files = strings.ReplaceAll(filesTemplate, "NODE_MODULES_SOURCE", "../../node_modules/bootstrap")
75 b = runFiles(files)
76 b.AssertFileContent("public/index.html", "Foo: foo project.")
77
78 files = strings.ReplaceAll(filesTemplate, "NODE_MODULES_SOURCE", "node_modules/bootstrap")
79 files += `
80 -- themes/mytheme/node_modules/bootstrap/foo.txt --
81 foo theme.
82 `
83
84 b = runFiles(files)
85 b.AssertFileContent("public/index.html", "Foo: foo theme.")
86 }
87
88 func TestMultipleMountsOfTheSameContentDirectoryIssue13818(t *testing.T) {
89 files := `
90 -- hugo.toml --
91
92 [[module.mounts]]
93 source = 'shared/tutorials'
94 target = 'content/product1/tutorials'
95
96 [[module.mounts]]
97 source = 'shared/tutorials'
98 target = 'content/product2/tutorials'
99
100 -- shared/tutorials/tutorial1.md --
101 ---
102 title: "Tutorial 1"
103 ---
104 -- shared/tutorials/tutorial2.md --
105 ---
106 title: "Tutorial 2"
107 ---
108 -- layouts/all.html --
109 Title: {{ .Title }}|
110
111 `
112 b := hugolib.Test(t, files)
113
114 b.AssertPublishDir(`
115 product1/tutorials/tutorial1/index.html
116 product1/tutorials/tutorial2/index.html
117 product2/tutorials/tutorial1/index.html
118 product2/tutorials/tutorial2/index.html
119 `)
120 }
121
122 func TestContentDirPerLangNoDeprecationPleaseIssue14287(t *testing.T) {
123 files := `
124 -- hugo.toml --
125 defaultContentLanguage = "en"
126 defaultContentLanguageInSubdir = true
127 [languages]
128 [languages.en]
129 contentDir = "content/en"
130 [languages.fr]
131 contentDir = "content/fr"
132 -- content/en/page.md --
133 ---
134 title: "English Page"
135 ---
136 -- content/fr/page.md --
137 ---
138 title: "Page Française"
139 ---
140 -- layouts/all.html --
141 Title: {{ .Title }}|
142 --
143 `
144 b := hugolib.Test(t, files, hugolib.TestOptInfo())
145
146 b.AssertFileContent("public/en/page/index.html", "Title: English Page|")
147 b.AssertFileContent("public/fr/page/index.html", "Title: Page Française|")
148 b.AssertLogContains("! deprecated")
149 }