mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-16 20:53:59 +02:00
Fix handling of HTML files without front matter
This means that any HTML file inside /content will be treated as a regular file. If you want it processes with shortcodes and a layout, add front matter. The defintion of an HTML file here is: * File with extension .htm or .html * With first non-whitespace character "<" that isn't a HTML comment. This is in line with the documentation. Fixes #7030 Fixes #7028 See #6789
This commit is contained in:
@@ -245,87 +245,6 @@ Page Content
|
||||
|
||||
}
|
||||
|
||||
func TestTemplateLateTemplates(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := newTestSitesBuilder(t).WithSimpleConfigFile().Running()
|
||||
|
||||
numPages := 500 // To get some parallelism
|
||||
homeTempl := `
|
||||
Len RegularPages: {{ len site.RegularPages }}
|
||||
{{ range site.RegularPages }}
|
||||
Link: {{ .RelPermalink }} Len Content: {{ len .Content }}
|
||||
{{ end }}
|
||||
`
|
||||
pageTemplate := `<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>{{ .RelPermalink }}</title>
|
||||
<meta name="description" content="The HTML5 Herald">
|
||||
<meta name="author" content="SitePoint">
|
||||
<link rel="stylesheet" href="css/styles.css?v=1.0">
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{ .RelPermalink }}</h1>
|
||||
<p>Shortcode: {{< shortcode >}}</p>
|
||||
<p>Partial: {{ partial "mypartial.html" . }}</p>
|
||||
<script src="js/scripts.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
|
||||
b.WithTemplatesAdded(
|
||||
"index.html", homeTempl,
|
||||
"partials/mypartial.html", `this my partial`,
|
||||
)
|
||||
|
||||
// Make sure we get some parallelism.
|
||||
for i := 0; i < numPages; i++ {
|
||||
b.WithContent(fmt.Sprintf("page%d.html", i+1), pageTemplate)
|
||||
}
|
||||
|
||||
b.Build(BuildCfg{})
|
||||
|
||||
b.AssertFileContent("public/index.html", fmt.Sprintf(`
|
||||
Len RegularPages: %d
|
||||
Link: /page3/ Len Content: 0
|
||||
Link: /page22/ Len Content: 0
|
||||
`, numPages))
|
||||
|
||||
for i := 0; i < numPages; i++ {
|
||||
b.AssertFileContent(fmt.Sprintf("public/page%d/index.html", i+1),
|
||||
fmt.Sprintf(`<title>/page%d/</title>`, i+1),
|
||||
`<p>Shortcode: Shortcode: Hello</p>`,
|
||||
"<p>Partial: this my partial</p>",
|
||||
)
|
||||
}
|
||||
|
||||
b.EditFiles(
|
||||
"layouts/partials/mypartial.html", `this my changed partial`,
|
||||
"layouts/index.html", (homeTempl + "CHANGED"),
|
||||
)
|
||||
for i := 0; i < 5; i++ {
|
||||
b.EditFiles(fmt.Sprintf("content/page%d.html", i+1), pageTemplate+"CHANGED")
|
||||
}
|
||||
|
||||
b.Build(BuildCfg{})
|
||||
b.AssertFileContent("public/index.html", fmt.Sprintf(`
|
||||
Len RegularPages: %d
|
||||
Link: /page3/ Len Content: 0
|
||||
Link: /page2/ Len Content: 0
|
||||
CHANGED
|
||||
`, numPages))
|
||||
for i := 0; i < 5; i++ {
|
||||
b.AssertFileContent(fmt.Sprintf("public/page%d/index.html", i+1),
|
||||
fmt.Sprintf(`<title>/page%d/</title>`, i+1),
|
||||
`<p>Shortcode: Shortcode: Hello</p>`,
|
||||
"<p>Partial: this my changed partial</p>",
|
||||
"CHANGED",
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestTemplateManyBaseTemplates(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := newTestSitesBuilder(t).WithSimpleConfigFile()
|
||||
|
Reference in New Issue
Block a user