As introduced in v0.146.0. Keep some legecy test to preserve backwards compatibility.
---
-- assets/a/pixel.png --
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
--- layouts/index.html --
+-- layouts/home.html --
{{ warnf "HOME!" }}
{{ $img := resources.GetMatch "**.png" }}
{{ $img = $img.Resize "3x3" }}
files := `
-- config.toml --
defaultContentLanguage = 'it'
--- layouts/index.html --
+-- layouts/home.html --
{{ $dates := slice
"2022-01-03"
"2022-02-01"
---
title: home
---
--- layouts/index.html --
+-- layouts/home.html --
multilingual={{ hugo.IsMultilingual }}
multihost={{ hugo.IsMultihost }}
`
removePathAccents = true
-- content/διακριτικός.md --
-- content/διακριτικός.fr.md --
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Language.Lang }}|Single.
--- layouts/_default/list.html --
+-- layouts/list.html --
List
`
b := hugolib.Test(t, files)
-- content/MySection/MyPage.fr.md --
-- content/MySection/MyBundle/index.md --
-- content/MySection/MyBundle/index.fr.md --
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Language.Lang }}|Single.
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Language.Lang }}|List.
`
b := hugolib.Test(t, files)
---
title: "p1"
---
--- layouts/_default/single.html --
+-- layouts/single.html --
Title: {{ .Title }}
`
[pagination]
disableAliases = true
pagerSize = 2
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ $paginator := .Paginate site.RegularPages }}
{{ template "_internal/pagination.html" . }}
{{ range $paginator.Pages }}
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
[outputs]
home = ['html','foo']
--- layouts/index.html --
+-- layouts/home.html --
x
`
disableLiveReload = true
[internal]
fastRenderMode = true
--- layouts/_default/baseof.html --
+-- layouts/baseof.html --
Base: {{ block "main" . }}{{ end }}
-- layouts/404.html --
{{ define "main" }}
files := `
-- hugo.toml --
baseURL = "http://example.com"
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
--- layouts/_default/single.amp.html --
+-- layouts/single.amp.html --
{{ .Content }}
--- layouts/_default/single.json --
+-- layouts/single.json --
{{ .Content }}
-- content/blog/page.md --
---
title: P2
tags: [t1, t2]
---
--- layouts/_default/list.html --
+-- layouts/list.html --
List: {{ len .Pages }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: Tags: {{ site.Taxonomies.tags }}|
`
baseURL = "https://example.com"
disableKinds = ['sitemap','rss', 'home', 'taxonomy','term']
disableLiveReload = true
--- layouts/_default/list.html --
+-- layouts/list.html --
Title: {{ .Title }}|{{ .Content }}|cascadeparam: {{ .Params.cascadeparam }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
Title: {{ .Title }}|{{ .Content }}|cascadeparam: {{ .Params.cascadeparam }}|
-- content/mysect/_index.md --
---
---
title: p1
---
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Title }}|
`
b := Test(t, files)
---
title: p1
---
--- layouts/_default/single.html --
+-- layouts/single.html --
Background: {{ .Params.background }}|
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Title }}|
`
files := `
-- hugo.toml --
disableKinds = ['home','rss','sitemap','taxonomy','term']
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Title }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
-- content/s/_index.md --
---
[params.pm2]
pm21 = "pm21base"
pm22 = "pm22base"
--- layouts/index.html --
+-- layouts/home.html --
p1: {{ .Site.Params.p1 }}
p2: {{ .Site.Params.p2 }}
pm21: {{ .Site.Params.pm2.pm21 }}
sub1 = "sub1en"
[languages.sv]
title = "Svensk Title Theme"
--- layouts/index.html --
+-- layouts/home.html --
title: {{ .Title }}|
p1: {{ .Site.Params.p1 }}|
p2: {{ .Site.Params.p2 }}|
[languages.no]
weight = 3
--- layouts/index.html --
+-- layouts/home.html --
Home.
`
-- themes/test-theme/config/production/config.toml --
[params]
t3 = "tv3p"
--- layouts/index.html --
+-- layouts/home.html --
m1: {{ .Site.Params.m1 }}
m2: {{ .Site.Params.m2 }}
t1: {{ .Site.Params.t1 }}
someOtherValue = "foo"
[privacy.youtube]
privacyEnhanced = true
--- layouts/index.html --
+-- layouts/home.html --
Privacy Enhanced: {{ .Site.Config.Privacy.YouTube.PrivacyEnhanced }}
`
b := Test(t, files)
defaultMarkdownHandler = 'blackfriday'
-- content/_index.md --
## Foo
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
`
-- themes/mytheme/hugo.toml --
[params]
themeparam = "themevalue"
--- layouts/index.html --
+-- layouts/home.html --
rootparam: {{ site.Params.rootparam }}
rootconfigparam: {{ site.Params.rootconfigparam }}
themeparam: {{ site.Params.themeparam }}
title = "Swedish"
wEight = WEIGHT_SV
disableKinds = ["page"]
--- layouts/index.html --
+-- layouts/home.html --
Home: {{ .Lang}}|{{ len site.RegularPages }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
-- content/p1.en.md --
-- content/p2.en.md --
[outputFormats.myformat]
baseName = 'myindex'
mediaType = 'text/html'
--- layouts/index.html --
+-- layouts/home.html --
Home.
title = "Svensk Title"
[languages.sv.params]
myparam = "svParamValue"
--- layouts/index.html --
+-- layouts/home.html --
MyParam: {{ site.Params.myparam }}
ThisIsAParam: {{ site.Params.thisIsAParam }}
---
title: "My Swedish Section"
---
--- layouts/index.html --
+-- layouts/home.html --
LanguageCode: {{ eq site.LanguageCode site.Language.LanguageCode }}|{{ site.Language.LanguageCode }}|
{{ range $i, $e := (slice site .Site) }}
{{ $i }}|AllPages: {{ len .AllPages }}|Sections: {{ if .Sections }}true{{ end }}|BuildDrafts: {{ .BuildDrafts }}|Param: {{ .Language.Params.myparam }}|Language string: {{ .Language }}|Languages: {{ .Languages }}
mainSections:
-- content/mysection/_index.md --
-- content/mysection/mycontent.md --
--- layouts/index.html --
+-- layouts/home.html --
mainSections: {{ site.Params.mainSections }}
`
files := `
-- hugo.toml --
--- layouts/index.html --
+-- layouts/home.html --
WorkingDir: {{ hugo.WorkingDir }}|
`
[languages.de.markup.goldmark.extensions.typographer]
leftDoubleQuote = '«' # default “
rightDoubleQuote = '»' # default ”
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
p1: {{ site.Params.p1 }}|
-- content/_index.en.md --
# taxonomyTerm was renamed to taxonomy in Hugo 0.60.0.
disableKinds = ["taxonomyTerm"]
--- layouts/index.html --
+-- layouts/home.html --
Home
`
---
outputs: ["html", "htaccess"]
---
--- layouts/index.html --
+-- layouts/home.html --
HTML.
--- layouts/_default/list.htaccess --
+-- layouts/list.htaccess --
HTACCESS.
files := `
-- hugo.toml --
languageCode = "en-US"
--- layouts/index.html --
+-- layouts/home.html --
LanguageCode: {{ .Site.LanguageCode }}|{{ site.Language.LanguageCode }}|
[languages.sv.mediatypes."text/html"]
suffixes = ["bar"]
--- layouts/index.html --
+-- layouts/home.html --
Home.
files := `
-- hugo.yaml --
params:
--- layouts/index.html --
+-- layouts/home.html --
Foo: {{ site.Params.foo }}|
lang = "en"
languageName = "English"
weight = 1
--- layouts/index.html --
+-- layouts/home.html --
Foo: {{ site.Params.foo }}|
-- hugo.toml --
baseURL = "https://example.org"
contentDir = "mycontent"
--- layouts/index.html --
+-- layouts/home.html --
Home.
disableKinds = ["taxonomy", "term", "page", "section"]
-- content/foo/bar.txt --
Foo.
--- layouts/index.html --
+-- layouts/home.html --
Home.
`
b := Test(t, files)
title = "Swedish Title"
-- content/foo/bar.txt --
Foo.
--- layouts/index.html --
+-- layouts/home.html --
Home.
`
b := Test(t, files)
title = "Swedish Title"
-- content/foo/bar.txt --
Foo.
--- layouts/index.html --
+-- layouts/home.html --
Home.
`
b := Test(t, files)
[languages.sv]
title = "Swedish Title"
disabled = true
--- layouts/index.html --
+-- layouts/home.html --
Home.
title = "English Title"
[languages.sv]
title = "Swedish Title"
--- layouts/index.html --
+-- layouts/home.html --
Home.
title: "P1"
categories: ["c1"]
---
--- layouts/index.html --
+-- layouts/home.html --
Home.
--- layouts/_default/list.html --
+-- layouts/list.html --
List.
disableKinds = ['foo', 'home']
[outputs]
foo = ['HTML', 'AMP', 'RSS']
--- layouts/_default/list.html --
+-- layouts/list.html --
List.
disableKinds = ['taxonomyTerm']
[outputs]
taxonomyterm = ['HTML', 'AMP', 'RSS']
--- layouts/_default/list.html --
+-- layouts/list.html --
List.
[languages.pt]
weight = 2
title = "Portuguese"
--- layouts/index.html --
+-- layouts/home.html --
Home.
-- content/custom/index.br.md --
---
a = "a1"
b = "b1"
c = "c1"
--- layouts/index.html --
+-- layouts/home.html --
Params: {{ site.Params}}
`
b := Test(t, files)
files := `
-- hugo.toml --
baseURL = "http://example.com"
--- layouts/index.html --
+-- layouts/home.html --
Num Regular: {{ len .Site.RegularPages }}|{{ range .Site.RegularPages }}{{ .RelPermalink }}|{{ end }}$
Main Sections: {{ .Site.Params.mainSections }}
Pag Num Pages: {{ len .Paginator.Pages }}
-- config.toml --
title = "Integration Test"
disableKinds=["page", "section", "taxonomy", "term", "sitemap", "robotsTXT", "RSS"]
--- layouts/index.html --
+-- layouts/home.html --
Home: {{ .Title }}|
`
weight = 2
[languages.de]
weight = 3
--- layouts/index.html --
+-- layouts/home.html --
{{ $bundle := site.GetPage "bundle" }}
{{ $r := $bundle.Resources.GetMatch "*.txt" }}
{{ .Language.Lang }}: {{ with $r }}{{ .RelPermalink }}|{{ .Content }}{{ end}}
-- content/bundle/index.md --
-- content/bundle/data with Spaces.txt --
Data.
--- layouts/index.html --
+-- layouts/home.html --
{{ $bundle := site.GetPage "bundle" }}
{{ $r := $bundle.Resources.Get "data with Spaces.txt" }}
R: {{ with $r }}{{ .Content }}{{ end }}|
Data 1.txt
-- content/bundle/Data-1.txt --
Data-1.txt
--- layouts/index.html --
+-- layouts/home.html --
{{ $bundle := site.GetPage "bundle" }}
{{ $r := $bundle.Resources.Get "data-1.txt" }}
R: {{ with $r }}{{ .Content }}{{ end }}|Len: {{ len $bundle.Resources }}|$
p1.txt
-- content/s1/p1-foo.txt --
p1-foo.txt
--- layouts/_default/list.html --
+-- layouts/list.html --
{{.Title }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
{{.Title }}|
`
---
-- content/s1x/a.txt --
a.txt
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ range .Resources.Match "**" }}
{{ .Name }}|
[languages.en]
[sitemap]
filename = 'foo.xml'
--- layouts/index.html --
+-- layouts/home.html --
irrelevant
`
<p>b</p>
-- content/p1/c.html --
<p>c</p>
--- layouts/_default/single.html --
+-- layouts/single.html --
Path: {{ .Path }}|{{.Kind }}
|{{ (.Resources.Get "a.html").RelPermalink -}}
|{{ (.Resources.Get "b.html").RelPermalink -}}
-- hugo.toml --
baseURL = "https://example.org"
disableKinds = ["taxonomy", "term"]
--- layouts/index.html --
+-- layouts/home.html --
{{ $p := site.GetPage "p1.md" }}
{{ $p2 := site.GetPage "p2.md" }}
P1: {{ $p.Content }}
{{ $p3 := site.GetPage "p3.md" }}
P2: {{ $p2.Content }}
P3: {{ $p3.Content }}
--- layouts/_default/_markup/render-link.html --
+-- layouts/_markup/render-link.html --
html-link: {{ .Destination | safeURL }}|
--- layouts/_default/_markup/render-link.rss.xml --
+-- layouts/_markup/render-link.rss.xml --
xml-link: {{ .Destination | safeURL }}|
--- layouts/_default/_markup/render-heading.html --
+-- layouts/_markup/render-heading.html --
html-heading: {{ .Text }}|
--- layouts/_default/_markup/render-heading.rss.xml --
+-- layouts/_markup/render-heading.rss.xml --
xml-heading: {{ .Text }}|
-- content/p1.md --
---
-- hugo.toml --
baseURL = "https://example.org"
disableKinds = ["taxonomy", "term"]
--- layouts/index.html --
+-- layouts/home.html --
{{ $p := site.GetPage "p1.md" }}
{{ $p2 := site.GetPage "p2.md" }}
P1: {{ $p.Content }}
{{ $p3 := site.GetPage "p3.md" }}
P2: {{ $p2.Content }}
P3: {{ $p3.Content }}
--- layouts/_default/_markup/render-link.rss.xml --
+-- layouts/_markup/render-link.rss.xml --
xml-link: {{ .Destination | safeURL }}|
--- layouts/_default/_markup/render-heading.rss.xml --
+-- layouts/_markup/render-heading.rss.xml --
xml-heading: {{ .Text }}|
-- content/p1.md --
---
[markup.goldmark]
[markup.goldmark.renderer]
unsafe = true
--- layouts/index.html --
+-- layouts/home.html --
{{ $p := site.GetPage "p1.md" }}
P1: {{ $p.Content }}
--- layouts/_default/_markup/render-link.html --
+-- layouts/_markup/render-link.html --
html-link: {{ .Destination | safeURL }}|Text: {{ .Text }}|Plain: {{ .PlainText | safeHTML }}
--- layouts/_default/_markup/render-image.html --
+-- layouts/_markup/render-image.html --
html-image: {{ .Destination | safeURL }}|Text: {{ .Text }}|Plain: {{ .PlainText | safeHTML }}
-- content/p1.md --
---
## E
## F
--- layouts/_default/_markup/render-heading.html --
+-- layouts/_markup/render-heading.html --
Heading: {{ .Text }}|
{{ with .Page }}
Self Fragments: {{ .Fragments.Identifiers }}|
{{ with (site.GetPage "p1.md") }}
P1 Fragments: {{ .Fragments.Identifiers }}|
{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content}}
`
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
-- content/p2/pixel.png --
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|{{ .Content }}|$
`
Image: 
{class="><script>alert()</script>" id="baz"}
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
`
First line.
Second line.
----------------
--- layouts/_default/_markup/render-heading.html --
+-- layouts/_markup/render-heading.html --
Plain text: {{ .PlainText }}|Text: {{ .Text }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
Content: {{ .Content}}|
}
`
func TestContentOutputReuseRenderHooksAndShortcodesHTMLOnly(t *testing.T) {
files := `
-- hugo.toml --
--- layouts/index.html --
+-- layouts/home.html --
HTML: {{ .Title }}|{{ .Content }}|
-- layouts/index.xml --
XML: {{ .Title }}|{{ .Content }}|
-- layouts/_markup/render-heading.html --
Render heading.
--- layouts/shortcodes/myshortcode.html --
+-- layouts/_shortcodes/myshortcode.html --
My shortcode.
-- content/_index.md --
---
files := `
-- hugo.toml --
disableKinds = ["taxonomy", "term"]
--- layouts/index.html --
+-- layouts/home.html --
HTML: {{ .Title }}|{{ .Content }}|
-- layouts/index.xml --
XML: {{ .Title }}|{{ .Content }}|
files := `
-- hugo.toml --
disableKinds = ["taxonomy", "term"]
--- layouts/index.html --
+-- layouts/home.html --
HTML: {{ .Title }}|{{ .Content }}|
-- layouts/index.xml --
XML: {{ .Title }}|{{ .Content }}|
-- layouts/_markup/render-heading.html --
Render heading.
--- layouts/shortcodes/myshortcode.html --
+-- layouts/_shortcodes/myshortcode.html --
My shortcode HTML.
--- layouts/shortcodes/myshortcode.xml --
+-- layouts/_shortcodes/myshortcode.xml --
My shortcode XML.
-- content/_index.md --
---
v1 = "a_v1_theme"
-- themes/mytheme/data/d.toml --
v1 = "d_v1_theme"
--- layouts/index.html --
+-- layouts/home.html --
a: {{ site.Data.a.v1 }}|
b: {{ site.Data.b.v1 }}|
cd: {{ site.Data.c.d.v1 }}|
baseURL = "https://example.com"
-- data/MyFolder/MyData.toml --
v1 = "my_v1"
--- layouts/index.html --
+-- layouts/home.html --
{{ site.Data }}
v1: {{ site.Data.MyFolder.MyData.v1 }}|
`
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
-- assets/data/foo.toml --
content = "I am assets/data/foo.toml"
--- layouts/index.html --
+-- layouts/home.html --
|{{ site.Data.foo.content }}|
`
title: Page
date: 2021-07-18
---
--- layouts/index.html --
+-- layouts/home.html --
Date: {{ .Date | time.Format ":date_long" }}
`
[languages.nn]
timeZone="America/Antigua"
weight=20
--- layouts/_default/single.html --
+-- layouts/single.html --
Date: {{ .Date | safeHTML }}
Lastmod: {{ .Lastmod | safeHTML }}
PublishDate: {{ .PublishDate | safeHTML }}
files := `
-- hugo.toml --
--- layouts/index.html --
+-- layouts/home.html --
time: {{ time "2020-10-20" "invalid-timezone" }}
-- content/p1.md --
`
{ date = 2050-02-12, name = "Future talk 1" },
{ date = 2050-02-13, name = "Future talk 2" },
]
--- layouts/index.html --
+-- layouts/home.html --
{{ $futureTalks := where site.Data.mydata.talks "date" ">" now }}
{{ $pastTalks := where site.Data.mydata.talks "date" "<" now }}
disableKinds = ['home','rss','sitemap']
[taxonomies]
tag = 'tags'
--- layouts/_default/list.html --
+-- layouts/list.html --
Date: {{ .Date.Format "2006-01-02" }}
PublishDate: {{ .PublishDate.Format "2006-01-02" }}
Lastmod: {{ .Lastmod.Format "2006-01-02" }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
-- content/s1/p1.md --
---
enableRobotsTXT = true
ignoreErrors = ["error-disable-taxonomy"]
disableKinds = ["%s"]
--- layouts/_default/single.html --
+-- layouts/single.html --
single
-- content/sect/page.md --
---
disableKinds = ["term", "taxonomy", "RSS"]
[outputs]
home = [ "HTML", "RSS" ]
--- layouts/index.html --
+-- layouts/home.html --
Home
`
b := Test(t, files)
files := `
-- hugo.toml --
baseURL = "http://example.com"
--- layouts/index.html --
+-- layouts/home.html --
{{ $bundle := site.GetPage "section/bundle-false" }}
{{ $data1 := $bundle.Resources.GetMatch "data1*" }}
Data1: {{ $data1.RelPermalink }}
files := `
-- hugo.toml --
baseURL = "http://example.com"
--- layouts/index.html --
+-- layouts/home.html --
{{ $page := site.GetPage "sect/no-render" }}
{{ $sect := site.GetPage "sect-no-render" }}
---
title: "Page 2 nn"
---
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
`
b := Test(t, files)
---
title: My Site
---
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ template "_internal/twitter_cards.html" . }}
{{ template "_internal/opengraph.html" . }}
---
title: p10
---
--- layouts/index.html --
+-- layouts/home.html --
{{ .Paginate (where site.RegularPages "Section" "s1") }}` + variant + `
`
b := Test(t, files)
[[module.mounts]]
source = "docs"
target = "content/mydocs"
--- layouts/index.html --
+-- layouts/home.html --
Home.
`
body { color: red; }
-- assets/scss/app.scss --
body { color: blue; }
--- layouts/index.html --
+-- layouts/home.html --
Home.
SCSS: {{ with resources.Get "scss/app.scss" }}{{ .RelPermalink }}|{{ .Content }}{{ end }}|
# Note that the pattern below will match 2 resources, which doesn't make much sense,
mixed: ["1", 2, 3]
strings: ["1", "2","3"]
---
--- layouts/_default/single.html --
+-- layouts/single.html --
Ints: {{ printf "%T" .Params.ints }} {{ range .Params.ints }}Int: {{ fmt.Printf "%[1]v (%[1]T)" . }}|{{ end }}
Mixed: {{ printf "%T" .Params.mixed }} {{ range .Params.mixed }}Mixed: {{ fmt.Printf "%[1]v (%[1]T)" . }}|{{ end }}
Strings: {{ printf "%T" .Params.strings }} {{ range .Params.strings }}Strings: {{ fmt.Printf "%[1]v (%[1]T)" . }}|{{ end }}
weight = 4
title = "French Title"
--- layouts/index.html --
+-- layouts/home.html --
{{ range .Site.RegularPages }}
|{{ .Title }}|{{ .RelPermalink }}|{{ .Plain }}
{{ end }}
-- themes/a/config.toml --
[params]
a = "Should Be Ignored!"
--- layouts/index.html --
+-- layouts/home.html --
Params: {{ .Site.Params }}
`
Test(t, files).AssertFileContent("public/index.html", "! Ignored")
-- themes/b/config.toml --
[params]
b = "B param"
--- layouts/index.html --
+-- layouts/home.html --
Params: {{ .Site.Params }}
`
Test(t, files).AssertFileContent("public/index.html", "A param", "! B param")
[[module.mounts]]
source="mycontent"
target="content"
--- layouts/_default/single.html --
+-- layouts/single.html --
Permalink: {{ .Permalink }}|
-- mycontent/mypage.md --
---
target = "content/_index.md"
-- README.md --
# Hello World
--- layouts/index.html --
+-- layouts/home.html --
Home: {{ .Title }}|{{ .Content }}|
`
b := Test(t, files)
[[module.mounts]]
source = "extra-content"
target = "content/resources-b"
--- layouts/_default/single.html --
+-- layouts/single.html --
Single
-- content/p1.md --
-- extra-content/_index.md --
target = "data/extra"
-- extra-data/test.yaml --
message: Hugo Rocks
--- layouts/index.html --
+-- layouts/home.html --
{{ site.Data.extra.test.message }}
`
return `
-- hugo.toml --
baseURL = "https://example.com"
--- layouts/shortcodes/sc.html --
+-- layouts/_shortcodes/sc.html --
` + f(shortcode, `SHORTCODE L1
SHORTCODE L2
SHORTCODE L3:
SHORTCODE L4: {{ .Page.Title }}
`) + `
--- layouts/_default/baseof.html --
+-- layouts/baseof.html --
` + f(base, `BASEOF L1
BASEOF L2
BASEOF L3
{{block "main" .}}This is the main content.{{end}}
BASEOF L6
`) + `
--- layouts/_default/single.html --
+-- layouts/single.html --
` + f(single, `{{ define "main" }}
SINGLE L2:
SINGLE L3:
fe := a.getFileError(err)
a.c.Assert(fe.Position().LineNumber, qt.Equals, 5)
a.c.Assert(fe.Position().ColumnNumber, qt.Equals, 14)
- a.assertErrorMessage("\"layouts/_default/single.html:5:14\": execute of template failed", fe.Error())
+ a.assertErrorMessage("\"layouts/single.html:5:14\": execute of template failed", fe.Error())
},
},
{
fe := a.getFileError(err)
a.c.Assert(fe.Position().LineNumber, qt.Equals, 5)
a.c.Assert(fe.Position().ColumnNumber, qt.Equals, 14)
- a.assertErrorMessage("\"layouts/_default/single.html:5:14\": execute of template failed", fe.Error())
+ a.assertErrorMessage("\"layouts/single.html:5:14\": execute of template failed", fe.Error())
},
},
{
assertErr: func(a testSiteBuildErrorAsserter, err error) {
fe := a.getFileError(err)
// Make sure that it contains both the content file and template
- a.assertErrorMessage(`"content/myyaml.md:7:10": failed to render shortcode "sc": failed to process shortcode: "layouts/shortcodes/sc.html:4:22": execute of template failed: template: shortcodes/sc.html:4:22: executing "shortcodes/sc.html" at <.Page.Titles>: can't evaluate field Titles in type page.Page`, fe.Error())
+ a.assertErrorMessage(`"content/myyaml.md:7:10": failed to render shortcode "sc": failed to process shortcode: "layouts/_shortcodes/sc.html:4:22": execute of template failed: template: shortcodes/sc.html:4:22: executing "shortcodes/sc.html" at <.Page.Titles>: can't evaluate field Titles in type page.Page`, fe.Error())
a.c.Assert(fe.Position().LineNumber, qt.Equals, 7)
},
},
[minify]
minifyOutput = true
--- layouts/index.html --
+-- layouts/home.html --
<body>
<script>=;</script>
</body>
---
title: "Home"
---
--- layouts/index.html --
+-- layouts/home.html --
line 1
line 2
1{{ .Render "myview" }}
--- layouts/_default/myview.html --
+-- layouts/myview.html --
line 1
12{{ partial "foo.html" . }}
line 4
line 5
--- layouts/partials/foo.html --
+-- layouts/_partials/foo.html --
line 1
line 2
123{{ .ThisDoesNotExist }}
b.Assert(errors, qt.HasLen, 4)
b.Assert(errors[0].Position().LineNumber, qt.Equals, 3)
b.Assert(errors[0].Position().ColumnNumber, qt.Equals, 4)
- b.Assert(errors[0].Error(), qt.Contains, filepath.FromSlash(`"/layouts/index.html:3:4": execute of template failed`))
+ b.Assert(errors[0].Error(), qt.Contains, filepath.FromSlash(`"/layouts/home.html:3:4": execute of template failed`))
b.Assert(errors[0].ErrorContext().Lines, qt.DeepEquals, []string{"line 1", "line 2", "1{{ .Render \"myview\" }}"})
b.Assert(errors[2].Position().LineNumber, qt.Equals, 2)
b.Assert(errors[2].Position().ColumnNumber, qt.Equals, 5)
## Hello
{{< hello >}}
--- layouts/index.html --
+-- layouts/home.html --
line 1
line 2
{{ .Content }}
line 5
--- layouts/shortcodes/hello.html --
+-- layouts/_shortcodes/hello.html --
line 1
12{{ partial "foo.html" . }}
line 4
line 5
--- layouts/partials/foo.html --
+-- layouts/_partials/foo.html --
line 1
line 2
123{{ .ThisDoesNotExist }}
b.Assert(errors[1].Position().LineNumber, qt.Equals, 6)
b.Assert(errors[1].Position().ColumnNumber, qt.Equals, 1)
b.Assert(errors[1].ErrorContext().ChromaLexer, qt.Equals, "md")
- b.Assert(errors[1].Error(), qt.Contains, filepath.FromSlash(`"/content/_index.md:6:1": failed to render shortcode "hello": failed to process shortcode: "/layouts/shortcodes/hello.html:2:5":`))
+ b.Assert(errors[1].Error(), qt.Contains, filepath.FromSlash(`"/content/_index.md:6:1": failed to render shortcode "hello": failed to process shortcode: "/layouts/_shortcodes/hello.html:2:5":`))
b.Assert(errors[1].ErrorContext().Lines, qt.DeepEquals, []string{"", "## Hello", "{{< hello >}}", ""})
b.Assert(errors[2].ErrorContext().Lines, qt.DeepEquals, []string{"line 1", "12{{ partial \"foo.html\" . }}", "line 4", "line 5"})
b.Assert(errors[3].Position().LineNumber, qt.Equals, 3)
## Hello
--- layouts/index.html --
+-- layouts/home.html --
line 1
line 2
{{ .Content }}
line 5
--- layouts/_default/_markup/render-heading.html --
+-- layouts/_markup/render-heading.html --
line 1
12{{ .Levels }}
line 4
errors := herrors.UnwrapFileErrorsWithErrorContext(err)
b.Assert(errors, qt.HasLen, 3)
- b.Assert(errors[0].Error(), qt.Contains, filepath.FromSlash(`"/content/_index.md:2:5": "/layouts/_default/_markup/render-heading.html:2:5": execute of template failed`))
+ b.Assert(errors[0].Error(), qt.Contains, filepath.FromSlash(`"/content/_index.md:2:5": "/layouts/_markup/render-heading.html:2:5": execute of template failed`))
}
func TestErrorRenderHookCodeblock(t *testing.T) {
§§§
--- layouts/index.html --
+-- layouts/home.html --
line 1
line 2
{{ .Content }}
line 5
--- layouts/_default/_markup/render-codeblock-foo.html --
+-- layouts/_markup/render-codeblock-foo.html --
line 1
12{{ .Foo }}
line 4
b.Assert(errors, qt.HasLen, 3)
first := errors[0]
- b.Assert(first.Error(), qt.Contains, filepath.FromSlash(`"/content/_index.md:7:1": "/layouts/_default/_markup/render-codeblock-foo.html:2:5": execute of template failed`))
+ b.Assert(first.Error(), qt.Contains, filepath.FromSlash(`"/content/_index.md:7:1": "/layouts/_markup/render-codeblock-foo.html:2:5": execute of template failed`))
}
func TestErrorInBaseTemplate(t *testing.T) {
{{ block "main" . }}empty{{ end }}
line 4 base
{{ block "toc" . }}empty{{ end }}
--- layouts/index.html --
+-- layouts/home.html --
{{ define "main" }}
line 2 index
line 3 index
{{ define "toc" }}
TOC: {{ partial "toc.html" . }}
{{ end }}
--- layouts/partials/toc.html --
+-- layouts/_partials/toc.html --
toc line 1
toc line 2
toc line 3
b.Assert(err.Error(), qt.Contains, `baseof.html:4:6`)
})
- t.Run("index template", func(t *testing.T) {
+ t.Run("home template", func(t *testing.T) {
files := strings.Replace(filesTemplate, "line 3 index", "1234{{ .ThisDoesNotExist \"abc\" }}", 1)
b, err := TestE(t, files)
b.Assert(err, qt.IsNotNil)
- b.Assert(err.Error(), qt.Contains, `index.html:3:7"`)
+ b.Assert(err.Error(), qt.Contains, `home.html:3:7"`)
})
t.Run("partial from define", func(t *testing.T) {
filesBuilder.WriteString(`
-- hugo.toml --
timeout = 5
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .WordCount }}
--- layouts/shortcodes/c.html --
+-- layouts/_shortcodes/c.html --
{{ range .Page.Site.RegularPages }}
{{ .WordCount }}
{{ end }}
files := `
-- hugo.toml --
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ .ThisDoesNotExist }}
`
b, err := TestE(t, files)
b.Assert(err, qt.Not(qt.IsNil))
- b.Assert(err.Error(), qt.Contains, filepath.FromSlash(`/layouts/index.html:2:3`))
+ b.Assert(err.Error(), qt.Contains, filepath.FromSlash(`/layouts/home.html:2:3`))
b.Assert(err.Error(), qt.Contains, `can't evaluate field ThisDoesNotExist`)
}
title: doc1 fr
slug: doc1-fr
---
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: {{ .Title }}|{{ .Lang }}|{{ .RelPermalink }}|
`
My Bundle
-- content/mysect/mybundle/foo.txt --
Foo
--- layouts/_default/list.html --
+-- layouts/list.html --
List|{{ .Title }}|{{ .Lang }}|{{ .Permalink}}|{{ .RelPermalink }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
Single|{{ .Title }}|{{ .Lang }}|{{ .Permalink}}|{{ .RelPermalink }}|
{{ $foo := .Resources.Get "foo.txt" | fingerprint }}
Foo: {{ $foo.Permalink }}|
.body {
color: french;
}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ $data := .Resources.GetMatch "styles*" | minify }}
{{ .Lang }}: {{ $data.Content}}|{{ $data.RelPermalink }}|
---
title: mybundle-en
---
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ with .Resources.Get "pixel.png" }}
{{ with .Resize "2x2" }}
{{ .RelPermalink }}|
File 1 en.
-- content/en/section/mybundle/file2.txt --
File 2 en.
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ $files := .Resources.Match "file*" }}
Files: {{ range $files }}{{ .Permalink }}|{{ end }}$
weight = 2
-- assets/css/main.css --
body { color: red; }
--- layouts/index.html --
+-- layouts/home.html --
{{ $css := resources.Get "css/main.css" | minify }}
CSS: {{ $css.Permalink }}|{{ $css.RelPermalink }}|
`
weight = 2
[languages.de]
weight = 3
--- layouts/index.html --
+-- layouts/home.html --
{{ $bundle := site.GetPage "bundle" }}
Bundle all translations: {{ range $bundle.AllTranslations }}{{ .Lang }}|{{ end }}$
Bundle translations: {{ range $bundle.Translations }}{{ .Lang }}|{{ end }}$
---
title: Page
---
--- layouts/index.html --
+-- layouts/home.html --
Home: {{ .Title }}
`
mytext.txt: {{ with .Resources.GetMatch "**.txt" }}{{ .Content }}|{{ .RelPermalink }}{{ end }}|
mypage.md: {{ with .Resources.GetMatch "**.md" }}{{ .Content }}|{{ .RelPermalink }}{{ end }}|
RenderString with shortcode: {{ .RenderString "{{< myshortcode >}}" }}|
--- layouts/shortcodes/myshortcode.html --
+-- layouts/_shortcodes/myshortcode.html --
myshortcode.html
--- layouts/shortcodes/myshortcode.en.html --
+-- layouts/_shortcodes/myshortcode.en.html --
myshortcode.en.html
`
---
Page.
--- layouts/_default/list.html --
+-- layouts/list.html --
List: {{ .Title }}|{{ .RelPermalink}}|{{ range .OutputFormats }}{{ .Name }}: {{ .RelPermalink }}|{{ end }}$
--- layouts/_default/list.xml --
+-- layouts/list.xml --
List xml: {{ .Title }}|{{ .RelPermalink}}|{{ range .OutputFormats }}{{ .Name }}: {{ .RelPermalink }}|{{ end }}$
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: {{ .Title }}|{{ .RelPermalink}}|{{ range .OutputFormats }}{{ .Name }}: {{ .RelPermalink }}|{{ end }}$
`
[outputs]
home = ["html", "json", "rss"]
--- layouts/index.html --
+-- layouts/home.html --
Home: {{ .Lang}}|{{ .Kind }}|{{ .RelPermalink }}|{{ .Title }}|{{ .Content }}|Len Resources: {{ len .Resources }}|HTML
Resources: {{ range .Resources }}{{ .ResourceType }}|{{ .RelPermalink }}|{{ .MediaType }} - {{ end }}|
Site last mod: {{ site.Lastmod.Format "2006-02-01" }}|
Paginate: {{ .Paginator.PageNumber }}/{{ .Paginator.TotalPages }}|
-- layouts/index.json --
Home:{{ .Lang}}|{{ .Kind }}|{{ .RelPermalink }}|{{ .Title }}|{{ .Content }}|Len Resources: {{ len .Resources }}|JSON
--- layouts/_default/list.html --
+-- layouts/list.html --
List: {{ .Lang}}|{{ .Kind }}|{{ .RelPermalink }}|{{ .Title }}|{{ .Content }}|Len Resources: {{ len .Resources }}|
Resources: {{ range .Resources }}{{ .ResourceType }}|{{ .RelPermalink }}|{{ .MediaType }} - {{ end }}
Pages Length: {{ len .Pages }}
Kind: {{ .Kind }}
Type: {{ .Type }}
Paginate: {{ .Paginator.PageNumber }}/{{ .Paginator.TotalPages }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: {{ .Lang}}|{{ .Kind }}|{{ .RelPermalink }}|{{ .Title }}|{{ .Content }}|Len Resources: {{ len .Resources }}|Background: {{ .Params.background }}|
Resources: {{ range .Resources }}{{ .ResourceType }}|{{ .RelPermalink }}|{{ .MediaType }}|{{ .Params }} - {{ end }}
{{ $textResource := .Resources.GetMatch "**.txt" }}
NextInSection: {{ with .NextInSection }}{{ .RelPermalink }}|{{ .Title }}{{ end }}|
PrevInSection: {{ with .PrevInSection }}{{ .RelPermalink }}|{{ .Title }}{{ end }}|
GetTerms: {{ range .GetTerms "tags" }}name: {{ .Name }}, title: {{ .Title }}|{{ end }}
--- layouts/shortcodes/hello.html --
+-- layouts/_shortcodes/hello.html --
Hello.
-- content/_index.md --
---
lang = "nn"
[[module.imports]]
path = "mytheme"
--- layouts/index.html --
+-- layouts/home.html --
i18n s1: {{ i18n "s1" }}|
i18n s2: {{ i18n "s2" }}|
data s1: {{ site.Data.d1.s1 }}|
isPlainText = true
isHTML = false
--- layouts/_default/single.html --
+-- layouts/single.html --
HTML Single: {{ .Data.Pages }}
--- layouts/_default/list.html --
+-- layouts/list.html --
HTML List: {{ .Data.Pages }}
-- content/_index.md --
---
[languages.sv]
title = "Svenska"
weight = 4
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Title }}
{{ .Content }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
{{ .Content }}
--- layouts/shortcodes/myshort.html --
+-- layouts/_shortcodes/myshort.html --
{{ .Inner }}
`
title: P1
tags: ['T1']
---
--- layouts/_default/single.html --
+-- layouts/single.html --
<ul>{{ range .AllTranslations }}<li>{{ .Title }}-{{ .Lang }}</li>{{ end }}</ul>
--- layouts/_default/list.html --
+-- layouts/list.html --
<ul>{{ range .AllTranslations }}<li>{{ .Title }}-{{ .Lang }}</li>{{ end }}</ul>
`
t.Parallel()
files := `
--- layouts/index.html --
+-- layouts/home.html --
{{ $opts := dict "markup" "foo" }}
{{ "something" | .RenderString $opts }}
`
---
title: Films
---
--- layouts/index.html --
+-- layouts/home.html --
{{ (site.GetPage "/tags").Title }}
{{ (site.GetPage "/tags/fiction").Title }}
{{ (site.GetPage "/books").Title }}
file 2 en
-- content/nn/myfiles/file1.txt --
file 1 nn
--- layouts/index.html --
+-- layouts/home.html --
Title: {{ .Title }}|
Len Resources: {{ len .Resources }}|
{{ range $i, $e := .Resources }}
weight = 1
-- i18n/%s.toml --
hello.one = "Hello"
--- layouts/index.html --
+-- layouts/home.html --
Hello: {{ i18n "hello" 1 }}
-- content/p1.md --
`, tc.langCode, tc.langCode, tc.langCode)
weight=10
[languages.nn]
weight=20
--- layouts/index.html --
+-- layouts/home.html --
FormatNumber: {{ 512.5032 | lang.FormatNumber 2 }}
FormatPercent: {{ 512.5032 | lang.FormatPercent 2 }}
baseurl = "http://example.com/"
title = "Section Menu"
sectionPagesMenu = "sect"
--- layouts/partials/menu.html --
+-- layouts/_partials/menu.html --
{{- $p := .page -}}
{{- $m := .menu -}}
{{ range (index $p.Site.Menus $m) -}}
{{- if $p.IsMenuCurrent $m . }}IsMenuCurrent{{ else }}-{{ end -}}|
{{- if $p.HasMenuCurrent $m . }}HasMenuCurrent{{ else }}-{{ end -}}|
{{- end -}}
--- layouts/_default/single.html --
+-- layouts/single.html --
Single|{{ .Title }}
Menu Sect: {{ partial "menu.html" (dict "page" . "menu" "sect") }}
Menu Main: {{ partial "menu.html" (dict "page" . "menu" "main") }}
--- layouts/_default/list.html --
+-- layouts/list.html --
List|{{ .Title }}|{{ .Content }}
-- content/sect1/p1.md --
---
files := `
-- hugo.toml --
baseURL = "http://example.com/"
--- layouts/index.html --
+-- layouts/home.html --
Main: {{ len .Site.Menus.main }}
Other: {{ len .Site.Menus.other }}
{{ range .Site.Menus.main }}
mediaType = "text/html"
path = "damp"
--- layouts/index.html --
+-- layouts/home.html --
{{ range .Site.Menus.main }}{{ .Title }}|{{ .URL }}|{{ end }}
-- content/_index.md --
---
files := `
-- hugo.toml --
baseURL = "http://example.com/"
--- layouts/index.html --
+-- layouts/home.html --
{{ range .Site.Menus.main }}{{ .Title }}|Children:
{{- $children := sort .Children ".Page.Date" "desc" }}{{ range $children }}{{ .Title }}|{{ end }}{{ end }}
foo = "foo_config"
key2 = "key2_config"
camelCase = "camelCase_config"
--- layouts/index.html --
+-- layouts/home.html --
Main: {{ len .Site.Menus.main }}
{{ range .Site.Menus.main }}
foo: {{ .Params.foo }}
title = "My Post 3"
url = "/blog/post3"
--- layouts/index.html --
+-- layouts/home.html --
Main: {{ len .Site.Menus.main }}
{{ range .Site.Menus.main }}
{{ .Title }}|HasMenuCurrent: {{ $.HasMenuCurrent "main" . }}|Page: {{ .Page.Path }}
{{ .Title }}|IsMenuCurrent: {{ $.IsMenuCurrent "main" . }}|Page: {{ .Page.Path }}
{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
Main: {{ len .Site.Menus.main }}
{{ range .Site.Menus.main }}
{{ .Title }}|HasMenuCurrent: {{ $.HasMenuCurrent "main" . }}|Page: {{ .Page.Path }}
---
title: "Test 1"
---
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ range site.Menus.main }}
{{ .Name }}|{{ .URL }}|IsMenuCurrent = {{ $.IsMenuCurrent "main" . }}|HasMenuCurrent = {{ $.HasMenuCurrent "main" . }}|
{{ range .Children }}
pre = "<span>"
post = "</span>"
weight = 1
--- layouts/index.html --
+-- layouts/home.html --
{{ range $i, $e := site.Menus.main }}
Menu Item: {{ $i }}: {{ .Pre }}{{ .Name }}{{ .Post }}|{{ .URL }}|
{{ end }}
name = "Posts"
url = "/posts"
weight = 1
--- layouts/index.html --
+-- layouts/home.html --
{{ range $i, $e := site.Menus.main }}
Menu Item: {{ $i }}|{{ .URL }}|
{{ end }}
sectionPagesMenu = "main"
[languages.en]
[languages.fr]
--- layouts/_default/home.html --
+-- layouts/home.html --
{{- range site.Menus.main -}}
<a href="{{ .URL }}">{{ .Name }}</a>
{{- end -}}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
-- content/p1.en.md --
---
---
title: p3
---
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ range site.Menus.main }}<a href="{{ .URL }}">{{ .Name }}</a>{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
`
title: S3_Title
linkTitle: S3_LinkTitle
---
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Content }}
--- layouts/_default/home.html --
+-- layouts/home.html --
{{- range site.Menus.main }}
URL: {{ .URL }}| Name: {{ .Name }}| Title: {{ .Title }}| PageRef: {{ .PageRef }}| Page.Title: {{ .Page.Title }}| Page.LinkTitle: {{ .Page.LinkTitle }}|
{{- end }}
baseURL = "https://example.org/"
[minify]
minifyOutput = true
--- layouts/index.html --
+-- layouts/home.html --
<!DOCTYPE html>
<html lang="en">
<head>
[[module.mounts]]
source = 'archetypes'
target = 'archetypes'
--- layouts/_default/single.html --
+-- layouts/single.html --
Single page.
-- content/a/b/p1.md --
---
b1='bval'
-- data/nodata/c.toml --
c1='bval'
--- layouts/partials/foo.html --
+-- layouts/_partials/foo.html --
foo
-- assets/exclude.txt --
foo
foo
-- assets/js/include.js --
foo
--- layouts/index.html --
+-- layouts/home.html --
Data: {{ site.Data }}:END
Template: {{ templates.Exists "partials/foo.html" }}:END
---
## Heading 1 FR
--- layouts/_default/single.html --
+-- layouts/single.html --
HTML
--- layouts/_default/single.json --
+-- layouts/single.json --
{{ $secondSite := index .Sites 1 }}
{{ $p1 := $secondSite.GetPage "p1" }}
ToC: {{ $p1.TableOfContents }}
### Heading P2 1
### Heading P2 2
--- layouts/shortcodes/include.html --
+-- layouts/_shortcodes/include.html --
{{ with site.GetPage (.Get 0) }}{{ .RawContent }}{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
Fragments: {{ .Fragments.Identifiers }}|
title: page-1
tags: 'tag-a'
---
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Title }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
`
title: "p2"
draft: true
---
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
`
b := Test(t, files)
[Languages.nn]
weight = 20
contentDir = "content/nn"
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: {{ .Title }}|Hello|{{ .Lang }}|RelPermalink: {{ .RelPermalink }}|Permalink: {{ .Permalink }}|
--- layouts/_default/list.html --
+-- layouts/list.html --
List Page 1|{{ .Title }}|Hello|{{ .Permalink }}|
-- content/en/blog/page1.md --
---
categories: ["c", "e"]
---
p2
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Title }}|Date: {{ .Date.Format "2006-01-02" }}|Lastmod: {{ .Lastmod.Format "2006-01-02" }}|
`
---
title: "empty"
---
--- layouts/_default/single.html --
+-- layouts/single.html --
|{{ .RawContent }}|
`
summary: "Front **matter** summary"
---
Simple Page
--- layouts/_default/single.html --
+-- layouts/single.html --
Summary: {{ .Summary }}|Truncated: {{ .Truncated }}|
`).AssertFileContent("public/simple/index.html", "Summary: Front <strong>matter</strong> summary|", "Truncated: false")
This is **summary**.
<!--more-->
This is **content**.
--- layouts/_default/single.html --
+-- layouts/single.html --
Summary: {{ .Summary }}|Truncated: {{ .Truncated }}|
Content: {{ .Content }}|
<div>
This is <b>content</b>.
</div>
--- layouts/_default/single.html --
+-- layouts/single.html --
Summary: {{ .Summary }}|Truncated: {{ .Truncated }}|
Content: {{ .Content }}|
This is **more summary**.
This is **content**.
--- layouts/_default/single.html --
+-- layouts/single.html --
Summary: {{ .Summary }}|Truncated: {{ .Truncated }}|
Content: {{ .Content }}|
[outputs]
home = ["HTML", "JSON"]
--- layouts/index.html --
+-- layouts/home.html --
{{- range .Site.Home.Translations -}}
<p>{{- .RenderString "foo" -}}</p>
{{- end -}}
{{- range .Site.Home.AllTranslations -}}
<p>{{- .RenderString "bar" -}}</p>
{{- end -}}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
-- layouts/index.json --
{"Title": "My Site"}
<li>Len: {{ .Len }}</li>
{{ end }}
</ul>
--- layouts/_default/baseof.html --
+-- layouts/baseof.html --
<html>
<body>
</body>
</html>
--- layouts/_default/home.html --
+-- layouts/home.html --
{{ define "main" }}
<h2>Translations</h2>
<ul>
translationkey: "adfasdf"
title: "p1 nn"
---
--- layouts/_default/single.html --
+-- layouts/single.html --
Title: {{ .Title }}|TranslationKey: {{ .TranslationKey }}|
Translations: {{ range .Translations }}{{ .Language.Lang }}|{{ end }}|
AllTranslations: {{ range .AllTranslations }}{{ .Language.Lang }}|{{ end }}|
weight = 2
[taxonomies]
category = 'categories'
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .IsTranslated }}|{{ range .Translations }}{{ .RelPermalink }}|{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|
-- content/p1.en.md --
---
---
-- content/sect/mybundle_nn/f2.nn.txt --
f2.nn
--- layouts/_default/single.html --
+-- layouts/single.html --
Title: {{ .Title }}|TranslationKey: {{ .TranslationKey }}|
Resources: {{ range .Resources }}{{ .RelPermalink }}|{{ .Content }}|{{ end }}|
# more
Content.
--- layouts/shortcodes/sc.html --
+-- layouts/_shortcodes/sc.html --
a shortcode
--- layouts/_default/single.html --
+-- layouts/single.html --
SUMMARY:{{ .Summary }}:END
--------------------------
CONTENT:{{ .Content }}
-- hugo.toml --
baseURL = "http://example.com/"
title = "Site Title"
--- layouts/index.html --
+-- layouts/home.html --
Title|{{ with .Title }}{{ . }}{{ end }}|
-- content/_index.md --
---
slug: "PaGe4"
---
p4.
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: {{ .Title}}|{{ .RelPermalink }}|{{ .Path }}|
`
b := Test(t, files)
files := `
-- hugo.toml --
baseURL = "http://example.com/"
--- layouts/index.html --
+-- layouts/home.html --
{{ .Scratch.Set "b" "bv" }}
B: {{ .Scratch.Get "b" }}
--- layouts/shortcodes/scratch.html --
+-- layouts/_shortcodes/scratch.html --
{{ .Scratch.Set "c" "cv" }}
C: {{ .Scratch.Get "c" }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
-- content/scratchme.md --
---
-- hugo.toml --
disableKinds = ["taxonomy", "term", "page", "section"]
disableLiveReload = true
--- layouts/index.html --
+-- layouts/home.html --
{{ .Scratch.Set "a" "b" }}
{{ .Store.Set "c" "d" }}
.Scratch eq .Store: {{ eq .Scratch .Store }}
[params]
[params.author]
name = "Kurt Vonnegut"
--- layouts/index.html --
+-- layouts/home.html --
{{ $withParam := .Site.GetPage "withparam" }}
{{ $noParam := .Site.GetPage "noparam" }}
unsafe = false
[markup.highlight]
noClasses=false
--- layouts/_default/single.html --
+-- layouts/single.html --
Title: {{ .Title }}
ToC: {{ .TableOfContents }}
Content: {{ .Content }}
--- layouts/shortcodes/t.html --
+-- layouts/_shortcodes/t.html --
T-SHORT
--- layouts/shortcodes/s.html --
+-- layouts/_shortcodes/s.html --
## Code
{{ .Inner }}
-- content/page.md --
files := `
-- hugo.toml --
--- layouts/index.html --
+-- layouts/home.html --
{{ .Render }}
`
title: "Home"
---
{{< s >}}
--- layouts/shortcodes/s.html --
+-- layouts/_shortcodes/s.html --
{{ if not (.Store.Get "Shortcode") }}{{ .Store.Set "Shortcode" (printf "sh-%s" $.Page.Title) }}{{ end }}
Shortcode: {{ .Store.Get "Shortcode" }}|
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
{{ if not (.Store.Get "Page") }}{{ .Store.Set "Page" (printf "p-%s" $.Title) }}{{ end }}
{{ if not (hugo.Store.Get "Hugo") }}{{ hugo.Store.Set "Hugo" (printf "h-%s" $.Title) }}{{ end }}
---
title: "Root"
---
--- layouts/_default/single.html --
+-- layouts/single.html --
Basic: {{ .Title }}|{{ .Kind }}|{{ .BundleType }}|{{ .RelPermalink }}|
Tree: Section: {{ .Section }}|CurrentSection: {{ .CurrentSection.RelPermalink }}|Parent: {{ .Parent.RelPermalink }}|FirstSection: {{ .FirstSection.RelPermalink }}
`
{{< myShort >}}
--- layouts/_default/single.html --
+-- layouts/single.html --
Bundled page: {{ .RelPermalink}}|{{ with .Resources.Get "p1.md" }}Title: {{ .Title }}|Content: {{ .Content }}{{ end }}|
--- layouts/shortcodes/myShort.html --
+-- layouts/_shortcodes/myShort.html --
MyShort.
`
{{< hello >}}
--- layouts/shortcodes/hello.html --
+-- layouts/_shortcodes/hello.html --
Hello HTML.
--- layouts/_default/single.html --
+-- layouts/single.html --
Basic: {{ .Title }}|{{ .Kind }}|{{ .BundleType }}|{{ .RelPermalink }}|
Resources: {{ range .Resources }}RelPermalink: {{ .RelPermalink }}|Content: {{ .Content }}|{{ end }}|
--- layouts/shortcodes/hello.cpath --
+-- layouts/_shortcodes/hello.cpath --
Hello CPATH.
--- layouts/_default/single.cpath --
+-- layouts/single.cpath --
Basic: {{ .Title }}|{{ .Kind }}|{{ .BundleType }}|{{ .RelPermalink }}|
Resources: {{ range .Resources }}RelPermalink: {{ .RelPermalink }}|Content: {{ .Content }}|{{ end }}|
`
F2
-- content/mybundle/f2.nn.txt --
F2 nn.
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|{{ .RelPermalink }}|{{ .Lang }}|
Resources: {{ range .Resources }}RelPermalink: {{ .RelPermalink }}|Content: {{ .Content }}|{{ end }}|
title: "P1nn"
---
P1nn
--- layouts/index.html --
+-- layouts/home.html --
Len RegularPages: {{ len .Site.RegularPages }}|RegularPages: {{ range site.RegularPages }}{{ .RelPermalink }}: {{ .Title }}|{{ end }}|
Len Pages: {{ len .Site.Pages }}|
Len Sites: {{ len .Site.Sites }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|{{ .Content }}|{{ .Lang }}|
`
title: "P1nn"
---
P1nn
--- layouts/index.html --
+-- layouts/home.html --
Len RegularPages: {{ len .Site.RegularPages }}|RegularPages: {{ range site.RegularPages }}{{ .RelPermalink }}: {{ .Title }}|{{ end }}|
Len Pages: {{ len .Site.Pages }}|
Len Sites: {{ len .Site.Sites }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|{{ .Content }}|{{ .Lang }}|
`
title: My Headless Bundle2
headless: true
---
--- layouts/index.html --
+-- layouts/home.html --
{{ $headless1 := .Site.GetPage "headless/h1" }}
{{ $headless2 := .Site.GetPage "headless/h2" }}
---
Single content.
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|{{ .Content }}
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Title }}|{{ .Content }}
`
b := Test(t, files)
F2 en.
-- content/mybundle/f2.nn.txt --
F2 nn.
--- layouts/shortcodes/getresource.html --
+-- layouts/_shortcodes/getresource.html --
{{ $r := .Page.Resources.Get (.Get 0)}}
Resource: {{ (.Get 0) }}|{{ with $r }}{{ .RelPermalink }}|{{ .Content }}|{{ else }}Not found.{{ end}}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|{{ .RelPermalink }}|{{ .Lang }}|{{ .Content }}|
`
b := Test(t, files)
---
-- content/mybundle/data.json --
MyData
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ range .Resources }}
{{ .ResourceType }}|{{ .Title }}|
{{ end }}
title: "Bundled page nn"
---
--- layouts/_default/single.html --
+-- layouts/single.html --
Bundled page: {{ .RelPermalink}}|Len resources: {{ len .Resources }}|
files := `
-- hugo.toml --
baseURL = "https://example.com"
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ range .Resources }}
{{ .ResourceType }}|{{ .Title }}|
{{ end }}

-- content/data.json --
DATA
--- layouts/index.html --
+-- layouts/home.html --
Title: {{ .Title }}|First Resource: {{ index .Resources 0 }}|Content: {{ .Content }}
--- layouts/_default/_markup/render-image.html --
+-- layouts/_markup/render-image.html --
Hook Len Page Resources {{ len .Page.Resources }}
`
b := Test(t, files)
---
-->
<html>hello</html>
--- layouts/index.html --
+-- layouts/home.html --
{{ range site.RegularPages }}{{ .RelPermalink }}|{{ end }}$
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|{{ .RelPermalink }}Resources: {{ range .Resources }}{{ .Name }}|{{ end }}$
`
-- content/mysection/p2.md --
-- content/mysection/p2.html --
-- content/mysection/foo/p2.md --
--- layouts/_default/single.html --
+-- layouts/single.html --
Single:{{ .Title }}|{{ .Path }}|File LogicalName: {{ with .File }}{{ .LogicalName }}{{ end }}||{{ .RelPermalink }}|{{ .Kind }}|Resources: {{ range .Resources}}{{ .Name }}: {{ .Content }}|{{ end }}$
--- layouts/_default/list.html --
+-- layouts/list.html --
List: {{ .Title }}|{{ .Path }}|File LogicalName: {{ with .File }}{{ .LogicalName }}{{ end }}|{{ .RelPermalink }}|{{ .Kind }}|Resources: {{ range .Resources}}{{ .Name }}: {{ .Content }}|{{ end }}$
RegularPages: {{ range .RegularPages }}{{ .RelPermalink }}|File LogicalName: {{ with .File }}{{ .LogicalName }}|{{ end }}{{ end }}$
`
-- content/mybundle/index.md --
-- content/mybundle/f1.en.txt --
F1.
--- layouts/_default/single.html --
+-- layouts/single.html --
GetMatch: {{ with .Resources.GetMatch "f1.en.*" }}{{ .Name }}: {{ .Content }}|{{ end }}
Match: {{ range .Resources.Match "f1.En.*" }}{{ .Name }}: {{ .Content }}|{{ end }}
`
---
-- content/mybundle/f1.en.txt --
F1.
--- layouts/_default/single.html --
+-- layouts/single.html --
GetMatch: {{ with .Resources.GetMatch "f1.*" }}{{ .Name }}: {{ .Content }}|{{ end }}$
`
---
p1.txt
---
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Title }}|
`
files := `
-- hugo.toml --
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Title }}
-- content/_index.md --
---
title: "Mysect Index"
---
--- layouts/index.html --
+-- layouts/home.html --
GetPage 1: {{ with site.GetPage "mysect/index/index.md" }}{{ .Title }}|{{ .RelPermalink }}|{{ .Path }}{{ end }}|
GetPage 2: {{ with site.GetPage "mysect/index" }}{{ .Title }}|{{ .RelPermalink }}|{{ .Path }}{{ end }}|
`
---title: members who
draft: true
---
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ with .GetPage "members.md" }}
Members: {{ .Title }}
{{ else }}
---
-- p1/p1.xyz --
xyz.
--- layouts/index.html --
+-- layouts/home.html --
Home. {{ with .Page.GetPage "p1.xyz" }}{{ else }}OK 1{{ end }} {{ with .Site.GetPage "p1.xyz" }}{{ else }}OK 2{{ end }}
`
title: p2
layout: p2
---
--- layouts/_default/p1.html --
+-- layouts/p1.html --
{{ (.GetPage "p2.md").Title }}|
--- layouts/_default/p2.html --
+-- layouts/p2.html --
{{ (.GetPage "p1").Title }}|
`
title: p1
tags: [news]
---
--- layouts/index.html --
+-- layouts/home.html --
/tags/news: {{ with .Site.GetPage "/tags/news" }}{{ .Title }}{{ end }}|
news: {{ with .Site.GetPage "news" }}{{ .Title }}{{ end }}|
/news: {{ with .Site.GetPage "/news" }}{{ .Title }}{{ end }}|
---
title: p2
---
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ with .GetPage "p2" }}
OK: {{ .LinkTitle }}
{{ else }}
---
title: p2_root
---
--- layouts/index.html --
+-- layouts/home.html --
/s1: {{ with .GetPage "/s1" }}{{ .Title }}{{ end }}|
/s1/: {{ with .GetPage "/s1/" }}{{ .Title }}{{ end }}|
/s1/p2.md: {{ with .GetPage "/s1/p2.md" }}{{ .Title }}{{ end }}|
/s1/p2: {{ with .GetPage "/s1/p2" }}{{ .Title }}{{ end }}|
/s1/p1/index.md: {{ with .GetPage "/s1/p1/index.md" }}{{ .Title }}{{ end }}|
/s1/p1: {{ with .GetPage "/s1/p1" }}{{ .Title }}{{ end }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
../p2: {{ with .GetPage "../p2" }}{{ .Title }}{{ end }}|
../p2.md: {{ with .GetPage "../p2.md" }}{{ .Title }}{{ end }}|
p1/index.md: {{ with .GetPage "p1/index.md" }}{{ .Title }}{{ end }}|
---
title: d1
---
--- layouts/shortcodes/ref.html --
+-- layouts/_shortcodes/ref.html --
{{ $ref := .Get 0 }}
.Page.GetPage({{ $ref }}).Title: {{ with .Page.GetPage $ref }}{{ .Title }}{{ end }}|
--- layouts/index.html --
+-- layouts/home.html --
Home.
/blog/b1.md: {{ with .GetPage "/blog/b1.md" }}{{ .Title }}{{ end }}|
/blog/b2/index.md: {{ with .GetPage "/blog/b2/index.md" }}{{ .Title }}{{ end }}|
/docs/d1.md: {{ with .GetPage "/docs/d1.md" }}{{ .Title }}{{ end }}|
/README.md: {{ with .GetPage "/README.md" }}{{ .Title }}{{ end }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
/README.md: {{ with .GetPage "/README.md" }}{{ .Title }}{{ end }}|
{{ .Content }}
---
title: about1en
---
--- layouts/index.html --
+-- layouts/home.html --
{{ with site.GetPage "docs/1" }}
Docs p1: {{ .Title }}
{{ else }}
---
title: news1
---
--- layouts/index.html --
+-- layouts/home.html --
{{ $sect1 := site.GetPage "sect1" }}
Sect1 RegularPagesRecursive: {{ range $sect1.RegularPagesRecursive }}{{ .Kind }}:{{ .RelPermalink}}|{{ end }}|End.
-- hugo.toml --
-- content/p1.md --
-- content/post/p2.md --
--- layouts/index.html --
+-- layouts/home.html --
RegularPagesRecursive: {{ range .RegularPagesRecursive }}{{ .Kind }}:{{ .RelPermalink}}|{{ end }}|End.
`
-- content/s1-foo/s2/p3.md --
-- content/s1-foo/s2-foo/_index.md --
-- content/s1-foo/s2-foo/p4.md --
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .RelPermalink }}: Pages: {{ range .Pages }}{{ .RelPermalink }}|{{ end }}$
`
files := `
-- hugo.toml --
disableKinds = ['rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
Test A: {{ (site.GetPage "/s1/p1").Title }}
Test B: {{ (site.GetPage "p1").Title }}
Test C: {{ (site.GetPage "/s2/p2").Title }}
Test D: {{ (site.GetPage "p2").Title }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
-- content/s1/p1.md --
---
{{ $nil := resources.Get "asdfasdfasdf" }}
Pages3: {{ $frSite.RegularPages | lang.Merge $nil }}
Pages4: {{ $nil | lang.Merge $frSite.RegularPages }}
--- layouts/shortcodes/shortcode.html --
+-- layouts/_shortcodes/shortcode.html --
MyShort
--- layouts/shortcodes/lingo.html --
+-- layouts/_shortcodes/lingo.html --
MyLingo
`
b := Test(t, files)
// Add shortcode templates
b.WriteString(`
--- layouts/shortcodes/shortcode.html --
+-- layouts/_shortcodes/shortcode.html --
MyShort
--- layouts/shortcodes/lingo.html --
+-- layouts/_shortcodes/lingo.html --
MyLingo
`)
-- assets/mydata.yaml --
p1: "p1"
draft: false
--- layouts/partials/get-value.html --
+-- layouts/_partials/get-value.html --
{{ $val := "p1" }}
{{ return $val }}
--- layouts/_default/baseof.html --
+-- layouts/baseof.html --
Baseof:
{{ block "main" . }}{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ define "main" }}
Single: {{ .Title }}|{{ .Content }}|Params: {{ .Params.param1 }}|Path: {{ .Path }}|
Dates: Date: {{ .Date.Format "2006-01-02" }}|Lastmod: {{ .Lastmod.Format "2006-01-02" }}|PublishDate: {{ .PublishDate.Format "2006-01-02" }}|ExpiryDate: {{ .ExpiryDate.Format "2006-01-02" }}|
{{ end}}
{{ end }}
{{ end }}
--- layouts/_default/list.html --
+-- layouts/list.html --
List: {{ .Title }}|{{ .Content }}|
RegularPagesRecursive: {{ range .RegularPagesRecursive }}{{ .Title }}:{{ .Path }}|{{ end }}$
Sections: {{ range .Sections }}{{ .Title }}:{{ .Path }}|{{ end }}$
[security]
[security.exec]
allow = ['asciidoctor', 'pandoc','rst2html', 'python']
--- layouts/_default/single.html --
+-- layouts/single.html --
|Content: {{ .Content }}|Title: {{ .Title }}|Path: {{ .Path }}|
-- content/docs/_content.gotmpl --
{{ $.AddPage (dict "path" "asciidoc" "content" (dict "value" "Mark my words, #automation is essential#." "mediaType" "text/asciidoc" )) }}
func TestPagesFromGoTmplEditPartial(t *testing.T) {
t.Parallel()
b := hugolib.TestRunning(t, filesPagesFromDataTempleBasic)
- b.EditFileReplaceAll("layouts/partials/get-value.html", "p1", "p1edited").Build()
+ b.EditFileReplaceAll("layouts/_partials/get-value.html", "p1", "p1edited").Build()
b.AssertFileContent("public/docs/p1/index.html", "Single: p1:p1edited|")
b.AssertFileContent("public/docs/index.html", "p1edited")
}
weight = 2
title = "Titre"
disabled = DISABLE
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: {{ .Title }}|{{ .Content }}|
-- content/docs/_content.gotmpl --
{{ $.AddPage (dict "kind" "page" "path" "p1" "title" "Title" ) }}
files := `
-- hugo.toml --
defaultContentLanguage = "en"
--- layouts/index.html --
+-- layouts/home.html --
{{ range site.RegularPages }}{{ .RelPermalink }}|{{ end}}
-- content/_content.gotmpl --
{{ $.AddPage (dict "kind" "page" "path" "docs/_p22" "title" "A" ) }}
-- hugo.toml --
disableKinds = ["taxonomy", "term", "rss", "sitemap"]
baseURL = "https://example.com"
--- layouts/_default/single.html --
+-- layouts/single.html --
|Content: {{ .Content }}|Title: {{ .Title }}|Path: {{ .Path }}|
-- content/docs/_content.gotmpl --
{{ $content := "**Hello World**" | markdownify }}
-- hugo.toml --
disableKinds = ["taxonomy", "term", "rss", "sitemap"]
baseURL = "https://example.com"
--- layouts/_default/single.html --
+-- layouts/single.html --
|Content: {{ .Content }}|Title: {{ .Title }}|Path: {{ .Path }}|
{{ range .Resources }}
|RelPermalink: {{ .RelPermalink }}|Name: {{ .Name }}|Title: {{ .Title }}|Params: {{ .Params }}|MediaType: {{ .MediaType }}|
-- hugo.toml --
disableKinds = ["taxonomy", "term", "rss", "sitemap"]
baseURL = "https://example.com"
--- layouts/_default/single.html --
+-- layouts/single.html --
|Content: {{ .Content }}|Title: {{ .Title }}|Path: {{ .Path }}|Params: {{ .Params }}|
-- content/_content.gotmpl --
{{ $cascade := dict "params" (dict "cascadeparam1" "cascadeparam1value" ) }}
-- hugo.toml --
disableKinds = ["taxonomy", "term", "rss", "sitemap"]
baseURL = "https://example.com"
--- layouts/_default/single.html --
+-- layouts/single.html --
|Content: {{ .Content }}|Title: {{ .Title }}|Path: {{ .Path }}|Params: {{ .Params }}|
-- content/_content.gotmpl --
{{ $.AddPage (dict "path" "docs/p1" "content" (dict "value" "**Hello World**" "mediaType" "text/markdown" )) }}
disableKinds = ['home','section','rss','sitemap','taxonomy','term']
-- content/_content.gotmpl --
{{ .AddPage (dict "path" "s-1.2.3/p-4.5.6" "title" "p-4.5.6") }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
`
-- content/_content.gotmpl --
{{ .AddPage (dict "path" "p1" "title" "p1" "params" (dict "paraM1" "param1v" )) }}
{{ .AddResource (dict "path" "p1/data1.yaml" "content" (dict "value" "data1" ) "params" (dict "paraM1" "param1v" )) }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|{{ .Params.paraM1 }}
{{ range .Resources }}
{{ .Name }}|{{ .Params.paraM1 }}
{{ $content := dict "mediaType" "text/html" "value" "{{< sc >}}" }}
{{ .AddPage (dict "content" $content "path" "b") }}
--- layouts/_default/single.html --
+-- layouts/single.html --
|{{ .Content }}|
--- layouts/shortcodes/sc.html --
+-- layouts/_shortcodes/sc.html --
foo
{{- /**/ -}}
`
-- content/_content.gotmpl --
{{ .AddPage (dict "path" "p1" "title" "p1" "menus" "main" ) }}
{{ .AddPage (dict "path" "p2" "title" "p2" "menus" (slice "main" "footer")) }}
--- layouts/index.html --
+-- layouts/home.html --
Main: {{ range index site.Menus.main }}{{ .Name }}|{{ end }}|
Footer: {{ range index site.Menus.footer }}{{ .Name }}|{{ end }}|
{{ $menus := dict "m1" $menu1 "m2" $menu2 }}
{{ .AddPage (dict "path" "p1" "title" "p1" "menus" $menus ) }}
--- layouts/index.html --
+-- layouts/home.html --
Menus: {{ range $k, $v := site.Menus }}{{ $k }}|{{ end }}
`
"path" "p1"
}}
{{ .AddPage $page }}
--- layouts/_default/single.html --
+-- layouts/single.html --
summary: {{ .Summary }}|content: {{ .Content}}
`
-- content/tags/_content.gotmpl --
{{ .AddPage (dict "path" "mothertag" "title" "My title" "kind" "term") }}
--
--- layouts/_default/taxonomy.html --
+-- layouts/taxonomy.html --
Terms: {{ range .Data.Terms.ByCount }}{{ .Name }}: {{ .Count }}|{{ end }}§s
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
`
}
files += `
--- layouts/index.html --
+-- layouts/home.html --
{{ $pag := $.Paginator }}
Total: {{ $pag.TotalPages }}
First: {{ $pag.First.URL }}
baseURL = "https://example.com/"
-- content/p1.md --
-- content/p2.md --
--- layouts/index.html --
+-- layouts/home.html --
{{ $empty := site.RegularPages | complement site.RegularPages }}
Len: {{ len $empty }}: Type: {{ printf "%T" $empty }}
{{ $pgs := $empty.GroupByPublishDate "January 2006" }}
[pagination]
pagerSize = 1
-- content/p1.md --
--- layouts/_default/single.html --
+-- layouts/single.html --
Paginator: {{ .Paginator }}
`
b, err := TestE(t, files)
files := `
-- hugo.toml --
-- content/p1.md --
--- layouts/_default/single.html --
+-- layouts/single.html --
Home Filename: {{ site.Home.File.Filename }}
`
b, err := TestE(t, files)
a: "p1-a"
summary: "params.summary"
---
--- layouts/_default/single.html --
+-- layouts/single.html --
Params: {{ range $k, $v := .Params }}{{ $k }}: {{ $v }}|{{ end }}$
Summary: {{ .Summary }}|
`
title: "P1"
build: "foo"
---
--- layouts/_default/single.html --
+-- layouts/single.html --
Params: {{ range $k, $v := .Params }}{{ $k }}: {{ $v }}|{{ end }}$
`
b, err := TestE(t, files)
Assets My Shortcode Text.
-- assets/myothertext.txt --
Assets My Other Text.
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: {{ .Title }}|{{ .Content }}$
Resources: {{ range $i, $e := .Resources }}{{ $i }}:{{ .RelPermalink }}|{{ .Content }}|{{ end }}$
Len Resources: {{ len .Resources }}|
--- layouts/_default/list.html --
+-- layouts/list.html --
List: {{ .Title }}|{{ .Content }}$
Len Resources: {{ len .Resources }}|
Resources: {{ range $i, $e := .Resources }}{{ $i }}:{{ .RelPermalink }}|{{ .Content }}|{{ end }}$
--- layouts/shortcodes/foo.html --
+-- layouts/_shortcodes/foo.html --
Foo.
--- layouts/shortcodes/myshortcodetext.html --
+-- layouts/_shortcodes/myshortcodetext.html --
{{ warnf "mytext %s" now}}
{{ $r := resources.Get "myshortcodetext.txt" }}
My Shortcode Text: {{ $r.Content }}|{{ $r.Permalink }}|
--- layouts/_default/_markup/render-codeblock-myothertext.html --
+-- layouts/_markup/render-codeblock-myothertext.html --
{{ $r := resources.Get "myothertext.txt" }}
My Other Text: {{ $r.Content }}|{{ $r.Permalink }}|
-- content/mybundle/index.md --
-- content/mybundle/mydata.yml --
foo: bar
--- layouts/_default/single.html --
+-- layouts/single.html --
MyData: {{ .Resources.Get "mydata.yml" | transform.Unmarshal }}|
`
b := TestRunning(t, files)
---
title: "P1"
---
--- layouts/index.html --
+-- layouts/home.html --
Pages: {{ range .Site.RegularPages }}{{ .RelPermalink }}|{{ end }}$
`
b := TestRunning(t, files)
-- content/foo/p1.h.md --
-- content/foo/p1.i.md --
-- content/foo/p1.j.md --
--- layouts/index.html --
+-- layouts/home.html --
RegularPages: {{ range .Site.RegularPages }}{{ .RelPermalink }}|{{ end }}$
`
b := TestRunning(t, files)
title: "P1"
weight: 1
---
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: {{ .Title }}|{{ .Content }}|
--- layouts/index.html --
+-- layouts/home.html --
Pages: {{ range .RegularPages }}{{ .RelPermalink }}|{{ end }}$
`
title: "P1"
weight: 1
---
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: {{ .Title }}|{{ .Content }}|
--- layouts/index.html --
+-- layouts/home.html --
Pages: {{ range .RegularPages }}{{ .RelPermalink }}|{{ end }}$
`
P1 Content.
{{< myshort >}}
--- layouts/_default/single.html --
+-- layouts/single.html --
Single HTML: {{ .Title }}|{{ .Content }}|
--- layouts/_default/single.json --
+-- layouts/single.json --
Single JSON: {{ .Title }}|{{ .Content }}|
--- layouts/shortcodes/myshort.html --
+-- layouts/_shortcodes/myshort.html --
My short.
`
b := Test(t, files, TestOptRunning())
b.AssertRenderCountContent(1)
b.AssertFileContent("public/p1/index.html", "Single HTML: P1|<p>P1 Content.</p>\n")
b.AssertFileContent("public/p1/index.json", "Single JSON: P1|<p>P1 Content.</p>\n")
- b.EditFileReplaceAll("layouts/_default/single.html", "Single HTML", "Single HTML Edited").Build()
+ b.EditFileReplaceAll("layouts/single.html", "Single HTML", "Single HTML Edited").Build()
b.AssertFileContent("public/p1/index.html", "Single HTML Edited: P1|<p>P1 Content.</p>\n")
b.AssertRenderCountPage(1)
// Edit shortcode. Note that this is reused across all output formats.
- b.EditFileReplaceAll("layouts/shortcodes/myshort.html", "My short", "My short edited").Build()
+ b.EditFileReplaceAll("layouts/_shortcodes/myshort.html", "My short", "My short edited").Build()
b.AssertFileContent("public/p1/index.html", "My short edited")
b.AssertFileContent("public/p1/index.json", "My short edited")
b.AssertRenderCountPage(3) // rss (uses .Content) + 2 single pages.
baseURL = "https://example.com"
disableKinds = ["term", "taxonomy"]
disableLiveReload = true
--- layouts/_default/baseof.html --
+-- layouts/baseof.html --
Baseof: {{ .Title }}|
{{ block "main" . }}default{{ end }}
--- layouts/index.html --
+-- layouts/home.html --
{{ define "main" }}
Home: {{ .Title }}|{{ .Content }}|
{{ end }}
`
testRebuildBothWatchingAndRunning(t, files, func(b *IntegrationTestBuilder) {
b.AssertFileContent("public/index.html", "Baseof: Hugo Site|", "Home: Hugo Site||")
- b.EditFileReplaceFunc("layouts/_default/baseof.html", func(s string) string {
+ b.EditFileReplaceFunc("layouts/baseof.html", func(s string) string {
return strings.Replace(s, "Baseof", "Baseof Edited", 1)
}).Build()
b.AssertFileContent("public/index.html", "Baseof Edited: Hugo Site|", "Home: Hugo Site||")
title: "P1"
---
P1 Content.
--- layouts/index.html --
+-- layouts/home.html --
Home.
-- layouts/single.html --
Single: {{ .Title }}|{{ .Content }}|
---
P1 Content.
[foo](/foo)
--- layouts/_default/baseof.html --
+-- layouts/baseof.html --
Baseof: {{ .Title }}|
{{ block "main" . }}default{{ end }}
{{ with (templates.Defer (dict "foo" "bar")) }}
Defer.
{{ end }}
--- layouts/index.html --
+-- layouts/home.html --
Home.
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ define "main" }}
Single: {{ .Title }}|{{ .Content }}|
{{ end }}
`
b := Test(t, files, TestOptRunning())
b.AssertFileContent("public/p1/index.html", "Single: P1|")
- b.EditFileReplaceFunc("layouts/_default/single.html", func(s string) string {
+ b.EditFileReplaceFunc("layouts/single.html", func(s string) string {
return strings.Replace(s, "Single", "Single Edited", 1)
}).Build()
b.AssertFileContent("public/p1/index.html", "Single Edited")
---
P1 Content.
[foo](/foo)
--- layouts/_default/baseof.html --
+-- layouts/baseof.html --
Baseof: {{ .Title }}|
{{ block "main" . }}default{{ end }}
{{ with (templates.Defer (dict "foo" "bar")) }}
Defer.
{{ end }}
--- layouts/index.html --
+-- layouts/home.html --
Home.
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ define "main" }}
Single: {{ .Title }}|{{ .Content }}|
{{ end }}
b := Test(t, files, TestOptRunning())
b.AssertFileContent("public/p1/index.html", "Single: P1|")
fmt.Println("===============")
- b.EditFileReplaceAll("layouts/_default/baseof.html", "Baseof", "Baseof Edited").Build()
+ b.EditFileReplaceAll("layouts/baseof.html", "Baseof", "Baseof Edited").Build()
b.AssertFileContent("public/p1/index.html", "Baseof Edited")
}
---
P1 Content.
[foo](/foo)
--- layouts/_default/baseof.html --
+-- layouts/baseof.html --
Baseof: {{ .Title }}|
{{ block "main" . }}default{{ end }}
{{ with (templates.Defer (dict "foo" "bar")) }}
{{ define "main" }}
Single: {{ .Title }}|{{ .Content }}|
{{ end }}
--- layouts/_default/_markup/render-link.html --
+-- layouts/_markup/render-link.html --
Render Link.
`
b := Test(t, files, TestOptRunning())
// Edit render hook.
- b.EditFileReplaceAll("layouts/_default/_markup/render-link.html", "Render Link", "Render Link Edited").Build()
+ b.EditFileReplaceAll("layouts/_markup/render-link.html", "Render Link", "Render Link Edited").Build()
b.AssertFileContent("public/p1/index.html", "Render Link Edited")
}
P2 Content.
-- assets/mytext.txt --
My Text
--- layouts/_default/l1.html --
+-- layouts/l1.html --
{{ $r := partial "get-resource.html" . }}
L1: {{ .Title }}|{{ .Content }}|R: {{ $r.Content }}|
--- layouts/_default/l2.html --
+-- layouts/l2.html --
L2.
--- layouts/partials/get-resource.html --
+-- layouts/_partials/get-resource.html --
{{ $mytext := resources.Get "mytext.txt" }}
{{ $txt := printf "Text: %s" $mytext.Content }}
{{ $r := resources.FromString "r.txt" $txt }}
---
title: "P7"
---
--- layouts/_default/list.html --
+-- layouts/list.html --
List.
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
--- layouts/_default/single.html --
+-- layouts/single.html --
Next: {{ with .PrevInSection }}{{ .Title }}{{ end }}|
Prev: {{ with .NextInSection }}{{ .Title }}{{ end }}|
title: "P7 NN"
---
P7 NN Content.
--- layouts/index.html --
+-- layouts/home.html --
Home: {{ .Title }}|{{ .Content }}|
RegularPages: {{ range .RegularPages }}{{ .RelPermalink }}|{{ end }}$
Len RegularPagesRecursive: {{ len .RegularPagesRecursive }}
Site.Lastmod: {{ .Site.Lastmod.Format "2006-01-02" }}|
Paginate: {{ range (.Paginate .Site.RegularPages).Pages }}{{ .RelPermalink }}|{{ .Title }}|{{ end }}$
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: .Site: {{ .Site }}
Single: {{ .Title }}|{{ .Content }}|
Single Partial Cached: {{ partialCached "pcached" . }}|
Page.Lastmod: {{ .Lastmod.Format "2006-01-02" }}|
Cascade param: {{ .Params.cascadeparam }}|
--- layouts/_default/list.html --
+-- layouts/list.html --
List: {{ .Title }}|{{ .Content }}|
RegularPages: {{ range .RegularPages }}{{ .Title }}|{{ end }}$
Len RegularPagesRecursive: {{ len .RegularPagesRecursive }}
List Partial P1: {{ partial "p1" . }}|
Page.Lastmod: {{ .Lastmod.Format "2006-01-02" }}|
Cascade param: {{ .Params.cascadeparam }}|
--- layouts/partials/p1.html --
+-- layouts/_partials/p1.html --
Partial P1.
--- layouts/partials/pcached.html --
+-- layouts/_partials/pcached.html --
Partial Pcached.
--- layouts/shortcodes/include.html --
+-- layouts/_shortcodes/include.html --
{{ $p := site.GetPage (.Get 0)}}
.Page.Site: {{ .Page.Site }} :: site: {{ site }}
{{ with $p }}
{{ end }}
Shortcode .Page.Title: {{ .Page.Title }}|
Shortcode Partial P1: {{ partial "p1" . }}|
--- layouts/_default/_markup/render-codeblock.html --
+-- layouts/_markup/render-codeblock.html --
{{ $p := site.GetPage (.Attributes.page)}}
{{ with $p }}
Codeblock Include: {{ .Title }}|
b.AssertFileContent("public/en/translations/index.html", "RegularPagesRecursive: /en/translations/p7/")
// Edit shortcode
- editFile("layouts/shortcodes/include.html", func(s string) string {
+ editFile("layouts/_shortcodes/include.html", func(s string) string {
return s + "\nShortcode Include Edited."
})
b.AssertFileContent("public/mysect/p1/index.html", "Shortcode Include Edited.")
// Edit render hook
- editFile("layouts/_default/_markup/render-codeblock.html", func(s string) string {
+ editFile("layouts/_markup/render-codeblock.html", func(s string) string {
return s + "\nCodeblock Include Edited."
})
b.AssertFileContent("public/mysect/p1/index.html", "Codeblock Include Edited.")
// Edit partial p1
- editFile("layouts/partials/p1.html", func(s string) string {
+ editFile("layouts/_partials/p1.html", func(s string) string {
return strings.Replace(s, "Partial P1", "Partial P1 Edited", 1)
})
b.AssertFileContent("public/mysect/index.html", "List Partial P1: Partial P1 Edited.")
b.AssertFileContent("public/mysect/p1/index.html", "Shortcode Partial P1: Partial P1 Edited.")
// Edit partial cached.
- editFile("layouts/partials/pcached.html", func(s string) string {
+ editFile("layouts/_partials/pcached.html", func(s string) string {
return strings.Replace(s, "Partial Pcached", "Partial Pcached Edited", 1)
})
b.AssertFileContent("public/mysect/p1/index.html", "Pcached Edited.")
}
-- layouts/default/list.html --
List.
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
{{ $css := resources.Get "main.css" | minify }}
RelPermalink: {{ $css.RelPermalink }}|
P4.
-- assets/js/main.js --
console.log("Hello");
--- layouts/_default/list.html --
+-- layouts/list.html --
List. {{ partial "head.html" . }}$
--- layouts/_default/single.html --
+-- layouts/single.html --
Single. {{ partial "head.html" . }}$
--- layouts/partials/head.html --
+-- layouts/_partials/head.html --
{{ partialCached "js.html" . }}$
--- layouts/partials/js.html --
+-- layouts/_partials/js.html --
{{ $js := resources.Get "js/main.js" | js.Build | fingerprint }}
RelPermalink: {{ $js.RelPermalink }}|
`
disableLiveReload = true
-- assets/js/main.js --
console.log("Hello");
--- layouts/_default/baseof.html --
+-- layouts/baseof.html --
Base. {{ partial "common/head.html" . }}$
{{ block "main" . }}default{{ end }}
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ define "main" }}main{{ end }}
--- layouts/partials/common/head.html --
+-- layouts/_partials/common/head.html --
{{ partial "myfiles/js.html" . }}$
--- layouts/partials/myfiles/js.html --
+-- layouts/_partials/myfiles/js.html --
{{ $js := resources.Get "js/main.js" | js.Build | fingerprint }}
RelPermalink: {{ $js.RelPermalink }}|
`
console.log("Hello");
-- content/foo.js --
console.log("Foo");
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ $js := site.Home.Resources.Get "main.js" }}
{{ with $js }}
<script src="{{ .RelPermalink }}"></script>
{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
Single. Deliberately no .Content in here.
--- layouts/_default/plain.html --
+-- layouts/plain.html --
Content: {{ .Content }}|
--- layouts/_default/main.html --
+-- layouts/main.html --
{{ $js := site.Home.Resources.Get "main.js" }}
{{ with $js }}
<script>
{{ .Content }}
</script>
{{ end }}
--- layouts/shortcodes/jsfingerprinted.html --
+-- layouts/_shortcodes/jsfingerprinted.html --
{{ $js := site.Home.Resources.Get "foo.js" | fingerprint }}
<script src="{{ $js.RelPermalink }}"></script>
`
---
Foo inline: {{< foo.inline >}}{{ site.Data.mydata.foo }}|{{< /foo.inline >}}
--- layouts/shortcodes/data.html --
+-- layouts/_shortcodes/data.html --
{{ $path := split (.Get 0) "." }}
{{ $data := index site.Data $path }}
Foo: {{ $data }}|
--- layouts/index.html --
+-- layouts/home.html --
Content: {{ .Content }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: {{ .Content }}|
`
b := TestRunning(t, files)
title: "Home"
---
Home.
--- layouts/index.html --
+-- layouts/home.html --
Content: {{ .Content }}
`
b := TestRunning(t, files)
title: "Home"
---
Home.
--- layouts/index.html --
+-- layouts/home.html --
Home.
--- layouts/_default/index.searchindex.txt --
+-- layouts/index.searchindex.txt --
Text. {{ .Title }}|{{ .RelPermalink }}|
`
b.AssertFileContent("public/search.txt", "Text.")
- b.EditFileReplaceAll("layouts/_default/index.searchindex.txt", "Text.", "Text Edited.").Build()
+ b.EditFileReplaceAll("layouts/index.searchindex.txt", "Text.", "Text Edited.").Build()
b.BuildPartial("/docs/search.txt")
baseURL = "https://example.com"
disableKinds = ["term", "taxonomy"]
disableLiveReload = true
--- layouts/index.html --
+-- layouts/home.html --
Home. {{ now }}
{{ with (resources.Get "js/main.js" | js.Build | fingerprint) }}
<script>{{ .Content | safeJS }}</script>
layout: "foo"
---
{{< notfingerprinted >}}
--- layouts/shortcodes/fingerprinted.html --
+-- layouts/_shortcodes/fingerprinted.html --
Fingerprinted.
{{ $opts := dict "inlineImports" true "noMap" true }}
{{ with (resources.Get "css/main.css" | postCSS $opts | fingerprint) }}
<style src="{{ .RelPermalink }}"></style>
{{ end }}
--- layouts/shortcodes/notfingerprinted.html --
+-- layouts/_shortcodes/notfingerprinted.html --
Fingerprinted.
{{ $opts := dict "inlineImports" true "noMap" true }}
{{ with (resources.Get "css/main.css" | postCSS $opts) }}
<style src="{{ .RelPermalink }}"></style>
{{ end }}
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ $opts := dict "inlineImports" true "noMap" true }}
{{ with (resources.Get "css/main.css" | postCSS $opts) }}
<style>{{ .Content | safeCSS }}</style>
{{ end }}
--- layouts/_default/foo.html --
+-- layouts/foo.html --
Foo.
{{ .Title }}|{{ .Content }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
{{ $opts := dict "inlineImports" true "noMap" true }}
{{ with (resources.Get "css/main.css" | postCSS $opts) }}
disableLiveReload = true
-- i18n/en.toml --
hello = "Hello"
--- layouts/index.html --
+-- layouts/home.html --
Hello: {{ i18n "hello" }}
`
B nn.
-- content/p1/f1.nn.txt --
F1 nn
--- layouts/_default/all.html --
+-- layouts/all.html --
All: {{ .Title }}|{{ .Kind }}|{{ .Content }}|Bundled File: {{ with .Resources.GetMatch "f1.*" }}{{ .Content }}{{ end }}|Bundled Page: {{ with .Resources.GetMatch "b.*" }}{{ .Content }}{{ end }}|
`
title: "P1 nn"
---
P1 nn.
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: {{ .Title }}|{{ .Content }}|
`
}
-- assets/css/main.scss --
@import "lib/foo";
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ $opts := dict "transpiler" "TRANSPILER" }}
{{ with (resources.Get "css/main.scss" | toCSS $opts) }}
baseURL = "https://example.com"
disableKinds = ["term", "taxonomy"]
disableLiveReload = true
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: {{ .Title }}|{{ .Content }}|
--- layouts/_default/list.html --
+-- layouts/list.html --
List: {{ .Title }}|{{ .Content }}|
-- content/mysect/_index.md --
---
c1
-- assets/common/c2.css --
c2
--- layouts/index.html --
+-- layouts/home.html --
{{ $a := resources.Get "a.css" }}
{{ $b := resources.Get "b.css" }}
{{ $common := resources.Match "common/*.css" | resources.Concat "common.css" | minify }}
-- hugo.toml --
baseURL = "https://example.com"
disableLiveReload = true
--- layouts/partials/MyTemplate.html --
+-- layouts/_partials/MyTemplate.html --
MyTemplate
--- layouts/index.html --
+-- layouts/home.html --
MyTemplate: {{ partial "MyTemplate.html" . }}|
b.AssertFileContent("public/index.html", "MyTemplate: MyTemplate")
- b.EditFileReplaceAll("layouts/partials/MyTemplate.html", "MyTemplate", "MyTemplate Edited").Build()
+ b.EditFileReplaceAll("layouts/_partials/MyTemplate.html", "MyTemplate", "MyTemplate Edited").Build()
b.AssertFileContent("public/index.html", "MyTemplate: MyTemplate Edited")
}
title: "P2"
---
P2 Content.
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: {{ .Title }}|{{ .Content }}|
`
b := TestRunning(t, files)
-- hugo.toml --
disableKinds = ['rss','section','sitemap','taxonomy','term']
disableLiveReload = true
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ range .Pages }}{{ .Title }}|{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
-- content/p1.md --
---
baseURL = "https://example.com"
disableKinds = ['sitemap','taxonomy','term']
disableLiveReload = true
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Content }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
-- content/_index.md --
---
### p3-h2
{{% withmarkdown %}}
{{< level3 >}}
--- layouts/shortcodes/include.html --
+-- layouts/_shortcodes/include.html --
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
--- layouts/shortcodes/withhtml.html --
+-- layouts/_shortcodes/withhtml.html --
<div>{{ .Page.Title }} withhtml</div>
--- layouts/shortcodes/withmarkdown.html --
+-- layouts/_shortcodes/withmarkdown.html --
#### {{ .Page.Title }} withmarkdown
--- layouts/shortcodes/level3.html --
+-- layouts/_shortcodes/level3.html --
Level 3: {{ .Page.Title }}
--- layouts/_default/single.html --
+-- layouts/single.html --
Fragments: {{ .Fragments.Identifiers }}|
HasShortcode Level 1: {{ .HasShortcode "include" }}|
HasShortcode Level 2: {{ .HasShortcode "withmarkdown" }}|
---
### p2-h1
{{% myshort %}}
--- layouts/shortcodes/include.html --
+-- layouts/_shortcodes/include.html --
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
--- layouts/shortcodes/myshort.html --
+-- layouts/_shortcodes/myshort.html --
Myshort HTML.
--- layouts/shortcodes/myshort.json --
+-- layouts/_shortcodes/myshort.json --
Myshort JSON.
--- layouts/_default/single.html --
+-- layouts/single.html --
HTML: {{ .Content }}
--- layouts/_default/single.json --
+-- layouts/single.json --
JSON: {{ .Content }}
---
### p2-h1
{{% myshort %}}
--- layouts/shortcodes/include.html --
+-- layouts/_shortcodes/include.html --
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
--- layouts/shortcodes/myshort.html --
+-- layouts/_shortcodes/myshort.html --
Myshort Original.
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
b := TestRunning(t, files)
b.AssertNoRenderShortcodesArtifacts()
b.AssertFileContent("public/p1/index.html", "Myshort Original.")
- b.EditFileReplaceAll("layouts/shortcodes/myshort.html", "Original", "Edited").Build()
+ b.EditFileReplaceAll("layouts/_shortcodes/myshort.html", "Original", "Edited").Build()
b.AssertNoRenderShortcodesArtifacts()
b.AssertFileContent("public/p1/index.html", "Myshort Edited.")
}
---
### Original
{{% myshort %}}
--- layouts/shortcodes/include.html --
+-- layouts/_shortcodes/include.html --
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
--- layouts/shortcodes/myshort.html --
+-- layouts/_shortcodes/myshort.html --
Myshort Original.
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
---
### Original
{{% myshort %}}
--- layouts/shortcodes/include.html --
+-- layouts/_shortcodes/include.html --
{{ $p := .Page.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
--- layouts/shortcodes/myshort.html --
+-- layouts/_shortcodes/myshort.html --
Myshort Original.
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Content }}
files := `
-- hugo.toml --
disableKinds = ["taxonomy", "term", "rss", "sitemap", "robotsTXT", "404"]
--- layouts/_default/_markup/render-image.html --
+-- layouts/_markup/render-image.html --
{{- with .PageInner.Resources.Get .Destination -}}Image: {{ .RelPermalink }}|{{- end -}}
--- layouts/_default/_markup/render-link.html --
+-- layouts/_markup/render-link.html --
{{- with .PageInner.GetPage .Destination -}}Link: {{ .RelPermalink }}|{{- end -}}
--- layouts/_default/_markup/render-heading.html --
+-- layouts/_markup/render-heading.html --
Heading: {{ .PageInner.Title }}: {{ .PlainText }}|
--- layouts/_default/_markup/render-codeblock.html --
+-- layouts/_markup/render-codeblock.html --
CodeBlock: {{ .PageInner.Title }}: {{ .Type }}|
--- layouts/_default/list.html --
+-- layouts/list.html --
Content:{{ .Content }}|
Fragments: {{ with .Fragments }}{{.Identifiers }}{{ end }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
Content:{{ .Content }}|
--- layouts/shortcodes/include.html --
+-- layouts/_shortcodes/include.html --
{{ with site.GetPage (.Get 0) }}
{{ .RenderShortcodes }}
{{ end }}
title: "p2"
---
Hello <b>world</b>. Some **bold** text. Some Unicode: 神真美好.
--- layouts/shortcodes/include.html --
+-- layouts/_shortcodes/include.html --
{{ with site.GetPage (.Get 0) }}
<div>{{ .RenderShortcodes }}</div>
{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
§§§ php
code_p3
§§§
--- layouts/shortcodes/include.html --
+-- layouts/_shortcodes/include.html --
{{ with site.GetPage (.Get 0) -}}
{{ .RenderShortcodes -}}
{{ end -}}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
--- layouts/_default/_markup/render-codeblock.html --
+-- layouts/_markup/render-codeblock.html --
<code>{{ .Inner | safeHTML }}</code>
`
### p2-h1
This is some **markup**.
--- layouts/shortcodes/include.html --
+-- layouts/_shortcodes/include.html --
{{ $p := site.GetPage (.Get 0) -}}
{{ $p.RenderShortcodes -}}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
b := TestRunning(t, files)
files := `
-- hugo.toml --
disableKinds = ['section','rss','sitemap','taxonomy','term']
--- layouts/_default/home.html --
+-- layouts/home.html --
{{ .Content }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
--- layouts/shortcodes/include.html --
+-- layouts/_shortcodes/include.html --
{{ with site.GetPage (.Get 0) }}
{{ .RenderShortcodes }}
{{ end }}
files := `
-- hugo.toml --
baseURL = "http://example.com/"
--- layouts/index.html --
+-- layouts/home.html --
{{ $p := site.GetPage "p1.md" }}
{{ $optBlock := dict "display" "block" }}
{{ $optOrg := dict "markup" "org" }}
RSTART:{{ "**Bold Block Markdown**" | $p.RenderString $optBlock }}:REND
RSTART:{{ "/italic org mode/" | $p.RenderString $optOrg }}:REND
RSTART:{{ "## Header2" | $p.RenderString }}:REND
--- layouts/_default/_markup/render-heading.html --
+-- layouts/_markup/render-heading.html --
Hook Heading: {{ .Level }}
-- content/p1.md --
---
files := `
-- hugo.toml --
baseURL = "http://example.com/"
--- layouts/index.html --
+-- layouts/home.html --
{{ .RenderString "**Hello**" }}
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .RenderString "**Hello**" }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .RenderString "**Hello**" }}
-- content/mysection/p1.md --
FOO
files := `
-- hugo.toml --
disableKinds = ["page", "section", "taxonomy", "term"]
--- layouts/index.html --
+-- layouts/home.html --
{{ .RenderString "**Hello**" }}
-- content/p1.md --
`
title: "P1"
---
## First
--- layouts/shortcodes/mark1.md --
+-- layouts/_shortcodes/mark1.md --
{{ .Inner }}
--- layouts/shortcodes/mark2.md --
+-- layouts/_shortcodes/mark2.md --
1. Item Mark2 1
1. Item Mark2 2
1. Item Mark2 2-1
1. Item Mark2 3
--- layouts/shortcodes/myhthml.html --
+-- layouts/_shortcodes/myhthml.html --
Title: {{ .Page.Title }}
TableOfContents: {{ .Page.TableOfContents }}
Page Type: {{ printf "%T" .Page }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .RenderString "Markdown: {{% mark2 %}}|HTML: {{< myhthml >}}|Inline: {{< foo.inline >}}{{ site.Title }}{{< /foo.inline >}}|" }}
HasShortcode: mark2:{{ .HasShortcode "mark2" }}:true
HasShortcode: foo:{{ .HasShortcode "foo" }}:false
},
).Build()
- b.EditFiles("layouts/shortcodes/myhthml.html", "Edit shortcode").Build()
+ b.EditFiles("layouts/_shortcodes/myhthml.html", "Edit shortcode").Build()
b.AssertFileContent("public/p1/index.html",
`Edit shortcode`,
files := `
-- config.toml --
--- layouts/shortcodes/myshort.html --
+-- layouts/_shortcodes/myshort.html --
Page Kind: {{ .Page.Kind }}
--- layouts/index.html --
+-- layouts/home.html --
Short: {{ .RenderString "{{< myshort >}}" }}
Has myshort: {{ .HasShortcode "myshort" }}
Has other: {{ .HasShortcode "other" }}
{{ not a shortcode
{{< /noop >}}
}
--- layouts/shortcodes/noop.html --
+-- layouts/_shortcodes/noop.html --
{{ .Inner | $.Page.RenderString }}
--- layouts/shortcodes/toc.html --
+-- layouts/_shortcodes/toc.html --
{{ .Page.TableOfContents }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
baseURL = "http://example.com/"
-- assets/images/sunset.jpg --
` + getTestSunset(t) + `
--- layouts/index.html --
+-- layouts/home.html --
{{ $hello := "<h1> Hello World! </h1>" | resources.FromString "hello.html" | fingerprint "sha512" | minify | fingerprint }}
{{ $cssFingerprinted1 := "body { background-color: lightblue; }" | resources.FromString "styles.css" | minify | fingerprint }}
{{ $cssFingerprinted2 := "body { background-color: orange; }" | resources.FromString "styles2.css" | minify | fingerprint }}
---
title: Page2
---
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ $hello := "<h1> Hello World! </h1>" | resources.FromString "hello.html" | minify | fingerprint "md5" | resources.PostProcess }}
HELLO: {{ $hello.RelPermalink }}
--- layouts/index.html --
+-- layouts/home.html --
Start.
{{ $hello := "<h1> Hello World! </h1>" | resources.FromString "hello.html" | minify | fingerprint "md5" | resources.PostProcess }}
.content-navigation
border-color: $color
--- layouts/index.html --
+-- layouts/home.html --
{{ $a := "A" | resources.FromString "a.txt"}}
{{ $b := "B" | resources.FromString "b.txt"}}
{{ $c := "C" | resources.FromString "c.txt"}}
-- assets/jsons/data3.xml --
xml content
-- content/page.md --
--- layouts/index.html --
+-- layouts/home.html --
{{ $jsons := (resources.Match "jsons/*.json") }}
{{ $json := (resources.GetMatch "jsons/*.json") }}
{{ printf "jsonsMatch: %d" (len $jsons) }}
-- assets/xml/data.xml --
<root> <foo> asdfasdf </foo> </root>
-- content/page.md --
--- layouts/index.html --
+-- layouts/home.html --
{{ $xml := resources.Get "xml/data.xml" | minify | fingerprint }}
XML: {{ $xml.Content | safeHTML }}|{{ $xml.RelPermalink }}
`
enableDefault = true
[markup.goldmark.renderHooks.link]
enableDefault = true
--- layouts/_default/_markup/render-image.html --
+-- layouts/_markup/render-image.html --
{{- $u := urls.Parse .Destination -}}
{{- $src := $u.String | relURL -}}
<img srcset="{{ $src }}" src="{{ $src }} 2x">
<img src="{{ $src }}">
{{- /**/ -}}
--- layouts/_default/home.html --
+-- layouts/home.html --
{{ .Content }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}|
--- layouts/_default/rss.xml --
+-- layouts/rss.xml --
{{ with site.GetPage "/s1/p2" }}
{{ .Content | transform.XMLEscape | safeHTML }}
{{ end }}
files := `
-- hugo.toml --
baseURL = "https://example.org"
--- layouts/index.html --
+-- layouts/home.html --
{{ os.Getenv "FOOBAR" }}
`
_, err := TestE(c, files)
files := `
-- hugo.toml --
baseURL = "https://example.org"
--- layouts/index.html --
+-- layouts/home.html --
{{ os.Getenv "HUGO_FOO" }}
`
Test(c, files)
files := `
-- hugo.toml --
baseURL = "https://example.org"
--- layouts/index.html --
+-- layouts/home.html --
{{ $scss := "body { color: #333; }" | resources.FromString "foo.scss" | css.Sass (dict "transpiler" "dartsass") }}
`
Test(c, files)
[security]
[security.exec]
allow="none"
--- layouts/index.html --
+-- layouts/home.html --
{{ $scss := "body { color: #333; }" | resources.FromString "foo.scss" | css.Sass (dict "transpiler" "dartsass") }}
`
_, err := TestE(c, files)
files := fmt.Sprintf(`
-- hugo.toml --
baseURL = "https://example.org"
--- layouts/index.html --
+-- layouts/home.html --
{{ $json := resources.GetRemote "%s/fruits.json" }}{{ $json.Content }}
`, ts.URL)
Test(c, files)
files := fmt.Sprintf(`
-- hugo.toml --
baseURL = "https://example.org"
--- layouts/index.html --
+-- layouts/home.html --
{{ $json := resources.GetRemote "%s/fruits.json" (dict "method" "DELETE" ) }}{{ $json.Content }}
`, ts.URL)
_, err := TestE(c, files)
[security]
[security.http]
urls="none"
--- layouts/index.html --
+-- layouts/home.html --
{{ $json := resources.GetRemote "%s/fruits.json" }}{{ $json.Content }}
`, ts.URL)
_, err := TestE(c, files)
-- hugo.toml --
baseURL = "https://example.org"
[security]
--- layouts/index.html --
+-- layouts/home.html --
{{ $json := resources.GetRemote "%s/fakejson.json" }}{{ $json.Content }}
`, ts.URL)
_, err := TestE(c, files)
[security]
[security.http]
mediaTypes=["application/json"]
--- layouts/index.html --
+-- layouts/home.html --
{{ $json := resources.GetRemote "%s/fakejson.json" }}{{ $json.Content }}
`, ts.URL)
Test(c, files)
output = "rss"
[[segments.docs.excludes]]
output = "json"
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: {{ .Title }}|{{ .RelPermalink }}|
--- layouts/_default/list.html --
+-- layouts/list.html --
List: {{ .Title }}|{{ .RelPermalink }}|
-- content/docs/_index.md --
-- content/docs/section1/_index.md --
files := `
-- hugo.toml --
baseURL = "https://example.org"
--- layouts/index.html --
+-- layouts/home.html --
Page: |{{ index .Site.RegularPages 0 | jsonify }}|
Site: {{ site | jsonify }}
-- content/page.md --
---
title: "My Bundle"
---
--- layouts/_default/list.html --
+-- layouts/list.html --
Kind: {{ .Kind }}|RelPermalink: {{ .RelPermalink }}|SectionsPath: {{ .SectionsPath }}|SectionsEntries: {{ .SectionsEntries }}|Len: {{ len .SectionsEntries }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
Kind: {{ .Kind }}|RelPermalink: {{ .RelPermalink }}|SectionsPath: {{ .SectionsPath }}|SectionsEntries: {{ .SectionsEntries }}|Len: {{ len .SectionsEntries }}|
`
-- content/docs/logs/_index.md --
-- content/docs/logs/sdk.md --
-- content/docs/logs/sdk_exporters/stdout.md --
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .RelPermalink }}|{{ with .Parent}}{{ .RelPermalink }}{{ end }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .RelPermalink }}|{{ with .Parent}}{{ .RelPermalink }}{{ end }}|
`
---
date: 2023-04-01
---
--- layouts/index.html --
+-- layouts/home.html --
site.Lastmod: {{ .Site.Lastmod.Format "2006-01-02" }}
home.Lastmod: {{ site.Home.Lastmod.Format "2006-01-02" }}
t.Parallel()
basefiles := `
--- layouts/index.html --
+-- layouts/home.html --
Home Sweet {{ if.IsHome }}Home{{ end }}.
--- layouts/_default/single.html --
+-- layouts/single.html --
{{.Content}}{{ if.IsHome }}This is not home!{{ end }}
-- layouts/404.html --
Page Not Found.{{ if.IsHome }}This is not home!{{ end }}
[params]
mainSections=["a", "b"]
-- content/mysect/page1.md --
--- layouts/index.html --
+-- layouts/home.html --
{{/* Behaviour before Hugo 0.112.0. */}}
MainSections Params: {{ site.Params.mainSections }}|
MainSections Site method: {{ site.MainSections }}|
[params.sub]
mainSections=["c", "d"]
-- content/mysect/page1.md --
--- layouts/index.html --
+-- layouts/home.html --
{{/* Behaviour before Hugo 0.112.0. */}}
MainSections Params: {{ site.Params.mainSections }}|
MainSections Param sub: {{ site.Params.sub.mainSections }}|
-- config.toml --
disableKinds = ['RSS','sitemap','taxonomy','term']
-- content/mysect/page1.md --
--- layouts/index.html --
+-- layouts/home.html --
MainSections Params: {{ site.Params.mainSections }}|
MainSections Site method: {{ site.MainSections }}|
---
title: ca
---
--- layouts/index.html --
+-- layouts/home.html --
Home
--- layouts/_default/single.html --
+-- layouts/single.html --
Content: {{ .Content }}
`
[build]
writeStats = true
--- layouts/index.html --
+-- layouts/home.html --
<div id="el1" class="a b c">Foo</div>
files := `
-- hugo.toml --
` + writeStatsConfig + `
--- layouts/_default/list.html --
+-- layouts/list.html --
<div id="myid" class="myclass">Foo</div>
`
-- hugo.toml --
-- content/withfile/_index.md --
-- content/withoutfile/p1.md --
--- layouts/_default/list.html --
+-- layouts/list.html --
SectionsEntries: {{ .SectionsEntries }}
files := `
-- hugo.toml --
disableKinds = ['home','rss','section','taxonomy','term']
--- layouts/_default/single.html --
+-- layouts/single.html --
layouts/_default/single.html
-- layouts/sitemap/single.html --
layouts/sitemap/single.html
---
title: "This is S3s"
---
--- layouts/_default/list.html --
+-- layouts/list.html --
Taxonomy List Page 1|{{ .Title }}|Hello|{{ .Permalink }}|
--- layouts/_default/terms.html --
-Taxonomy Term Page 1|{{ .Title }}|Hello|{{ .Permalink }}|
+-- layouts/taxonomy.html --
+Taxonomy Page 1|{{ .Title }}|Hello|{{ .Permalink }}|
`
b := Test(t, files)
b.AssertFileContent("public/t1/t2/t3s/t4/t5/index.html", "Taxonomy List Page 1|This is T5|Hello|https://example.com/t1/t2/t3s/t4/t5/|")
b.AssertFileContent("public/t1/t2/t3s/t4/t5/t6/index.html", "Taxonomy List Page 1|t4/t5/t6|Hello|https://example.com/t1/t2/t3s/t4/t5/t6/|")
- b.AssertFileContent("public/news/categories/index.html", "Taxonomy Term Page 1|categories|Hello|https://example.com/news/categories/|")
- b.AssertFileContent("public/t1/t2/t3s/index.html", "Taxonomy Term Page 1|t3s|Hello|https://example.com/t1/t2/t3s/|")
- b.AssertFileContent("public/s1/s2/s3s/index.html", "Taxonomy Term Page 1|This is S3s|Hello|https://example.com/s1/s2/s3s/|")
+ b.AssertFileContent("public/news/categories/index.html", "Taxonomy Page 1|categories|Hello|https://example.com/news/categories/|")
+ b.AssertFileContent("public/t1/t2/t3s/index.html", "Taxonomy Page 1|t3s|Hello|https://example.com/t1/t2/t3s/|")
+ b.AssertFileContent("public/s1/s2/s3s/index.html", "Taxonomy Page 1|This is S3s|Hello|https://example.com/s1/s2/s3s/|")
}
// https://github.com/gohugoio/hugo/issues/5719
files := `
-- hugo.toml --
baseURL = "http://example.com"
--- layouts/index.html --
+-- layouts/home.html --
<h1>Tags</h1>
<ul>
{{ range .Site.Taxonomies.tags }}
<li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
{{ end }}
</ul>
--- layouts/_default/terms.html --
+-- layouts/taxonomy.html --
<h1>Terms</h1>
<ul>
{{ range .Data.Terms.Alphabetical }}
files := `
-- hugo.toml --
baseURL = "http://example.com/"
--- layouts/_default/list.html --
+-- layouts/list.html --
List page.
-- content/draft.md --
---
---
Content.
--- layouts/index.html --
+-- layouts/home.html --
{{ range .Site.Pages }}
{{ .RelPermalink }}|{{ .Title }}|{{ .WordCount }}|{{ .Content }}|
{{ end }}
---
Content.
--- layouts/index.html --
+-- layouts/home.html --
NO HOME FOR YOU
`
files := `
-- hugo.toml --
baseURL = "http://example.com"
--- layouts/_default/list.html --
+-- layouts/list.html --
List {{ .Title }}:
{{ range .Resources }}
Resource: {{ .RelPermalink }}|{{ .MediaType }}
files := `
-- hugo.toml --
disableLiveReload = true
--- layouts/index.html --
+-- layouts/home.html --
{{ $cats := .Site.Taxonomies.categories.cats }}
{{ if $cats }}
Len cats: {{ len $cats }}
files := `
-- hugo.toml --
baseURL = "http://example.com"
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ template "print-taxo" "categories.cats" }}
{{ template "print-taxo" "categories.funny" }}
files := `
-- hugo.toml --
baseURL = "http://example.com"
--- layouts/index.html --
+-- layouts/home.html --
{{ $home := site.Home }}
{{ $section := site.GetPage "section" }}
{{ $categories := site.GetPage "categories" }}
abcdef = "abcdefs"
abcdefg = "abcdefgs"
abcdefghi = "abcdefghis"
--- layouts/index.html --
+-- layouts/home.html --
{{ range site.Pages }}Page: {{ template "print-page" . }}
{{ end }}
{{ $abc := site.GetPage "abcdefgs/abc" }}
func TestTaxonomiesWeightSort(t *testing.T) {
files := `
--- layouts/index.html --
+-- layouts/home.html --
{{ $a := site.GetPage "tags/a"}}
:{{ range $a.Pages }}{{ .RelPermalink }}|{{ end }}:
-- content/p1.md --
title = "P1"
tags = ''
+++
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
`
- Neil Gaiman
- Terry Pratchett
---
--- layouts/index.html --
+-- layouts/home.html --
{{- $taxonomy := "book authors" }}
Len Book Authors: {{ len (index .Site.Taxonomies $taxonomy) }}
`
title: "Home"
tags: ["hellO world"]
---
--- layouts/_default/term.html --
+-- layouts/term.html --
{{ .Title }}|{{ .Kind }}|{{ .Data.Singular }}|{{ .Data.Plural }}|{{ .Page.Data.Term }}|
`
t.Parallel()
files := `
--- layouts/_default/list.html --
+-- layouts/list.html --
|{{ .Title }}|
-- content/p1.md --
---
t.Parallel()
files := `
--- layouts/index.html --
+-- layouts/home.html --
|{{ len site.Taxonomies.tags }}|
-- content/p1.md --
---
disableKinds = ['page','rss','section','sitemap']
[taxonomies]
author = 'authors'
--- layouts/_default/list.html --
-{{ .Title }}|
--- layouts/_default/author.terms.html --
-layouts/_default/author.terms.html
+-- layouts/list.html --
+list.html
+-- layouts/authors/taxonomy.html --
+authors/taxonomy.html
-- content/authors/_index.md --
---
title: Authors Page
b.AssertFileExists("public/index.html", true)
b.AssertFileExists("public/authors/index.html", true)
- b.AssertFileContent("public/authors/index.html", "layouts/_default/author.terms.html") // failing test
+ b.AssertFileContent("public/authors/index.html", "authors/taxonomy.html")
}
func TestTaxonomyNestedEmptySectionsIssue12188(t *testing.T) {
weight = 2
[taxonomies]
's1/category' = 's1/category'
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Title }}|
-- content/s1/p1.en.md --
---
disableKinds = ["RSS", "sitemap", "section"]
[taxononomies]
tag = "tags"
--- layouts/_default/list.html --
+-- layouts/list.html --
List.
--- layouts/_default/single.html --
+-- layouts/single.html --
GetTerms.tags: {{ range .GetTerms "tags" }}{{ .Title }}|{{ end }}
-- content/_index.md --
`
files := `
-- hugo.toml --
baseURL = "http://example.com/"
--- layouts/_default/baseof.html --
+-- layouts/baseof.html --
` + bom + `
Base: {{ block "main" . }}base main{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
` + bom + `{{ define "main" }}Hi!?{{ end }}
-- content/page.md --
---
Content.
`, id, id))
- b.WriteString(fmt.Sprintf("-- layouts/_default/layout%d.html --\n", id))
+ b.WriteString(fmt.Sprintf("-- layouts/layout%d.html --\n", id))
b.WriteString(fmt.Sprintf(`
{{ define "main" }}%d{{ end }}
`, id))
- b.WriteString(fmt.Sprintf("-- layouts/_default/layout%d-baseof.html --\n", id))
+ b.WriteString(fmt.Sprintf("-- layouts/layout%d-baseof.html --\n", id))
b.WriteString(fmt.Sprintf(`
Base %d: {{ block "main" . }}FOO{{ end }}
`, id))
files := `
-- hugo.toml --
baseURL = "http://example.com/"
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ define "main" }}
Bonjour
{{ end }}
{{ printf "list" }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ printf "single" }}
{{ define "main" }}
Bonjour
baseURL = "http://example.com/"
-- layouts/baseof.html --
Base: {{ block "main" . }}{{ end }}
--- layouts/index.html --
+-- layouts/home.html --
{{/* A comment */}}
{{ define "main" }}
Bonjour
files := `
-- hugo.toml --
baseURL = "http://example.com/"
--- layouts/_default/single.html --
+-- layouts/single.html --
Single: {{ .Title }}
--- layouts/_default/list.html --
+-- layouts/list.html --
List: {{ .Title }}
-- content/_index.md --
---
[languages.fr]
weight = 20
--- layouts/index.html --
+-- layouts/home.html --
{{ define "main" }}Main Home En{{ end }}
--- layouts/index.fr.html --
+-- layouts/home.fr.html --
{{ define "main" }}Main Home Fr{{ end }}
-- layouts/baseof.html --
Baseof en: {{ block "main" . }}main block{{ end }}
Baseof fr: {{ block "main" . }}main block{{ end }}
-- layouts/mysection/baseof.html --
Baseof mysection: {{ block "main" . }}mysection block{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ define "main" }}Main Default Single{{ end }}
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ define "main" }}Main Default List{{ end }}
-- content/mysection/p1.md --
---
[languages.fr]
weight = 20
--- layouts/index.html --
+-- layouts/home.html --
Site: {{ site.Language.Lang }} / {{ .Site.Language.Lang }} / {{ site.BaseURL }}
Sites: {{ site.Sites.Default.Home.Language.Lang }}
Hugo: {{ hugo.Generator }}
--- layouts/index.fr.html --
+-- layouts/home.fr.html --
Site: {{ site.Language.Lang }} / {{ .Site.Language.Lang }} / {{ site.BaseURL }}
Sites: {{ site.Sites.Default.Home.Language.Lang }}
Hugo: {{ hugo.Generator }}
files := `
-- hugo.toml --
baseURL = "http://example.com/"
--- layouts/partials/add42.tpl --
+-- layouts/_partials/add42.tpl --
{{ $v := add . 42 }}
{{ return $v }}
--- layouts/partials/dollarContext.tpl --
+-- layouts/_partials/dollarContext.tpl --
{{ $v := add $ 42 }}
{{ return $v }}
--- layouts/partials/dict.tpl --
+-- layouts/_partials/dict.tpl --
{{ $v := add $.adder 42 }}
{{ return $v }}
--- layouts/partials/complex.tpl --
+-- layouts/_partials/complex.tpl --
{{ return add . 42 }}
--- layouts/partials/hello.tpl --
+-- layouts/_partials/hello.tpl --
{{ $v := printf "hello %s" . }}
{{ return $v }}
--- layouts/index.html --
+-- layouts/home.html --
Test Partials With Return Values:
add42: 50: {{ partial "add42.tpl" 8 }}
files := `
-- hugo.toml --
baseURL = "http://example.com/"
--- layouts/index.html --
+-- layouts/home.html --
X{{ partial "retval" dict }}X
X{{ partial "retval" slice }}X
X{{ partial "retval" "" }}X
files := `
-- hugo.toml --
baseURL = "http://example.com/"
--- layouts/index.html --
+-- layouts/home.html --
{{ $key1 := (dict "a" "av" ) }}
{{ $key2 := (dict "a" "av2" ) }}
Partial cached1: {{ partialCached "p1" "input1" $key1 }}
Partial cached2: {{ partialCached "p1" "input2" $key1 }}
Partial cached3: {{ partialCached "p1" "input3" $key2 }}
--- layouts/partials/p1.html --
+-- layouts/_partials/p1.html --
partial: {{ . }}
`
b := NewIntegrationTestBuilder(
files := `
-- hugo.toml --
baseURL = "http://example.com/"
--- layouts/index.html --
+-- layouts/home.html --
{{ $p := index site.RegularPages 0 }}
{{ $zero := $p.ExpiryDate }}
{{ $notZero := time.Now }}
files := `
-- hugo.toml --
baseURL = "http://example.com/"
--- layouts/index.html --
+-- layouts/home.html --
{{ $title := "a & b" }}
<script type="application/ld+json">{"@type":"WebPage","headline":"{{$title}}"}</script>
-- hugo.toml --
baseURL = "http://example.com/"
-- content/p1.md --
--- layouts/index.html --
+-- layouts/home.html --
{{ $p1 := partial "p1" . }}
{{ $p2 := partial "p2" . }}
-- layouts/baseof.html --
{{ $p3 := partial "p3" . }}P3: {{ $p3 }}
{{ block "main" . }}{{ end }}{{ define "partials/p3" }}Inline: p3{{ end }}
--- layouts/index.html --
+-- layouts/home.html --
{{ define "main" }}
{{ $p1 := partial "p1" . }}
title: P
---
Content
--- layouts/_default/baseof.html --
+-- layouts/baseof.html --
::Header Start:{{ block "header" . }}{{ end }}:Header End:
::{{ block "main" . }}Main{{ end }}::
--- layouts/index.html --
+-- layouts/home.html --
{{ define "header" }}
Home Header
{{ end }}
{{ define "main" }}
This is home main
{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ define "main" }}
This is single main
{{ end }}
-- hugo.toml --
baseURL = "http://example.com/"
-- content/p1.md --
--- layouts/index.html --
+-- layouts/home.html --
{{ $b := slice " a " " b " " c" }}
{{ $a := apply $b "strings.Trim" "." " " }}
a: {{ $a }}
files := `
-- hugo.toml --
baseURL = "https://example.org"
--- layouts/index.html --
+-- layouts/home.html --
{{ template "_internal/google_analytics_async.html" . }}
-- layouts/_internal/google_analytics_async.html --
Overridden.
console.log("Hello, Runner!");
-- node_modules/mylib/index.js --
console.log("Hello, My Lib!");
--- layouts/shortcodes/hdx.html --
+-- layouts/_shortcodes/hdx.html --
{{ $path := .Get "r" }}
{{ $r := or (.Page.Resources.Get $path) (resources.Get $path) }}
{{ $batch := (js.Batch "mybatch") }}
{{ end }}
{{ end }}
hdx-instance: {{ $scriptID }}: {{ $instanceID }}|
--- layouts/_default/baseof.html --
+-- layouts/baseof.html --
Base.
{{ $batch := (js.Batch "mybatch") }}
{{ with $batch.Config }}
{{ end }}
{{ block "main" . }}Main{{ end }}
End.
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ define "main" }}
==> Single Template Content: {{ .Content }}$
{{ $batch := (js.Batch "mybatch") }}
{{ end }}
{{ end }}
{{ end }}
--- layouts/index.html --
+-- layouts/home.html --
{{ define "main" }}
Home.
{{ end }}
files := jsBatchFilesTemplate
b := hugolib.TestRunning(t, files, hugolib.TestOptWithOSFs())
b.AssertFileContent("public/mybatch/mygroup.js", "Instance 1")
- b.EditFileReplaceAll("layouts/_default/single.html", "Instance 1", "Instance 1 Edit").Build()
+ b.EditFileReplaceAll("layouts/single.html", "Instance 1", "Instance 1 Edit").Build()
b.AssertFileContent("public/mybatch/mygroup.js", "Instance 1 Edit")
}
files := jsBatchFilesTemplate
b := hugolib.TestRunning(t, files, hugolib.TestOptWithOSFs())
b.AssertFileContent("public/mybatch/mygroup.js", "param-p1-main")
- b.EditFileReplaceAll("layouts/_default/single.html", "param-p1-main", "param-p1-main-edited").Build()
+ b.EditFileReplaceAll("layouts/single.html", "param-p1-main", "param-p1-main-edited").Build()
b.AssertFileContent("public/mybatch/mygroup.js", "param-p1-main-edited")
}
console.log("Hello, Runner!");
-- node_modules/mylib/index.js --
console.log("Hello, My Lib!");
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ $batch := (js.Batch "mybatch") }}
{{ with $batch.Config }}
console.log("Hello, Runner!");
-- node_modules/mylib/index.js --
console.log("Hello, My Lib!");
--- layouts/shortcodes/hdx.html --
+-- layouts/_shortcodes/hdx.html --
{{ $path := .Get "r" }}
{{ $r := or (.Page.Resources.Get $path) (resources.Get $path) }}
{{ $batch := (js.Batch "mybatch") }}
{{ end }}
{{ end }}
hdx-instance: {{ $scriptID }}: {{ $instanceID }}|
--- layouts/_default/baseof.html --
+-- layouts/baseof.html --
Base.
{{ $batch := (js.Batch "mybatch") }}
{{ with $batch.Config }}
{{ end }}
{{ block "main" . }}Main{{ end }}
End.
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ define "main" }}
==> Single Template Content: {{ .Content }}$
{{ $batch := (js.Batch "mybatch") }}
{{ end }}
{{ end }}
{{ end }}
--- layouts/index.html --
+-- layouts/home.html --
{{ define "main" }}
Home.
{{ end }}
export default function Main3() {};
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
{{ $r := .Resources.GetMatch "*.jsx" }}
{{ .SetOptions (dict "title" "r2 instance 1")}}
{{ end }}
{{ end }}
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ with (templates.Defer (dict "key" "global")) }}
{{ $batch := (js.Batch "mybundle") }}
other = 'l2theme'
[l3]
other = 'l3theme'
--- layouts/index.html --
+-- layouts/home.html --
l1: {{ i18n "l1" }}|l2: {{ i18n "l2" }}|l3: {{ i18n "l3" }}
`
-- i18n/en.toml --
[a]
other = 'Reading time: {{ .ReadingTime }}'
--- layouts/index.html --
+-- layouts/home.html --
i18n: {{ i18n "a" . }}|
`
cat = 'gato'
-- i18n/fr.toml --
# this file intentionally empty
--- layouts/index.html --
+-- layouts/home.html --
{{ .Title }}_{{ T "cat" }}
-- content/_index.fr.md --
---
)
func TestCommands(t *testing.T) {
+ // These are somewhat flakey and takes some time,
+ // so usefule to have a way to skip them when developing.
+ const skipEnv = "HUGOTESTING_SKIP_COMMANDS"
+ if os.Getenv(skipEnv) != "" {
+ t.Skipf("skip because %s set in env", skipEnv)
+ }
p := commonTestScriptsParam
p.Dir = "testscripts/commands"
testscript.Run(t, p)
[markup.goldmark.parser.attribute]
block = true
title = true
--- layouts/_default/_markup/render-blockquote.html --
+-- layouts/_markup/render-blockquote.html --
Blockquote: |{{ .Text }}|{{ .Type }}|
--- layouts/_default/_markup/render-blockquote-alert.html --
+-- layouts/_markup/render-blockquote-alert.html --
{{ $text := .Text }}
Blockquote Alert: |{{ $text }}|{{ .Type }}|
Blockquote Alert Attributes: |{{ $text }}|{{ .Attributes }}|
{{ if .Attributes.showpos }}
Blockquote Alert Position: |{{ $text }}|{{ .Position | safeHTML }}|
{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
Content: {{ .Content }}
-- content/p1.md --
---
---
>
--- layouts/_default/single.html --
+-- layouts/single.html --
Content: {{ .Content }}
`
> > [!important] Yes!, they can.
> > > [!tip] You can even use multiple layers of nesting.
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
--- layouts/_default/_markup/render-blockquote.html --
+-- layouts/_markup/render-blockquote.html --
AlertType: {{ .AlertType }}|AlertTitle: {{ .AlertTitle }}|AlertSign: {{ .AlertSign | safeHTML }}|Text: {{ .Text }}|
`
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
--- layouts/_default/_markup/render-blockquote.html --
+-- layouts/_markup/render-blockquote.html --
AlertType: {{ .AlertType }}|AlertTitle: {{ .AlertTitle }}|Text: {{ .Text }}|
-- content/_index.md --
---
noClasses = false
style = 'monokai'
tabWidth = 4
--- layouts/_default/_markup/render-codeblock-goat.html --
+-- layouts/_markup/render-codeblock-goat.html --
{{ $diagram := diagrams.Goat .Inner }}
Goat SVG:{{ substr $diagram.Wrapped 0 100 | safeHTML }} }}|
Goat Attribute: {{ .Attributes.width}}|
--- layouts/_default/_markup/render-codeblock-go.html --
+-- layouts/_markup/render-codeblock-go.html --
Go Code: {{ .Inner | safeHTML }}|
Go Language: {{ .Type }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
-- content/p1.md --
---
noClasses = false
style = 'monokai'
tabWidth = 4
--- layouts/_default/_markup/render-codeblock.html --
+-- layouts/_markup/render-codeblock.html --
{{ $result := transform.HighlightCodeBlock . }}
Inner: |{{ $result.Inner | safeHTML }}|
Wrapped: |{{ $result.Wrapped | safeHTML }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
-- content/p1.md --
---
files := `
-- config.toml --
--- layouts/_default/_markup/render-codeblock.html --
+-- layouts/_markup/render-codeblock.html --
{{ .Position | safeHTML }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
-- content/p1.md --
---
§§§bash
echo "p1";
§§§
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
--- layouts/_default/_markup/render-codeblock.html --
+-- layouts/_markup/render-codeblock.html --
|{{ .Inner | safeHTML }}|
`
§§§
echo "p1";
§§§
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
--- layouts/_default/_markup/render-codeblock.html --
+-- layouts/_markup/render-codeblock.html --
Position: {{ .Position | safeHTML }}
Hello, World!
§§§
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
--- layouts/_default/_markup/render-codeblock.html --
+-- layouts/_markup/render-codeblock.html --
Attributes: {{ .Attributes }}|Type: {{ .Type }}|
`
§§§LANGUAGE {style=monokai}
echo "p1";
§§§
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
--- layouts/_default/_markup/render-codeblock.html --
+-- layouts/_markup/render-codeblock.html --
Attributes: {{ .Attributes }}|Options: {{ .Options }}|
Common
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
Hello, World!
§§§
--- layouts/index.html --
--- layouts/_default/single.html --
+-- layouts/home.html --
+-- layouts/single.html --
{{ .Content }}
--- layouts/_default/_markup/render-codeblock.html --
+-- layouts/_markup/render-codeblock.html --
Attributes: {{ .Attributes }}|Type: {{ .Type }}|
`
~~~bash {id="c" onmouseover="alert('code fence')" LINENOS=true}
foo
~~~
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
title: "p1"
---
## Heading {onclick="alert('renderhook')" data-foo="bar"}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
--- layouts/_default/_markup/render-heading.html --
+-- layouts/_markup/render-heading.html --
<h{{ .Level }}
{{- range $k, $v := .Attributes -}}
{{- printf " %s=%q" $k $v | safeHTMLAttr -}}
title: "p1"
---
## Heading Attribute Which Needs Escaping { class="a < b" }
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
title: "p1"
---
## Heading Attribute Which Needs Escaping { class="Smith & Wesson" }
--- layouts/_default/_markup/render-heading.html --
+-- layouts/_markup/render-heading.html --
plain: |{{- range $k, $v := .Attributes -}}{{ $k }}: {{ $v }}|{{ end }}|
safeHTML: |{{- range $k, $v := .Attributes -}}{{ $k }}: {{ $v | safeHTML }}|{{ end }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
title: "p1"
---
## Hello [Test](https://example.com)
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
--- layouts/_default/_markup/render-heading.html --
+-- layouts/_markup/render-heading.html --
<h{{ .Level }} id="{{ .Anchor | safeURL }}">
{{ .Text }}
<a class="anchor" href="#{{ .Anchor | safeURL }}">#</a>
</h{{ .Level }}>
--- layouts/_default/_markup/render-link.html --
+-- layouts/_markup/render-link.html --
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text }}</a>
`
noClasses = false
style = 'monokai'
tabWidth = 4
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
-- content/p1.md --
---
func BenchmarkRenderHooks(b *testing.B) {
files := `
-- config.toml --
--- layouts/_default/_markup/render-heading.html --
+-- layouts/_markup/render-heading.html --
<h{{ .Level }} id="{{ .Anchor | safeURL }}">
{{ .Text }}
<a class="anchor" href="#{{ .Anchor | safeURL }}">#</a>
</h{{ .Level }}>
--- layouts/_default/_markup/render-link.html --
+-- layouts/_markup/render-link.html --
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text }}</a>
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
noClasses = true
style = 'monokai'
tabWidth = 4
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
b.Run("Hook no higlight", func(b *testing.B) {
files := filesTemplate + `
--- layouts/_default/_markup/render-codeblock.html --
+-- layouts/_markup/render-codeblock.html --
{{ .Inner }}
`
t.Run(renderFunc, func(t *testing.T) {
files := `
-- config.toml --
--- layouts/_default/_markup/render-link.html --
+-- layouts/_markup/render-link.html --
<a href="{{ .Destination | safeURL }}">{{ .Text | RENDERFUNC }}</a>
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
-- content/p1.md --
---
title: "p1"
---

--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
Link http procol: http://www.example.org
Link https procol: https://www.example.org
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
files = strings.ReplaceAll(files, "PROTOCOL", protocol)
if withHook {
- files += `-- layouts/_default/_markup/render-link.html --
+ files += `-- layouts/_markup/render-link.html --
<a href="{{ .Destination | safeURL }}">{{ .Text }}</a>`
}
- This is a list item <!-- Comment: an innocent-looking comment -->
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`

--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
title: "p2"
---
:heavy_check_mark:
--- layouts/shortcodes/include.html --
+-- layouts/_shortcodes/include.html --
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
--- layouts/shortcodes/sc1.html --
+-- layouts/_shortcodes/sc1.html --
sc1_begin|{{ .Inner }}|sc1_end
--- layouts/shortcodes/sc2.html --
+-- layouts/_shortcodes/sc2.html --
sc2_begin|{{ .Inner | .Page.RenderString }}|sc2_end
--- layouts/shortcodes/sc3.html --
+-- layouts/_shortcodes/sc3.html --
sc3_begin|{{ .Inner }}|sc3_end
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
title: "p1"
---
:x:
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
title: "p1"
---
:x:
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
minifyOutput = true
[minify.tdewolff.html]
templateDelims = ["<?php","?>"]
--- layouts/index.html --
+-- layouts/home.html --
<div class="foo">
{{ safeHTML "<?php" }}
echo "hello";
Inline equation that would be mangled by default parser: $a^*=x-b^*$
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
$$a^*=x-b^*$$
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
a^*=x-b^*
%!%
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
enable = false
[markup.goldmark.extensions.extras.superscript]
enable = false
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
-- content/_index.md --
---
title: "p1"
---
<div>Some raw HTML</div>
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
title: "p1"
---
<em>raw HTML</em>
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
--> word.
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
{.b}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
t.Run("With Hook, no wrap", func(t *testing.T) {
files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "false")
- files = files + `-- layouts/_default/_markup/render-image.html --
+ files = files + `-- layouts/_markup/render-image.html --
{{ if .IsBlock }}
<figure class="{{ .Attributes.class }}">
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}|{{ .Ordinal }}" />
t.Run("With Hook, wrap", func(t *testing.T) {
files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "true")
- files = files + `-- layouts/_default/_markup/render-image.html --
+ files = files + `-- layouts/_markup/render-image.html --
{{ if .IsBlock }}
<figure class="{{ .Attributes.class }}">
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" />
## Example [hyperlink](https://example.com/) in a header
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}|Identifiers: {{ .Fragments.Identifiers }}|
`
-- hugo.toml --
[markup.goldmark.parser.attribute]
block = true
--- layouts/_default/single.html --
+-- layouts/single.html --
Content: {{ .Content }}
-- content/p1.md --
---
Some inline LaTeX 2: $a^*=x-b^*$.
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
--- layouts/_default/_markup/render-passthrough-block.html --
+-- layouts/_markup/render-passthrough-block.html --
Passthrough block: {{ .Inner | safeHTML }}|{{ .Type }}|{{ .Ordinal }}:END
--- layouts/_default/_markup/render-passthrough-inline.html --
+-- layouts/_markup/render-passthrough-inline.html --
Passthrough inline: {{ .Inner | safeHTML }}|{{ .Type }}|{{ .Ordinal }}:END
`
| February | $80 |
| March | $420 |
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
--- layouts/_default/_markup/render-table.html --
+-- layouts/_markup/render-table.html --
Attributes: {{ .Attributes }}|
{{ template "print" (dict "what" (printf "table-%d-thead" $.Ordinal) "rows" .THead) }}
{{ template "print" (dict "what" (printf "table-%d-tbody" $.Ordinal) "rows" .TBody) }}
1|2
{id="\"><script>alert()</script>"}
--- layouts/_default/single.html --
+-- layouts/single.html --
Summary: {{ .Summary }}
Content: {{ .Content }}
{{< foo >}}
--- layouts/index.html --
+-- layouts/home.html --
Content: {{ .Content }}
-- layouts/index.xml --
Content: {{ .Content }}
--- layouts/shortcodes/foo.xml --
+-- layouts/_shortcodes/foo.xml --
foo xml
--- layouts/shortcodes/foo.html --
+-- layouts/_shortcodes/foo.html --
foo html
`
[markup.goldmark.renderer]
unsafe = false
xhtml = false
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .TableOfContents }}
-- content/p1.md --
---
[markup.goldmark.renderer]
unsafe = true
xhtml = true
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .TableOfContents }}
-- content/p1.md --
---
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
Content:{{ .Content }}|
--- layouts/_default/_markup/render-heading.html --
+-- layouts/_markup/render-heading.html --
-- content/_index.md --
---
title: home
§§§
--- layouts/_default/_markup/render-codeblock-html.html --
+-- layouts/_markup/render-codeblock-html.html --
{{ $opts := dict "hl_inline" true }}
{{ $result := transform.HighlightCodeBlock . $opts }}
HighlightCodeBlock: Wrapped:{{ $result.Wrapped }}|Inner:{{ $result.Inner }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
§§§go
xəx := 0
§§§
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
`
§§§go
xəx := 0
§§§
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
`
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ range .Fragments.HeadingsMap }}
{{ printf "%s|%d|%s" .ID .Level .Title }}
{{ end }}
files := `
-- hugo.toml --
disableKinds = ['home','section','rss','sitemap','taxonomy','term']
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Fragments.ToHTML .Params.toc.startLevel .Params.toc.endLevel false }}
-- content/json.md --
{
## Common p3, p4, p5
--- layouts/shortcodes/see-also.html --
+-- layouts/_shortcodes/see-also.html --
{{ $p1 := site.GetPage "p1" }}
{{ $p2 := site.GetPage "p2" }}
{{ $p3 := site.GetPage "p3" }}
{{ define "list-related" }}{{ range $i, $e := . }} {{ $i }}: {{ .Title }}: {{ with .HeadingsFiltered}}{{ range $i, $e := .}}h{{ $i }}: {{ .Title }}|{{ .ID }}|{{ end }}{{ end }}::END{{ end }}{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
Content: {{ .Content }}
name = 'pagerefs'
type = 'fragments'
weight = 30
--- layouts/_default/single.html --
+-- layouts/single.html --
Len related: {{ site.RegularPages.Related . | len }}
`
sourcefilename: ../testdata/sunset.jpg
-- assets/gopher.png --
sourcefilename: ../testdata/gopher-hero8.png
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ $sunset := (resources.Get "sunset.jpg").Resize "x300" }}
{{ $sunsetGrayscale := $sunset.Filter (images.Grayscale) }}
-- assets/mask.png --
sourcefilename: ../testdata/mask.png
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ $sunset := resources.Get "sunset.jpg" }}
{{ $mask := resources.Get "mask.png" }}
-- assets/mask.png --
sourcefilename: ../testdata/mask.png
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ $sunset := resources.Get "sunset.jpg" }}
{{ $mask := resources.Get "mask.png" }}
-- assets/sunset.jpg --
sourcefilename: ../testdata/sunset.jpg
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ $sunset := resources.Get "sunset.jpg" }}
{{ $textOpts := dict
sourcefilename: ../testdata/sunset.jpg
-- assets/gopher.png --
sourcefilename: ../testdata/gopher-hero8.png
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ $sunset := resources.Get "sunset.jpg" }}
{{ $sunsetGrayscale := $sunset.Filter (images.Grayscale) }}
-- assets/gopher.png --
sourcefilename: ../testdata/gopher-hero8.png
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ $sunset := resources.Get "sunset.jpg" }}
{{ $gopher := resources.Get "gopher.png" }}
-- hugo.toml --
-- assets/rotate270.jpg --
sourcefilename: ../testdata/exif/orientation6.jpg
--- layouts/index.html --
+-- layouts/home.html --
{{ $img := resources.Get "rotate270.jpg" }}
W/H original: {{ $img.Width }}/{{ $img.Height }}
{{ $rotated := $img.Filter images.AutoOrient }}
-- hugo.toml --
-- assets/rotate270.jpg --
sourcefilename: ../testdata/exif/orientation6.jpg
--- layouts/index.html --
+-- layouts/home.html --
{{ $img := resources.Get "rotate270.jpg" }}
{{ $orientation := $img.Exif.Tags.Orientation }}
Orientation: {{ $orientation }}|eq 6: {{ eq $orientation 6 }}|Type: {{ printf "%T" $orientation }}|
title: "Post 2"
date: "2020-02-01"
---
--- layouts/index.html --
+-- layouts/home.html --
{{ range $k, $v := site.RegularPages.GroupByDate "January, 2006" }}{{ $k }}|{{ $v.Key }}|{{ $v.Pages }}{{ end }}
`
date: "2020-01-01"
param1: "éclair"
---
--- layouts/index.html --
+-- layouts/home.html --
ByTitle: {{ range site.RegularPages.ByTitle }}{{ .Title }}|{{ end }}
ByLinkTitle: {{ range site.RegularPages.ByLinkTitle }}{{ .Title }}|{{ end }}
ByParam: {{ range site.RegularPages.ByParam "param1" }}{{ .Params.param1 }}|{{ end }}
slug: "d"
---
D
--- layouts/_default/single.html --
+-- layouts/single.html --
RelPermalink: {{ .RelPermalink }}
`
date: "2020-01-01"
---
{{% foo %}}
--- layouts/shortcodes/foo.html --
+-- layouts/_shortcodes/foo.html --
Two *words*.
{{/* Test that markup scope is set in all relevant constructs. */}}
{{ if eq hugo.Context.MarkupScope "foo" }}
### Heading 2
Exercitation quis est consectetur occaecat nostrud. Ullamco aute mollit aliqua est amet. Exercitation ullamco consectetur dolor labore et non irure eu cillum Lorem.
{{ end }}
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ .Content }}
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
Page.ContentWithoutSummmary: {{ .ContentWithoutSummary }}|
{{ template "render-scope" (dict "page" . "scope" "main") }}
{{< foo >}}
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ with site.GetPage "p1" }}
{{ with .Markup "home" }}
{{ .Render.Content }}
{{ end }}
{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
{{ with .Markup }}
{{ with .Render }}
{{ .Content }}
{{ end }}
{{ end }}
--- layouts/_default/_markup/render-heading.html --
+-- layouts/_markup/render-heading.html --
Render heading: title: {{ .Text}} scope: {{ hugo.Context.MarkupScope }}|
--- layouts/shortcodes/foo.html --
+-- layouts/_shortcodes/foo.html --
Foo scope: {{ hugo.Context.MarkupScope }}|
--- layouts/shortcodes/includerendershortcodes.html --
+-- layouts/_shortcodes/includerendershortcodes.html --
{{ $p := site.GetPage (.Get 0) }}
includerendershortcodes: {{ hugo.Context.MarkupScope }}|{{ $p.Markup.RenderShortcodes }}|
--- layouts/shortcodes/includecontent.html --
+-- layouts/_shortcodes/includecontent.html --
{{ $p := site.GetPage (.Get 0) }}
includecontent: {{ hugo.Context.MarkupScope }}|{{ $p.Markup.Render.Content }}|
summary: "This is summary in front matter."
---
This is content.
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
Page.Summary: {{ .Summary }}|
{{ with .Markup.Render }}
This is summary.
<!--more-->
This is content.
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
Page.Summary: {{ .Summary }}|
{{ with .Markup.Render }}
This is summary.
<!--more-->
This is content.
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
Page.Summary: {{ .Summary }}|
{{ with .Markup.Render }}
title: p1
date: 2024-03-13T06:00:00
---
--- layouts/_default/single.html --
+-- layouts/single.html --
Date: {{ .Date }}
Lastmod: {{ .Lastmod }}
Eq: {{ eq .Date .Lastmod }}
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
-- content/_index.md --
FRONT_MATTER
--- layouts/index.html --
+-- layouts/home.html --
{{ .Date.UTC.Format "2006-01-02" }}
--
`
title: "Page 3"
weight: 30
---
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|Next: {{ with .Next}}{{ .Title}}{{ end }}|Prev: {{ with .Prev}}{{ .Title}}{{ end }}|NextInSection: {{ with .NextInSection}}{{ .Title}}{{ end }}|PrevInSection: {{ with .PrevInSection}}{{ .Title}}{{ end }}|
`
disableKinds = ['section','rss','sitemap','taxonomy']
[permalinks]
s1 = '/:section/:slug'
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ range site.Pages }}{{ .RelPermalink }}|{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
-- content/s1/p1.md --
---
t.Parallel()
files := `
--- layouts/_default/list.html --
+-- layouts/list.html --
List|{{ .Kind }}|{{ .RelPermalink }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
Single|{{ .Kind }}|{{ .RelPermalink }}|
-- hugo.toml --
[taxonomies]
t.Parallel()
files := `
--- layouts/_default/list.html --
+-- layouts/list.html --
List|{{ .Kind }}|{{ .RelPermalink }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
Single|{{ .Kind }}|{{ .RelPermalink }}|
-- hugo.toml --
[permalinks]
---
title: Book 1
---
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
--- layouts/_default/list.html --
+-- layouts/list.html --
List.
`
---
title: Book One
---
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
--- layouts/_default/list.html --
+-- layouts/list.html --
List.
`
t.Parallel()
files := `
--- layouts/_default/list.html --
+-- layouts/list.html --
List|{{ .Kind }}|{{ .RelPermalink }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
Single|{{ .Kind }}|{{ .RelPermalink }}|
-- hugo.toml --
-- content/cooking/delicious-recipes/_index.md --
---
title: p2
---
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Title }}
`
{{ $.AddPage (dict "kind" "page" "path" "a/b/contentbasename2" "slug" "myslug" "title" "My A Page With Slug") }}
{{ $.AddPage (dict "kind" "section" "path" "b/c" "title" "My B Section") }}
{{ $.AddPage (dict "kind" "page" "path" "b/c/contentbasename3" "title" "My B Page No Slug") }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|{{ .RelPermalink }}|{{ .Kind }}|
`
b := hugolib.Test(t, files)
title: "C2"
slug: "c2slug"
---
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|{{ .RelPermalink }}|{{ .Kind }}|
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Title }}|{{ .RelPermalink }}|{{ .Kind }}|
`
b := hugolib.Test(t, files)
---
title: Some Page
---
--- layouts/_default/list.html --
+-- layouts/list.html --
List|{{ .Kind }}|{{ .RelPermalink }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
Single|{{ .Kind }}|{{ .RelPermalink }}|
`
[languages.de]
languageName = 'Deutsch'
weight = 2
--- layouts/index.html --
+-- layouts/home.html --
{{ .Site.Sites.Default.Language.LanguageName }}
`
disableKinds = ['rss','sitemap']
[taxonomies]
author = 'authors'
--- layouts/_default/home.html --
+-- layouts/home.html --
John Smith count: {{ site.Taxonomies.authors.Count "John Smith" }}
Robert Jones count: {{ (site.Taxonomies.authors.Get "Robert Jones").Pages.Len }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Title }}|
-- content/p1.md --
---
title: p1
tags: [tag-a]
---
--- layouts/_default/list.html --
+-- layouts/list.html --
{{- with site.Taxonomies.tags.Page }}{{ .RelPermalink }}{{ end }}|
{{- with site.Taxonomies.categories.Page }}{{ .RelPermalink }}{{ end }}|
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
`
Text 1.
-- content/mybundle/sub/txt2.txt --
Text 1.
--- layouts/index.html --
+-- layouts/home.html --
{{ $mybundle := site.GetPage "mybundle" }}
{{ $subResources := resources.Match "/text/sub/*.*" }}
{{ $subResourcesMount := $subResources.Mount "/text/sub" "/newroot" }}
Text 1.
-- content/mybundle/foo/txt2.txt --
Text 2.
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
{{ $mybundle := site.GetPage "mybundle" }}
Resources:{{ range $mybundle.Resources }}Name: {{ .Name }}|{{ end }}$
[security.http]
methods = ['(?i)GET|POST|HEAD']
urls = ['.*gohugo\.io.*']
--- layouts/index.html --
+-- layouts/home.html --
{{ $url := "https://gohugo.io/img/hugo.png" }}
{{ $opts := dict "method" "head" }}
{{ with try (resources.GetRemote $url $opts) }}
[security.http]
methods = ['(?i)GET|POST|HEAD']
urls = ['.*gohugo\.io.*']
--- layouts/index.html --
+-- layouts/home.html --
{{ $url := "https://gohugo.io/img/hugo.png" }}
{{ $opts := dict "method" "head" "responseHeaders" (slice "X-Frame-Options" "Server") }}
{{ with try (resources.GetRemote $url $opts) }}
[security.http]
urls = ['.*']
mediaTypes = ['text/plain']
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ $url := printf "%s%s" "URL" .RelPermalink}}
{{ $opts := dict }}
{{ with try (resources.GetRemote $url $opts) }}
[security]
[security.exec]
allow = ['^npx$', '^babel$']
--- layouts/index.html --
+-- layouts/home.html --
{{ $options := dict "noComments" true }}
{{ $transpiled := resources.Get "js/main.js" | babel -}}
Transpiled: {{ $transpiled.Content | safeJS }}
-- i18n/fr.yaml --
hello:
other: "Bonjour"
--- layouts/index.html --
+-- layouts/home.html --
{{ $options := dict "inlineImports" true }}
{{ $styles := resources.Get "css/styles.css" | css.PostCSS $options }}
Styles RelPermalink: {{ $styles.RelPermalink }}
--color-neon-lime: oklch(91.5% 0.258 129);
--color-neon-cyan: oklch(91.3% 0.139 195.8);
}
--- layouts/index.html --
+-- layouts/home.html --
{{ $css := resources.Get "css/styles.css" | css.TailwindCSS }}
CSS: {{ $css.Content | safeCSS }}|
`
export function hello3() {
return 'efgh';
}
--- layouts/index.html --
+-- layouts/home.html --
{{ $js := resources.Get "js/main.js" | js.Build }}
JS Content:{{ $js.Content }}:End:
-- i18n/fr.yaml --
hello:
other: "Bonjour"
--- layouts/index.html --
+-- layouts/home.html --
{{ $options := dict "minify" false "externals" (slice "react" "react-dom") "sourcemap" "linked" }}
{{ $js := resources.Get "js/main.js" | js.Build $options }}
JS: {{ template "print" $js }}
export function hello3() {
return 'efgh';
}
--- layouts/index.html --
+-- layouts/home.html --
{{ $js := resources.Get "js/main.js" | js.Build }}
JS Content:{{ $js.Content }}:End:
import 'imp1/index.js';
import 'imp2/index.js';
import 'imp3/foo.js';
--- layouts/index.html --
+-- layouts/home.html --
{{ $js := resources.Get "js/main.js" | js.Build }}
{{ $js.RelPermalink }}
`
-- assets/js/utils/util2.js --
//! License util2 */
console.log("Hello 2");
--- layouts/index.html --
+-- layouts/home.html --
{{ $js := resources.Get "js/main.js" | js.Build (dict "minify" false) }}
{{ $js.RelPermalink }}
`
function addFoo(target: any) {target.prototype.foo = 'bar'}
@addFoo
class A {}
--- layouts/index.html --
+-- layouts/home.html --
{{ $opts := dict "target" "es2020" "targetPath" "js/main.js" }}
{{ (resources.Get "ts/main.ts" | js.Build $opts).Publish }}
`
hello1();
hello2();
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ $js := resources.Get "js/main.js" | js.Build (dict "externals" (slice "./util1.js")) }}
{{ $js.Publish }}
-- assets/js/test.js --
new Date(2002, 04, 11)
-- config.toml --
--- layouts/index.html --
+-- layouts/home.html --
{{ $js := resources.Get "js/test.js" | minify }}
<script>
{{ $js.Content }}
-- i18n/fr.toml --
[hello]
other = "Bonjour"
--- layouts/index.fr.html --
+-- layouts/home.fr.html --
Lang: {{ site.Language.Lang }}
{{ $templ := "{{T \"hello\"}}" | resources.FromString "f1.html" }}
{{ $helloResource := $templ | resources.ExecuteAsTemplate (print "f%s.html" .Lang) . }}
Hello1: {{T "hello"}}
Hello2: {{ $helloResource.Content }}
LangURL: {{ relLangURL "foo" }}
--- layouts/index.html --
+-- layouts/home.html --
Lang: {{ site.Language.Lang }}
{{ $templ := "{{T \"hello\"}}" | resources.FromString "f1.html" }}
{{ $helloResource := $templ | resources.ExecuteAsTemplate (print "f%s.html" .Lang) . }}
color: $moolor;
}
-- config.toml --
--- layouts/index.html --
+-- layouts/home.html --
{{ $cssOpts := (dict "includePaths" (slice "node_modules/foo") "transpiler" "dartsass" ) }}
{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }}
T1: {{ $r.Content }}
-- assets/scss/regular.css --
-- config.toml --
--- layouts/index.html --
+-- layouts/home.html --
{{ $r := resources.Get "scss/main.scss" | toCSS (dict "transpiler" "dartsass") }}
T1: {{ $r.Content | safeHTML }}
/* foo */
-- config.toml --
--- layouts/index.html --
+-- layouts/home.html --
{{ $r := resources.Get "scss/main.scss" | toCSS (dict "transpiler" "dartsass") }}
T1: {{ $r.Content | safeHTML }}
a {color: compile-this-mounted-file-css;}
-- foo/_import-this-mounted-file.css --
a {color: import-this-mounted-file-css;}
--- layouts/index.html --
+-- layouts/home.html --
{{- $opts := dict "transpiler" "dartsass" }}
{{- with resources.Get "main.scss" | toCSS $opts }}{{ .Content | safeHTML }}{{ end }}
-- config.toml --
}
-- config.toml --
theme = 'mytheme'
--- layouts/index.html --
+-- layouts/home.html --
{{ $cssOpts := (dict "includePaths" (slice "node_modules/foo" ) "transpiler" "dartsass" ) }}
{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }}
T1: {{ $r.Content }}
-- config.toml --
disableKinds = ["term", "taxonomy", "section", "page"]
--- layouts/index.html --
+-- layouts/home.html --
{{ $cssOpts := (dict "transpiler" "dartsass" ) }}
{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts }}
T1: {{ $r.Content }}
color: $maincolor;
}
--- layouts/index.html --
+-- layouts/home.html --
{{ $cssOpts := dict "transpiler" "dartsass" }}
{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }}
T1: {{ $r.Content }}
b {
color: vars.$color2;
}
--- layouts/index.html --
+-- layouts/home.html --
{{ $image := "images/hero.jpg" }}
{{ $font := "Hugo's New Roman" }}
{{ $vars := dict "$color1" "blue" "$color2" "green" "font_size" "24px" "image" $image "font" $font }}
b {
color: vars.$color2;
}
--- layouts/index.html --
+-- layouts/home.html --
{{ $vars := site.Params.sassvars}}
{{ $cssOpts := (dict "transpiler" "dartsass" "outputStyle" "compressed" "vars" $vars ) }}
{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts }}
@debug meta.type-of(vars.$integer);
@debug meta.type-of(vars.$float);
@debug meta.type-of(vars.$a_number);
--- layouts/index.html --
+-- layouts/home.html --
{{ $vars := site.Params.sassvars}}
{{ $vars = merge $vars (dict "not_a_number" ("32xxx" | css.Quoted) "a_number" ("234" | css.Unquoted) )}}
{{ $cssOpts := (dict "transpiler" "dartsass" "vars" $vars ) }}
module github.com/gohugoio/tests/testHugoModules
-- assets/scss/main.scss --
@import "bootstrap/bootstrap";
--- layouts/index.html --
+-- layouts/home.html --
{{ $cssOpts := (dict "transpiler" "dartsass" ) }}
{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts }}
Styles: {{ $r.RelPermalink }}
[[module.mounts]]
source = "miscellaneous/sass"
target = "assets/sass"
--- layouts/index.html --
+-- layouts/home.html --
{{ $opts := dict "transpiler" "dartsass" "outputStyle" "compressed" }}
{{ (resources.Get "sass/main.scss" | toCSS $opts).Content }}
-- assets/sass/main.scss --
color: $moolor;
}
-- config.toml --
--- layouts/index.html --
+-- layouts/home.html --
{{ $cssOpts := (dict "includePaths" (slice "node_modules/foo") "transpiler" "dartsass" ) }}
{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }}
T1: {{ $r.Content }}
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ $opts := dict
"transpiler" "dartsass"
"outputStyle" "compressed"
color: $moolor;
}
-- config.toml --
--- layouts/index.html --
+-- layouts/home.html --
{{ $cssOpts := (dict "includePaths" (slice "node_modules/foo") ) }}
{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }}
T1: {{ $r.Content }}
-- assets/scss/regular.css --
-- config.toml --
--- layouts/index.html --
+-- layouts/home.html --
{{ $r := resources.Get "scss/main.scss" | toCSS }}
T1: {{ $r.Content | safeHTML }}
}
-- config.toml --
theme = 'mytheme'
--- layouts/index.html --
+-- layouts/home.html --
{{ $cssOpts := (dict "includePaths" (slice "node_modules/foo" ) ) }}
{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }}
T1: {{ $r.Content }}
color: $maincolor;
}
--- layouts/index.html --
+-- layouts/home.html --
{{ $cssOpts := dict }}
{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }}
T1: {{ $r.Content }}
b {
color: $color2;
}
--- layouts/index.html --
+-- layouts/home.html --
{{ $image := "images/hero.jpg" }}
{{ $font := "Hugo's New Roman" }}
{{ $vars := dict "$color1" "blue" "$color2" "green" "font_size" "24px" "image" $image "font" $font }}
module github.com/gohugoio/tests/testHugoModules
-- assets/scss/main.scss --
@import "bootstrap/bootstrap";
--- layouts/index.html --
+-- layouts/home.html --
{{ $cssOpts := (dict "transpiler" "libsass" ) }}
{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts }}
Styles: {{ $r.RelPermalink }}
b {
color: red;
}
--- layouts/index.html --
+-- layouts/home.html --
{{ $r := resources.GetMatch "scss/main.scss" | toCSS }}
T1: {{ $r.Content }}
`
h3 {
color: green;
}
--- layouts/index.html --
+-- layouts/home.html --
{{ $a := slice (resources.Get "a.scss") }}
{{ $b := resources.Match "dir/*.scss" }}
[[module.mounts]]
source = "miscellaneous/sass"
target = "assets/sass"
--- layouts/index.html --
+-- layouts/home.html --
{{ $opts := dict "transpiler" "libsass" "outputStyle" "compressed" }}
{{ (resources.Get "sass/main.scss" | toCSS $opts).Content }}
-- assets/sass/main.scss --
-- content/mybundle/giphy.gif --
sourcefilename: testdata/giphy.gif
-- layouts/foo.html --
--- layouts/index.html --
+-- layouts/home.html --
{{ $p := site.GetPage "mybundle"}}
{{ $img := $p.Resources.Get "pixel.png" }}
{{ $giphy := $p.Resources.Get "giphy.gif" }}
-- config.toml --
-- assets/circle.svg --
<svg height="100" width="100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg>
--- layouts/index.html --
+-- layouts/home.html --
{{ $svg := resources.Get "circle.svg" }}
Width: {{ $svg.Width }}
`
files := `
-- assets/images/pixel.png --
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
--- layouts/index.html --
+-- layouts/home.html --
{{ $image := resources.Get "images/pixel.png" }}
{{ $image = $image.Resize "400x" }}
{{ $image = $image.Resize "300x" }}
files := `
-- assets/images/pixel.png --
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
--- layouts/index.html --
+-- layouts/home.html --
{{ $pixel := resources.Get "images/pixel.png" }}
{{ $filters := slice (images.GaussianBlur 6) (images.Pixelate 8) (images.Process "jpg") }}
{{ $image := $pixel.Filter $filters }}
files := `
-- config.toml --
disableKinds = ['section','rss','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{- range site.RegularPages.GroupByParamDate "eventDate" "2006-01" }}
{{- .Key }}|{{ range .Pages }}{{ .Title }}|{{ end }}
{{- end }}
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
-- assets/pixel.png --
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
--- layouts/index.html --
+-- layouts/home.html --
{{- with resources.Get "pixel.png" }}
{{- with .Resize "200x" | resources.Copy "pixel.png" }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">|{{ .Key }}
disableKinds = ['page','section','rss','sitemap','taxonomy','term']
-- assets/a.txt --
This was assets/a.txt
--- layouts/index.html --
+-- layouts/home.html --
{{ $nilResource := resources.Get "/p1/b.txt" }}
{{ $r := resources.Get "a.txt" }}
{{ $r = resources.Copy "/p1/b.txt" $r }}
title: "P2"
---
P2.
--- layouts/_default/list.html --
+-- layouts/list.html --
List.
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ $css := resources.Get "css/main.css" | resources.Minify }}
CSS: {{ $css.Content }}
`
files := `
-- config.toml --
baseURL = 'http://example.com/'
--- layouts/index.html --
+-- layouts/home.html --
{{ apply (seq 3) "partial" "foo.html"}}
--- layouts/partials/foo.html --
+-- layouts/_partials/foo.html --
{{ return "foo"}}
`
files := `
-- config.toml --
--- layouts/index.html --
+-- layouts/home.html --
{{ $values := slice (dict "a" 1 "b" 2) (dict "a" 3 "b" 1) (dict "a" 2 "b" 0) (dict "a" 1 "b" 0) (dict "a" 3 "b" 1) (dict "a" 2 "b" 2) (dict "a" 2 "b" 1) (dict "a" 0 "b" 3) (dict "a" 3 "b" 3) (dict "a" 0 "b" 0) (dict "a" 0 "b" 0) (dict "a" 2 "b" 0) (dict "a" 1 "b" 2) (dict "a" 1 "b" 1) (dict "a" 3 "b" 0) (dict "a" 2 "b" 0) (dict "a" 3 "b" 0) (dict "a" 3 "b" 0) (dict "a" 3 "b" 0) (dict "a" 3 "b" 1) }}
Asc: {{ sort (sort $values "b" "asc") "a" "asc" }}
Desc: {{ sort (sort $values "b" "desc") "a" "desc" }}
files := `
-- hugo.toml --
--- layouts/index.html --
+-- layouts/home.html --
{{ $obj := slice (slice "a") }}
{{ $obj = $obj | append (slice "b") }}
{{ $obj = $obj | append (slice "c") }}
files := `
-- hugo.toml --
--- layouts/index.html --
+-- layouts/home.html --
{{ $obj := (slice "a") }}
{{ $obj = $obj | append nil }}
files := `
-- hugo.toml --
--- layouts/index.html --
+-- layouts/home.html --
{{ $obj := (slice "a" nil "c") }}
{{ $obj = $obj | append nil }}
files := `
-- config.toml --
baseURL = 'http://example.com/'
--- layouts/index.html --
+-- layouts/home.html --
Home: {{ range where site.RegularPages "WordCount" "gt" 50 }}{{ .Title }}|{{ end }}
--- layouts/shortcodes/lorem.html --
+-- layouts/_shortcodes/lorem.html --
{{ "ipsum " | strings.Repeat (.Get 0 | int) }}
-- content/p1.md --
title: P3
foo: bc
---
--- layouts/index.html --
+-- layouts/home.html --
<ul>
{{- range where site.RegularPages "Params.foo" "like" "^ab" -}}
<li>{{ .Title }}</li>
categories: [cat-a]
tags: ['tag-b']
---
--- layouts/_default/term.html --
+-- layouts/term.html --
{{ $list1 := .Pages }}
{{ range $i, $e := site.Taxonomies.tags.ByCount }}
{{ $list2 := .Pages }}
files := `
-- config.toml --
disableKinds = ['rss','sitemap', 'taxonomy', 'term', 'page']
--- layouts/index.html --
+-- layouts/home.html --
{{ $a := resources.Match "*a*" }}
{{ $b := resources.Match "*b*" }}
{{ $union := $a | union $b }}
-- hugo.toml --
baseURL = "https://example.org/"
disableKinds = ["taxonomy", "term"]
--- layouts/index.html --
+-- layouts/home.html --
{{ range seq 5 }}
{{ $t := debug.Timer "foo" }}
{{ seq 1 1000 }}
title: "The First"
tags: ["a", "b"]
---
--- layouts/_default/list.html --
+-- layouts/list.html --
Dump: {{ debug.Dump . | safeHTML }}
Dump Site: {{ debug.Dump site }}
Dum site.Taxonomies: {{ debug.Dump site.Taxonomies | safeHTML }}
--- layouts/_default/single.html --
+-- layouts/single.html --
Dump: {{ debug.Dump . | safeHTML }}
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
ignoreErrors = ['error-b','error-C']
--- layouts/index.html --
+-- layouts/home.html --
{{ erroridf "error-a" "%s" "a"}}
{{ erroridf "error-b" "%s" "b"}}
{{ erroridf "error-C" "%s" "C"}}
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
ignoreLogs = ['warning-b', 'WarniNg-C']
--- layouts/index.html --
+-- layouts/home.html --
{{ warnidf "warning-a" "%s" "a"}}
{{ warnidf "warning-b" "%s" "b"}}
{{ warnidf "warNing-C" "%s" "c"}}
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
-- themes/mytheme/static/images/pixel2.png --
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
--- layouts/index.html --
+-- layouts/home.html --
{{ $path := "static/images/pixel1.png" }}
fileExists OK: {{ fileExists $path }}|
imageConfig OK: {{ (imageConfig $path).Width }}|
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{- $text := "https://gohugo.io" }}
{{- $optionMaps := slice
(dict)
-- assets/sunset.jpg --
sourcefilename: ../../resources/testdata/sunset.jpg
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ template "copy" (dict "name" "qr-default.png" "img" (images.QR "https://gohugo.io")) }}
Hello project!
-- themes/mytheme/mytheme.txt --
Hello theme!
--- layouts/index.html --
+-- layouts/home.html --
{{ $entries := (readDir ".") }}
START:|{{ range $entry := $entries }}{{ if not $entry.IsDir }}{{ $entry.Name }}|{{ end }}{{ end }}:END:
files := `
-- config.toml --
--- layouts/index.html --
+-- layouts/home.html --
{{ $fi := (readFile "doesnotexist") }}
{{ if $fi }}Failed{{ else }}OK{{ end }}
---
{{< foo.inline >}}{{ if page.IsHome }}Shortcode in bundled page OK.{{ else}}Failed.{{ end }}{{< /foo.inline >}}
-- content/p3.md --
--- layouts/_default/_markup/render-heading.html --
+-- layouts/_markup/render-heading.html --
{{ if page.IsHome }}
Heading OK.
{{ end }}
--- layouts/_default/_markup/render-image.html --
+-- layouts/_markup/render-image.html --
{{ if page.IsHome }}
Image OK.
{{ end }}
--- layouts/_default/_markup/render-link.html --
+-- layouts/_markup/render-link.html --
{{ if page.IsHome }}
Link OK.
{{ end }}
--- layouts/_default/myview.html
+-- layouts/myview.html
{{ if page.IsHome }}
Render OK.
{{ end }}
--- layouts/_default/_markup/render-codeblock.html --
+-- layouts/_markup/render-codeblock.html --
{{ if page.IsHome }}
Codeblock OK.
{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
Single.
--- layouts/index.html --
+-- layouts/home.html --
{{ if eq page . }}Page OK.{{ end }}
{{ $r := "{{ if page.IsHome }}ExecuteAsTemplate OK.{{ end }}" | resources.FromString "foo.html" | resources.ExecuteAsTemplate "foo.html" . }}
{{ $r.Content }}
{{ if eq page .Page }}Alias OK.{{ else }}Failed.{{ end }}
-- layouts/404.html --
{{ if eq page . }}404 Page OK.{{ else }}Failed.{{ end }}
--- layouts/partials/foo.html --
+-- layouts/_partials/foo.html --
{{ if page.IsHome }}Partial OK.{{ else }}Failed.{{ end }}
--- layouts/shortcodes/outer.html --
+-- layouts/_shortcodes/outer.html --
{{ .Inner }}
--- layouts/shortcodes/inner.html --
+-- layouts/_shortcodes/inner.html --
{{ if page.IsHome }}Shortcode Inner OK.{{ else }}Failed.{{ end }}
--- layouts/shortcodes/shortcode.html --
+-- layouts/_shortcodes/shortcode.html --
{{ if page.IsHome }}Shortcode {{ .Get 0 }} OK.{{ else }}Failed.{{ end }}
-- layouts/sitemap.xml --
{{ if eq page . }}Sitemap OK.{{ else }}Failed.{{ end }}
{{< toc >}}
# Heading 1
--- layouts/shortcodes/toc.html --
+-- layouts/_shortcodes/toc.html --
{{ page.TableOfContents }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
files := `
-- hugo.toml --
disableLiveReload = true
--- layouts/index.html --
+-- layouts/home.html --
{{ with resources.FromString "foo" "{{ seq 3 }}" }}
{{ with resources.ExecuteAsTemplate "bar" $ . }}
{{ .Content | safeHTML }}
files := `
-- config.toml --
baseURL = 'http://example.com/'
--- layouts/index.html --
+-- layouts/home.html --
partial: {{ partials.Include "foo.html" . }}
--- layouts/partials/foo.html --
+-- layouts/_partials/foo.html --
foo
`
files := `
-- config.toml --
baseURL = 'http://example.com/'
--- layouts/index.html --
+-- layouts/home.html --
partialCached: {{ partials.IncludeCached "foo.html" . }}
partialCached: {{ partials.IncludeCached "foo.html" . }}
--- layouts/partials/foo.html --
+-- layouts/_partials/foo.html --
foo
`
files := `
-- config.toml --
baseURL = 'http://example.com/'
--- layouts/index.html --
+-- layouts/home.html --
{{ partials.IncludeCached "p1.html" . }}
--- layouts/partials/p1.html --
+-- layouts/_partials/p1.html --
{{ partials.IncludeCached "p2.html" . }}
--- layouts/partials/p2.html --
+-- layouts/_partials/p2.html --
P2
`
title: "Index"
---
{{< short >}}
--- layouts/index.html --
+-- layouts/home.html --
{{ partials.IncludeCached "p1.html" . }}
--- layouts/partials/p1.html --
+-- layouts/_partials/p1.html --
{{ .Content }}
{{ partials.IncludeCached "p2.html" . }}
--- layouts/partials/p2.html --
--- layouts/shortcodes/short.html --
+-- layouts/_partials/p2.html --
+-- layouts/_shortcodes/short.html --
SHORT
{{ partials.IncludeCached "p2.html" . }}
P2
disableKinds = ["page", "section", "taxonomy", "term", "sitemap"]
[outputs]
home = ["HTML"]
--- layouts/index.html --
+-- layouts/home.html --
{{ partials.IncludeCached "static1.html" . }}
{{ partials.IncludeCached "static1.html" . }}
{{ partials.Include "static2.html" . }}
H1C: {{ partials.IncludeCached "halfdynamic1.html" . }}
H1C: {{ partials.IncludeCached "halfdynamic1.html" . }}
--- layouts/partials/static1.html --
+-- layouts/_partials/static1.html --
P1
--- layouts/partials/static2.html --
+-- layouts/_partials/static2.html --
P2
--- layouts/partials/dynamic1.html --
+-- layouts/_partials/dynamic1.html --
{{ math.Counter }}
--- layouts/partials/halfdynamic1.html --
+-- layouts/_partials/halfdynamic1.html --
D1
{{ math.Counter }}
got = normalize(got)
expect := `
- 0 0 0 1 index.html
+ 0 0 0 1 home.html
100 0 0 1 _partials/static2.html
100 50 1 2 _partials/static1.html
25 50 2 4 _partials/dynamic1.html
files := `
-- config.toml --
baseURL = 'http://example.com/'
--- layouts/index.html --
--- layouts/_default/single.html --
+-- layouts/home.html --
+-- layouts/single.html --
{{ partialCached "heavy.html" "foo" }}
{{ partialCached "easy1.html" "bar" }}
{{ partialCached "easy1.html" "baz" }}
{{ partialCached "easy2.html" "baz" }}
--- layouts/partials/easy1.html --
+-- layouts/_partials/easy1.html --
ABCD
--- layouts/partials/easy2.html --
+-- layouts/_partials/easy2.html --
ABCDE
--- layouts/partials/heavy.html --
+-- layouts/_partials/heavy.html --
{{ $result := slice }}
{{ range site.RegularPages }}
{{ $result = $result | append (dict "title" .Title "link" .RelPermalink "readingTime" .ReadingTime) }}
files := `
-- config.toml --
baseURL = 'http://example.com/'
--- layouts/index.html --
+-- layouts/home.html --
{{ partials.Include "foo.html" . }}
--- layouts/partials/foo.html --
+-- layouts/_partials/foo.html --
{{ partial "foo.html" . }}
`
-- config.toml --
baseURL = 'http://example.com/'
timeout = '200ms'
--- layouts/index.html --
+-- layouts/home.html --
{{ partials.IncludeCached "foo.html" . }}
--- layouts/partials/foo.html --
+-- layouts/_partials/foo.html --
{{ partialCached "bar.html" . }}
--- layouts/partials/bar.html --
+-- layouts/_partials/bar.html --
{{ partialCached "foo.html" . }}
`
-- config.toml --
baseURL = 'http://example.com/'
timeout = '200ms'
--- layouts/index.html --
+-- layouts/home.html --
{{ partialCached "foo.html" "a" "a" }}
--- layouts/partials/foo.html --
+-- layouts/_partials/foo.html --
{{ if eq . "a" }}
{{ partialCached "bar.html" . }}
{{ else }}
DONE
{{ end }}
--- layouts/partials/bar.html --
+-- layouts/_partials/bar.html --
{{ partialCached "foo.html" "b" "b" }}
`
b := hugolib.Test(t, files)
files := `
-- config.toml --
baseURL = 'http://example.com/'
--- layouts/index.html --
+-- layouts/home.html --
{{ $r := partial "foo" }}
FOO:{{ $r.Content }}
--- layouts/partials/foo.html --
+-- layouts/_partials/foo.html --
{{ $r := §§{{ partial "bar" }}§§ | resources.FromString "bar.html" | resources.ExecuteAsTemplate "bar.html" . }}
{{ return $r }}
--- layouts/partials/bar.html --
+-- layouts/_partials/bar.html --
BAR
`
baseURL = "http://example.com/blog"
-- assets/images/pixel.png --
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
--- layouts/index.html --
+-- layouts/home.html --
{{/* Image resources */}}
{{ $img := resources.Get "images/pixel.png" }}
{{ $imgCopy1 := $img | resources.Copy "images/copy.png" }}
files := `
-- config.toml --
--- layouts/index.html --
+-- layouts/home.html --
{{/* This is currently not supported. */}}
{{ $copy := .Copy "copy.md" }}
baseURL = "http://example.com/blog"
-- assets/images/pixel.png --
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
--- layouts/index.html --
+-- layouts/home.html --
{{ with resources.Get "images/pixel.png" }}Image OK{{ else }}Image not found{{ end }}
{{ with resources.Get "" }}Failed{{ else }}Empty string not found{{ end }}
baseURL = "http://example.com/"
-- assets/401K Prospectus.txt --
Prospectus.
--- layouts/index.html --
+-- layouts/home.html --
{{ $name := "401K Prospectus.txt" }}
Get: {{ with resources.Get $name }}{{ .RelPermalink }}|{{ .Permalink }}|{{ end }}
GetMatch: {{ with resources.GetMatch $name }}{{ .RelPermalink }}|{{ .Permalink }}|{{ end }}
I am a.txt
-- assets/b.txt --
I am b.txt
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ with resources.ByType "text" }}
{{ with .Get "a.txt" }}
I am c.txt
-- assets/files/C.txt --
I am C.txt
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ with resources.ByType "text" }}
{{ with .Get "files/a.txt" }}
files := `
-- hugo.toml --
disableKinds = ['page','section','rss','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ $opts := dict "transpiler" "dartsass" "outputStyle" "compressed" "vars" (dict "color" "red") }}
{{ with resources.Get "dartsass.scss" | css.Sass $opts }}
{{ .Content }}
Hello.
-- layouts/baseof.html --
HTML|{{ block "main" . }}{{ end }}$
--- layouts/index.html --
+-- layouts/home.html --
{{ define "main" }}
EDIT_COUNTER_OUTSIDE_0
{{ .Store.Set "hello" "Hello" }}
files := `
-- hugo.toml --
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ with (templates.Defer (dict "key" "foo")) }}
Defer
Defer
{{ end }}
Block:{{ block "main" . }}{{ end }}$
--- layouts/index.html --
+-- layouts/home.html --
{{ define "main" }}
Home.
{{ end }}
-- layouts/baseof.html --
Block:{{ block "main" . }}{{ end }}$
--- layouts/index.html --
+-- layouts/home.html --
{{ define "main" }}
Home.
{{ with (templates.Defer (dict "key" "foo")) }}
for i := range 5 {
old := fmt.Sprintf("EDIT_COUNTER_OUTSIDE_%d", i)
new := fmt.Sprintf("EDIT_COUNTER_OUTSIDE_%d", i+1)
- b.EditFileReplaceAll("layouts/index.html", old, new).Build()
+ b.EditFileReplaceAll("layouts/home.html", old, new).Build()
b.AssertFileContent("public/index.html", new)
}
}
for i := range 8 {
old := fmt.Sprintf("EDIT_COUNTER_DEFER_%d", i)
new := fmt.Sprintf("EDIT_COUNTER_DEFER_%d", i+1)
- b.EditFileReplaceAll("layouts/index.html", old, new).Build()
+ b.EditFileReplaceAll("layouts/home.html", old, new).Build()
b.AssertFileContent("public/index.html", new)
}
}
b := hugolib.TestRunning(t, deferFilesCommon)
b.AssertRenderCountPage(4)
- b.EditFileReplaceAll("layouts/index.html", "REPLACE_ME", "Edited.").Build()
+ b.EditFileReplaceAll("layouts/home.html", "REPLACE_ME", "Edited.").Build()
b.AssertFileContent("public/index.html", "Edited.")
b.AssertRenderCountPage(2)
}
source = 'public'
target = 'assets/public'
disableWatch = true
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ $mydata := dict "v1" "v1value" }}
{{ $json := resources.FromString "mydata/data.json" ($mydata | jsonify ) }}
-- hugo.toml --
-- assets/mytext.txt --
ABCD.
--- layouts/index.html --
+-- layouts/home.html --
Home
{{ with (templates.Defer (dict "key" "foo")) }}
{{ $mytext := resources.Get "mytext.txt" | minify | resources.PostProcess }}
files := `
-- hugo.toml --
--- layouts/index.html --
+-- layouts/home.html --
Home.
...
{{ with (templates.Defer (dict "data" (dict "a" "b") )) }}
ns.AddMethodMapping(ctx.Exists,
nil,
[][2]string{
- {`{{ if (templates.Exists "partials/header.html") }}Yes!{{ end }}`, `Yes!`},
- {`{{ if not (templates.Exists "partials/doesnotexist.html") }}No!{{ end }}`, `No!`},
+ {`{{ if (templates.Exists "_partials/header.html") }}Yes!{{ end }}`, `Yes!`},
+ {`{{ if not (templates.Exists "_partials/doesnotexist.html") }}No!{{ end }}`, `No!`},
},
)
files := `
-- config.toml --
baseURL = 'http://example.com/'
--- layouts/index.html --
-index.html: {{ templates.Exists "index.html" }}
+-- layouts/home.html --
+home.html: {{ templates.Exists "home.html" }}
post/single.html: {{ templates.Exists "post/single.html" }}
-partials/foo.html: {{ templates.Exists "partials/foo.html" }}
-partials/doesnotexist.html: {{ templates.Exists "partials/doesnotexist.html" }}
+_partials/foo.html: {{ templates.Exists "_partials/foo.html" }}
+_partials/doesnotexist.html: {{ templates.Exists "_partials/doesnotexist.html" }}
-- layouts/post/single.html --
--- layouts/partials/foo.html --
+-- layouts/_partials/foo.html --
`
b := hugolib.Test(t, files)
b.AssertFileContent("public/index.html", `
-index.html: true
+home.html: true
post/single.html: true
-partials/foo.html: true
-partials/doesnotexist.html: false
+_partials/foo.html: true
+_partials/doesnotexist.html: false
`)
}
baseURL = 'http://example.com/'
-- layouts/baseof.html --
{{ block "main" . }}{{ end }}
--- layouts/index.html --
+-- layouts/home.html --
{{ define "main" }}
-index.html: {{ templates.Exists "index.html" }}
+index.html: {{ templates.Exists "home.html" }}
post/single.html: {{ templates.Exists "post/single.html" }}
post/doesnotexist.html: {{ templates.Exists "post/doesnotexist.html" }}
{{ end }}
files := `
-- config.toml --
baseURL = 'http://example.com/'
--- layouts/index.html --
+-- layouts/home.html --
Home: {{ page.IsHome }}
`
files := `
-- config.toml --
baseURL = 'http://example.com/'
--- layouts/index.html --
+-- layouts/home.html --
Home.
{{ $g := try ("hello = \"Hello Hugo\"" | transform.Unmarshal) }}
{{ with $g.Err }}
b.AssertFileContent("public/index.html",
"Value1: Hello Hugo|",
- "Err2: template: index.html:",
+ "Err2: template: home.html:",
"Try upper: HELLO",
"Try printf: hello world",
)
+++ /dev/null
-// Copyright 2025 The Hugo Authors. All rights reserved.
-//
-// Portions Copyright The Go Authors.
-
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package tplimpl_test
-
-import (
- "testing"
-
- "github.com/gohugoio/hugo/hugolib"
-)
-
-func TestLegacyPartialIssue13599(t *testing.T) {
- t.Parallel()
-
- files := `
--- hugo.toml --
--- layouts/partials/mypartial.html --
-Mypartial.
--- layouts/_default/index.html --
-mypartial: {{ template "partials/mypartial.html" . }}
-
-`
- b := hugolib.Test(t, files)
-
- b.AssertFileContent("public/index.html", "Mypartial.")
-}
disableKinds = ['rss','sitemap','taxonomy','term']
[markup.goldmark.renderHooks.link]
enableDefault = true
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ .Content }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
-- assets/a.txt --
irrelevant
{id="\"><script>alert()</script>"}
-- content/p1/pixel.png --
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content }}
`
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
-- content/_index.md --
---
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
-- content/_index.md --
---
attr="an _emphasized_ word"
attrlink="https://example.org/foo"
>}}
--- layouts/index.html --
+-- layouts/home.html --
Hash: {{ .Content | hash.XxHash }}
Content: {{ .Content }}
`
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
-- content/_index.md --
---
files := `
-- hugo.toml --
disableKinds = ['home','rss','section','sitemap','taxonomy','term']
--- layouts/_default/single.html --
+-- layouts/single.html --
Hash: {{ .Content | hash.XxHash }}
Content: {{ .Content }}
-- content/p1.md --
title: home
---
{{< instagram CxOWiQNP2MO >}}
--- layouts/index.html --
+-- layouts/home.html --
Hash: {{ .Content | hash.XxHash }}
Content: {{ .Content }}
`
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
[params]
b = 2
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
-- content/_index.md --
---
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
-- content/_index.md --
---
weight = 2
[outputs]
page = ['html','json']
--- layouts/_default/home.html --
+-- layouts/home.html --
{{ .Content }}
--- layouts/_default/single.html.html --
+-- layouts/single.html.html --
{{ .Title }}
--- layouts/_default/single.json.json --
+-- layouts/single.json.json --
{{ .Title }}
-- content/_index.en.md --
---
weight = 2
[outputs]
page = ['html','json']
--- layouts/_default/home.html --
+-- layouts/home.html --
{{ .Content }}
--- layouts/_default/single.html.html --
+-- layouts/single.html.html --
{{ .Title }}
--- layouts/_default/single.json.json --
+-- layouts/single.json.json --
{{ .Title }}
-- content/_index.en.md --
---
title: p3
---
{{< vimeo id=55073825 allowFullScreen=false >}}
--- layouts/_default/single.html --
+-- layouts/single.html --
Hash: {{ .Content | hash.XxHash }}
Content: {{ .Content }}
`
title: p5
---
{{< twitter_simple user="SanDiegoZoo" id="1453110110599868418" >}}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Content | strings.TrimSpace | safeHTML }}
--
`
{{< x_simple user="__user_does_not_exist__" id="__id_does_not_exist__" >}}
{{< twitter user="__user_does_not_exist__" id="__id_does_not_exist__" >}}
{{< twitter_simple user="__user_does_not_exist__" id="__id_does_not_exist__" >}}
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
`
-- hugo.toml --
disableKinds = ['home','rss','section','sitemap','taxonomy','term']
privacy.youtube.privacyEnhanced = false
--- layouts/_default/single.html --
+-- layouts/single.html --
Hash: {{ .Content | hash.XxHash }}
Content: {{ .Content }}
-- content/p1.md --
t.Parallel()
files := `
--- config.toml --
+-- hugo.toml --
disableKinds=["home", "section", "taxonomy", "term", "sitemap", "robotsTXT"]
ignoreErrors = ["my-err-id"]
[outputs]
home=["HTML"]
--- layouts/partials/header.html --
+-- layouts/_partials/header.html --
<title>Hugo Rocks!</title>
-- files/README.txt --
Hugo Rocks!
}
}
- files += fmt.Sprintf("-- layouts/_default/single.html --\n%s\n", strings.Join(templates, "\n"))
+ files += fmt.Sprintf("-- layouts/single.html --\n%s\n", strings.Join(templates, "\n"))
b = hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
+// Copyright 2025 The Hugo Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
package tplimpl_test
import (
"github.com/gohugoio/hugo/tpl/tplimpl"
)
-// Old as in before Hugo v0.146.0.
-func TestLayoutsOldSetup(t *testing.T) {
- t.Parallel()
-
- files := `
--- hugo.toml --
-defaultContentLanguage = "en"
-defaultContentLanguageInSubdir = true
-[languages]
-[languages.en]
-title = "Title in English"
-weight = 1
-[languages.nn]
-title = "Tittel på nynorsk"
-weight = 2
--- layouts/index.html --
-Home.
-{{ template "_internal/twitter_cards.html" . }}
--- layouts/_default/single.html --
-Single.
--- layouts/_default/single.nn.html --
-Single NN.
--- layouts/_default/list.html --
-List HTML.
--- layouts/docs/list-baseof.html --
-Docs Baseof List HTML.
-{{ block "main" . }}Docs Baseof List HTML main block.{{ end }}
--- layouts/docs/list.section.html --
-{{ define "main" }}
-Docs List HTML.
-{{ end }}
--- layouts/_default/list.json --
-List JSON.
--- layouts/_default/list.rss.xml --
-List RSS.
--- layouts/_default/list.nn.rss.xml --
-List NN RSS.
--- layouts/_default/baseof.html --
-Base.
--- layouts/partials/mypartial.html --
-Partial.
--- layouts/shortcodes/myshortcode.html --
-Shortcode.
--- content/docs/p1.md --
----
-title: "P1"
----
-
- `
-
- b := hugolib.Test(t, files)
-
- // b.DebugPrint("", tplimpl.CategoryBaseof)
-
- b.AssertFileContent("public/en/docs/index.html", "Docs Baseof List HTML.\n\nDocs List HTML.")
-}
-
-func TestLayoutsOldSetupBaseofPrefix(t *testing.T) {
- t.Parallel()
-
- files := `
--- hugo.toml --
--- layouts/_default/layout1-baseof.html --
-Baseof layout1. {{ block "main" . }}{{ end }}
--- layouts/_default/layout2-baseof.html --
-Baseof layout2. {{ block "main" . }}{{ end }}
--- layouts/_default/layout1.html --
-{{ define "main" }}Layout1. {{ .Title }}{{ end }}
--- layouts/_default/layout2.html --
-{{ define "main" }}Layout2. {{ .Title }}{{ end }}
--- content/p1.md --
----
-title: "P1"
-layout: "layout1"
----
--- content/p2.md --
----
-title: "P2"
-layout: "layout2"
----
-`
-
- b := hugolib.Test(t, files)
-
- b.AssertFileContent("public/p1/index.html", "Baseof layout1. Layout1. P1")
- b.AssertFileContent("public/p2/index.html", "Baseof layout2. Layout2. P2")
-}
-
-func TestLayoutsOldSetupTaxonomyAndTerm(t *testing.T) {
- t.Parallel()
-
- files := `
--- hugo.toml --
-[taxonomies]
-cat = 'cats'
-dog = 'dogs'
-# Templates for term taxonomy, old setup.
--- layouts/dogs/terms.html --
-Dogs Terms. Most specific taxonomy template.
--- layouts/taxonomy/terms.html --
-Taxonomy Terms. Down the list.
-# Templates for term term, old setup.
--- layouts/dogs/term.html --
-Dogs Term. Most specific term template.
--- layouts/term/term.html --
-Term Term. Down the list.
--- layouts/dogs/max/list.html --
-max: {{ .Title }}
--- layouts/_default/list.html --
-Default list.
--- layouts/_default/single.html --
-Default single.
--- content/p1.md --
----
-title: "P1"
-dogs: ["luna", "daisy", "max"]
----
-
-`
- b := hugolib.Test(t, files, hugolib.TestOptWarn())
-
- b.AssertLogContains("! WARN")
-
- b.AssertFileContent("public/dogs/index.html", "Dogs Terms. Most specific taxonomy template.")
- b.AssertFileContent("public/dogs/luna/index.html", "Dogs Term. Most specific term template.")
- b.AssertFileContent("public/dogs/max/index.html", "max: Max") // layouts/dogs/max/list.html wins over layouts/term/term.html because of distance.
-}
-
-func TestLayoutsOldSetupCustomRSS(t *testing.T) {
- t.Parallel()
-
- files := `
--- hugo.toml --
-disableKinds = ["taxonomy", "term", "page"]
-[outputs]
-home = ["rss"]
--- layouts/_default/list.rss.xml --
-List RSS.
-`
- b := hugolib.Test(t, files)
- b.AssertFileContent("public/index.xml", "List RSS.")
-}
-
var newSetupTestSites = `
-- hugo.toml --
defaultContentLanguage = "en"
Base term.
-- layouts/baseof.section.fr.amp.html --
Base with identifiers.{{ block "main" . }}{{ end }}
--- layouts/partials/mypartial.html --
+-- layouts/_partials/mypartial.html --
Partial. {{ partial "_inline/my-inline-partial-in-partial-with-no-ext" . }}
{{ define "partials/_inline/my-inline-partial-in-partial-with-no-ext" }}
Partial in partial.
{{ end }}
--- layouts/partials/returnfoo.html --
+-- layouts/_partials/returnfoo.html --
{{ $v := "foo" }}
{{ return $v }}
--- layouts/shortcodes/myshortcode.html --
+-- layouts/_shortcodes/myshortcode.html --
Shortcode. {{ partial "mypartial.html" . }}|return:{{ partial "returnfoo.html" . }}|
-- content/_index.md --
---
Home: {{ .Title }}|{{ .Content }}|
-- layouts/single.html --
Single: {{ .Title }}|{{ .Content }}|
--- layouts/shortcodes/myshortcode.html --
+-- layouts/_shortcodes/myshortcode.html --
Myshortcode: Count: {{ math.Counter }}|
-- content/p1.md --
---
{{ block "main" . }}{{ end }}
-- layouts/baseof.json --
{{ block "main" . }}{{ end }}
--- layouts/index.html --
+-- layouts/home.html --
{{ define "main" }}FOO{{ end }}
--- layouts/_default/single.json --
--- layouts/_default/single.html --
+-- layouts/single.json --
+-- layouts/single.html --
{{ define "main" }}MAIN /_default/single.html{{ end }}
-- layouts/post/single.html --
{{ define "main" }}MAIN{{ end }}
-- layouts/_partials/unusedpartial.html --
-- layouts/_shortcodes/usedshortcode.html --
{{ partial "usedpartial.html" }}
--- layouts/shortcodes/unusedshortcode.html --
+-- layouts/_shortcodes/unusedshortcode.html --
`
}
}
- b.Assert(names, qt.DeepEquals, []string{"_partials/unusedpartial.html", "shortcodes/unusedshortcode.html", "baseof.json", "post/single.html", "_default/single.json"})
+ b.Assert(names, qt.DeepEquals, []string{"_partials/unusedpartial.html", "_shortcodes/unusedshortcode.html", "baseof.json", "post/single.html", "single.json"})
b.Assert(len(unused), qt.Equals, 5, qt.Commentf("%#v", names))
}
b.AssertFileContent("public/admin/v1.0.0/en/index.html", "layouts/v1/all.html")
}
-func TestLayoutWithLanguagesLegacy(t *testing.T) {
- t.Parallel()
- files := `
--- hugo.toml --
-disableKinds = ["taxonomy", "term", "sitemap", "rss"]
-defaultContentLanguage = "en"
-defaultContentLanguageInSubdir = true
-[languages]
-[languages.en]
-weight = 1
-[languages.nn]
-weight = 2
-[languages.sv]
-weight = 3
--- layouts/_default/single.en.html --
-layouts/_default/single.html
--- layouts/_default/single.nn.html --
-layouts/_default/single.nn.html
--- layouts/_default/single.sv.html --
-layouts/_default/single.sv.html
--- content/p1.md --
----
-title: "P1"
----
--- content/p1.nn.md --
----
-title: "P1 NN"
----
--- content/p1.sv.md --
----
-title: "P1 SV"
----
-`
- b := hugolib.Test(t, files)
-
- b.AssertFileContent("public/en/p1/index.html", "layouts/_default/single.html")
- b.AssertFileContent("public/nn/p1/index.html", "layouts/_default/single.nn.html")
- b.AssertFileContent("public/sv/p1/index.html", "layouts/_default/single.sv.html")
-}
-
-func TestLayoutWithLanguagesLegacyMounts(t *testing.T) {
- t.Parallel()
- files := `
--- hugo.toml --
-disableKinds = ["taxonomy", "term", "sitemap", "rss"]
-defaultContentLanguage = "en"
-defaultContentLanguageInSubdir = true
-[languages]
-[languages.en]
-weight = 1
-[languages.nn]
-weight = 2
-[languages.sv]
-weight = 3
-
-
-[[module.mounts]]
-source = 'layouts/en'
-target = 'layouts'
-lang = 'en'
-
-[[module.mounts]]
-source = 'layouts/nn'
-target = 'layouts'
-lang = 'nn'
-[[module.mounts]]
-source = 'layouts/sv'
-target = 'layouts'
-lang = 'sv'
-
--- layouts/en/_default/single.html --
-layouts/en/_default/single.html
--- layouts/nn/_default/single.html --
-layouts/nn/_default/single.html
--- layouts/sv/_default/single.html --
-layouts/sv/_default/single.html
--- content/p1.md --
----
-title: "P1"
----
--- content/p1.nn.md --
----
-title: "P1 NN"
----
--- content/p1.sv.md --
----
-title: "P1 SV"
----
-`
- b := hugolib.Test(t, files)
-
- b.AssertFileContent("public/en/p1/index.html", "layouts/en/_default/single.html")
- b.AssertFileContent("public/nn/p1/index.html", "layouts/nn/_default/single.html")
- b.AssertFileContent("public/sv/p1/index.html", "layouts/sv/_default/single.html")
-}
-
func BenchmarkLookupPagesLayout(b *testing.B) {
files := `
-- hugo.toml --
-- layouts/list.xml --
layouts/list.xml
-- layouts/_shortcodes/myshortcode.html --
-layouts/shortcodes/myshortcode.html
+layouts/_shortcodes/myshortcode.html
-- layouts/foo/bar/_shortcodes/myshortcode.html --
layouts/foo/bar/_shortcodes/myshortcode.html
-- layouts/_markup/render-codeblock.html --
b.AssertFileContent("public/en/p/index.html", "layouts/single.html",
"layouts/_markup/render-codeblock.html|",
"layouts/_markup/render-codeblock-go.html|go|",
- "layouts/shortcodes/myshortcode.html",
+ "layouts/_shortcodes/myshortcode.html",
)
b.AssertFileContent("public/en/foo/p/index.html", "layouts/single.html")
b.AssertFileContent("public/en/foo/bar/p/index.html", "layouts/foo/bar/page.html")
{{ partial "css.html" .}}
</head>
</html>
--- layouts/partials/css.html --
+-- layouts/_partials/css.html --
<link rel="stylesheet" href="/css/style.css">
`
{{ partial "mypartial.txt" . }}
</head>
</html>
--- layouts/partials/mypartial.txt --
+-- layouts/_partials/mypartial.txt --
My <div>partial</div>.
`
-- content/v0.123.0.md --
-- layouts/all.html --
All.
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}|
`
a|b
:--|:--
1|2
--- layouts/index.html --
+-- layouts/home.html --
{{ .Content }}
-- layouts/index.json --
{{ .Content }}
--- /dev/null
+// Copyright 2025 The Hugo Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package tplimpl_test
+
+import (
+ "testing"
+
+ "github.com/gohugoio/hugo/hugolib"
+)
+
+// Old as in before Hugo v0.146.0.
+func TestLayoutsOldSetup(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+defaultContentLanguage = "en"
+defaultContentLanguageInSubdir = true
+[languages]
+[languages.en]
+title = "Title in English"
+weight = 1
+[languages.nn]
+title = "Tittel på nynorsk"
+weight = 2
+-- layouts/index.html --
+Home.
+{{ template "_internal/twitter_cards.html" . }}
+-- layouts/_default/single.html --
+Single.
+-- layouts/_default/single.nn.html --
+Single NN.
+-- layouts/_default/list.html --
+List HTML.
+-- layouts/docs/list-baseof.html --
+Docs Baseof List HTML.
+{{ block "main" . }}Docs Baseof List HTML main block.{{ end }}
+-- layouts/docs/list.section.html --
+{{ define "main" }}
+Docs List HTML.
+{{ end }}
+-- layouts/_default/list.json --
+List JSON.
+-- layouts/_default/list.rss.xml --
+List RSS.
+-- layouts/_default/list.nn.rss.xml --
+List NN RSS.
+-- layouts/_default/baseof.html --
+Base.
+-- layouts/partials/mypartial.html --
+Partial.
+-- layouts/shortcodes/myshortcode.html --
+Shortcode.
+-- content/docs/p1.md --
+---
+title: "P1"
+---
+
+ `
+
+ b := hugolib.Test(t, files)
+
+ // b.DebugPrint("", tplimpl.CategoryBaseof)
+
+ b.AssertFileContent("public/en/docs/index.html", "Docs Baseof List HTML.\n\nDocs List HTML.")
+}
+
+func TestLayoutsOldSetupBaseofPrefix(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+-- layouts/_default/layout1-baseof.html --
+Baseof layout1. {{ block "main" . }}{{ end }}
+-- layouts/_default/layout2-baseof.html --
+Baseof layout2. {{ block "main" . }}{{ end }}
+-- layouts/_default/layout1.html --
+{{ define "main" }}Layout1. {{ .Title }}{{ end }}
+-- layouts/_default/layout2.html --
+{{ define "main" }}Layout2. {{ .Title }}{{ end }}
+-- content/p1.md --
+---
+title: "P1"
+layout: "layout1"
+---
+-- content/p2.md --
+---
+title: "P2"
+layout: "layout2"
+---
+`
+
+ b := hugolib.Test(t, files)
+
+ b.AssertFileContent("public/p1/index.html", "Baseof layout1. Layout1. P1")
+ b.AssertFileContent("public/p2/index.html", "Baseof layout2. Layout2. P2")
+}
+
+func TestLayoutsOldSetupTaxonomyAndTerm(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+[taxonomies]
+cat = 'cats'
+dog = 'dogs'
+# Templates for term taxonomy, old setup.
+-- layouts/dogs/terms.html --
+Dogs Terms. Most specific taxonomy template.
+-- layouts/taxonomy/terms.html --
+Taxonomy Terms. Down the list.
+# Templates for term term, old setup.
+-- layouts/dogs/term.html --
+Dogs Term. Most specific term template.
+-- layouts/term/term.html --
+Term Term. Down the list.
+-- layouts/dogs/max/list.html --
+max: {{ .Title }}
+-- layouts/_default/list.html --
+Default list.
+-- layouts/_default/single.html --
+Default single.
+-- content/p1.md --
+---
+title: "P1"
+dogs: ["luna", "daisy", "max"]
+---
+
+`
+ b := hugolib.Test(t, files, hugolib.TestOptWarn())
+
+ b.AssertLogContains("! WARN")
+
+ b.AssertFileContent("public/dogs/index.html", "Dogs Terms. Most specific taxonomy template.")
+ b.AssertFileContent("public/dogs/luna/index.html", "Dogs Term. Most specific term template.")
+ b.AssertFileContent("public/dogs/max/index.html", "max: Max") // layouts/dogs/max/list.html wins over layouts/term/term.html because of distance.
+}
+
+func TestLayoutsOldSetupCustomRSS(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+disableKinds = ["taxonomy", "term", "page"]
+[outputs]
+home = ["rss"]
+-- layouts/_default/list.rss.xml --
+List RSS.
+`
+ b := hugolib.Test(t, files)
+ b.AssertFileContent("public/index.xml", "List RSS.")
+}
+
+func TestLayoutWithLanguagesLegacy(t *testing.T) {
+ t.Parallel()
+ files := `
+-- hugo.toml --
+disableKinds = ["taxonomy", "term", "sitemap", "rss"]
+defaultContentLanguage = "en"
+defaultContentLanguageInSubdir = true
+[languages]
+[languages.en]
+weight = 1
+[languages.nn]
+weight = 2
+[languages.sv]
+weight = 3
+-- layouts/_default/single.en.html --
+layouts/_default/single.html
+-- layouts/_default/single.nn.html --
+layouts/_default/single.nn.html
+-- layouts/_default/single.sv.html --
+layouts/_default/single.sv.html
+-- content/p1.md --
+---
+title: "P1"
+---
+-- content/p1.nn.md --
+---
+title: "P1 NN"
+---
+-- content/p1.sv.md --
+---
+title: "P1 SV"
+---
+`
+ b := hugolib.Test(t, files)
+
+ b.AssertFileContent("public/en/p1/index.html", "layouts/_default/single.html")
+ b.AssertFileContent("public/nn/p1/index.html", "layouts/_default/single.nn.html")
+ b.AssertFileContent("public/sv/p1/index.html", "layouts/_default/single.sv.html")
+}
+
+func TestLayoutWithLanguagesLegacyMounts(t *testing.T) {
+ t.Parallel()
+ files := `
+-- hugo.toml --
+disableKinds = ["taxonomy", "term", "sitemap", "rss"]
+defaultContentLanguage = "en"
+defaultContentLanguageInSubdir = true
+[languages]
+[languages.en]
+weight = 1
+[languages.nn]
+weight = 2
+[languages.sv]
+weight = 3
+
+
+[[module.mounts]]
+source = 'layouts/en'
+target = 'layouts'
+lang = 'en'
+
+[[module.mounts]]
+source = 'layouts/nn'
+target = 'layouts'
+lang = 'nn'
+[[module.mounts]]
+source = 'layouts/sv'
+target = 'layouts'
+lang = 'sv'
+
+-- layouts/en/_default/single.html --
+layouts/en/_default/single.html
+-- layouts/nn/_default/single.html --
+layouts/nn/_default/single.html
+-- layouts/sv/_default/single.html --
+layouts/sv/_default/single.html
+-- content/p1.md --
+---
+title: "P1"
+---
+-- content/p1.nn.md --
+---
+title: "P1 NN"
+---
+-- content/p1.sv.md --
+---
+title: "P1 SV"
+---
+`
+ b := hugolib.Test(t, files)
+
+ b.AssertFileContent("public/en/p1/index.html", "layouts/en/_default/single.html")
+ b.AssertFileContent("public/nn/p1/index.html", "layouts/nn/_default/single.html")
+ b.AssertFileContent("public/sv/p1/index.html", "layouts/sv/_default/single.html")
+}
+
+func TestLegacyPartialIssue13599(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+-- layouts/partials/mypartial.html --
+Mypartial.
+-- layouts/index.html --
+mypartial: {{ template "partials/mypartial.html" . }}
+
+`
+ b := hugolib.Test(t, files)
+
+ b.AssertFileContent("public/index.html", "Mypartial.")
+}
---
title: "P1"
---
--- layouts/partials/counter.html --
+-- layouts/_partials/counter.html --
{{ if .Scratch.Get "counter" }}{{ .Scratch.Add "counter" 1 }}{{ else }}{{ .Scratch.Set "counter" 1 }}{{ end }}{{ return true }}
--- layouts/_default/single.html --
+-- layouts/single.html --
continue:{{ range seq 5 }}{{ if eq . 2 }}{{continue}}{{ end }}{{ . }}{{ end }}:END:
break:{{ range seq 5 }}{{ if eq . 2 }}{{break}}{{ end }}{{ . }}{{ end }}:END:
continue2:{{ range seq 5 }}{{ if eq . 2 }}{{ continue }}{{ end }}{{ . }}{{ end }}:END:
files := `
-- hugo.toml --
title = "Hugo"
--- layouts/index.html --
+-- layouts/home.html --
{{ with false }}{{ else with .Site }}{{ .Title }}{{ end }}|
`
b := hugolib.Test(t, files)
---
title: "S3P1"
---
--- layouts/_default/baseof.html --
+-- layouts/baseof.html --
{{ block "main" . }}{{ end }}
-- layouts/s1/single.html --
{{/* foo */}}
files := `
-- config.toml --
--- layouts/index.html --
+-- layouts/home.html --
{{ $m := dict "key" "value" }}
{{ $k := "" }}
{{ $v := "" }}
filesTemplate := `
-- config.toml --
SECURITYCONFIG
--- layouts/index.html --
+-- layouts/home.html --
<script>
var a = §§{{.Title }}§§;
</script>
shortname = 'foo'
[privacy.disqus]
disable = false
--- layouts/index.html --
+-- layouts/home.html --
{{ template "_internal/disqus.html" . }}
`
title: p2
---
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ .Title }}
`
[taxonomies]
series = 'series'
tag = 'tags'
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ template "_internal/opengraph.html" . }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ template "_internal/opengraph.html" . }}
-- content/s1/p1.md --
---
description = "m <em>n</em> and **o** can't."
[taxonomies]
tag = 'tags'
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ template "_internal/schema.html" . }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ template "_internal/schema.html" . }}
-- content/s1/p1.md --
---
description = "m <em>n</em> and **o** can't."
[params.social]
twitter = 'foo'
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ template "_internal/twitter_cards.html" . }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ template "_internal/twitter_cards.html" . }}
-- content/s1/p1.md --
---
disableKinds = ["taxonomy", "term", "rss", "404", "sitemap"]
[internal]
fastRenderMode = true
--- layouts/_default/baseof.html --
+-- layouts/baseof.html --
Baseof!
{{ block "main" . }}default{{ end }}
{{ with (templates.Defer (dict "key" "global")) }}
Now. {{ now }}
{{ end }}
--- layouts/_default/single.html --
+-- layouts/single.html --
{{ define "main" }}
Single.
{{ end }}
--- layouts/_default/list.html --
+-- layouts/list.html --
{{ define "main" }}
List.
{{ .Content }}
b := hugolib.TestRunning(t, files)
b.AssertFileContent("public/index.html", "Home!")
- b.EditFileReplaceAll("layouts/_default/baseof.html", "baseof", "Baseof!").Build()
+ b.EditFileReplaceAll("layouts/baseof.html", "baseof", "Baseof!").Build()
b.BuildPartial("/")
b.AssertFileContent("public/index.html", "Baseof!")
b.BuildPartial("/mybundle1/")
[markup.goldmark.parser.attribute]
title = true
block = true
--- layouts/_default/single.html --
+-- layouts/single.html --
_{{ markdownify .RawContent }}_
-- content/p1.md --
---
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ highlight "a" "b" 0 }}
`
b := hugolib.NewIntegrationTestBuilder(
Felix,a "malicious" cat,7
Bella,"an "evil" cat",9
Scar,"a "dead cat",11
--- layouts/index.html --
+-- layouts/home.html --
{{ $opts := dict "lazyQuotes" true }}
{{ $data := resources.Get "pets.csv" | transform.Unmarshal $opts }}
{{ printf "%v" $data | safeHTML }}
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ transform.ToMath "c = \\pm\\sqrt{a^2 + b^2}" }}
`
b := hugolib.Test(t, files)
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ transform.ToMath "c = \\foo{a^2 + b^2}" }}
`
b, err := hugolib.TestE(t, files, hugolib.TestOptWarn())
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ $opts := dict "throwOnError" false }}
{{ transform.ToMath "c = \\foo{a^2 + b^2}" $opts }}
`
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ with try (transform.ToMath "c = \\foo{a^2 + b^2}") }}
{{ with .Err }}
{{ warnf "error: %s" . }}
b, err := hugolib.TestE(t, files, hugolib.TestOptWarn())
b.Assert(err, qt.IsNil)
- b.AssertLogContains("WARN error: template: index.html:1:22: executing \"index.html\" at <transform.ToMath>: error calling ToMath: KaTeX parse error: Undefined control sequence: \\foo at position 5: c = \\̲f̲o̲o̲{a^2 + b^2}")
+ b.AssertLogContains("WARN error: template: home.html:1:22: executing \"home.html\" at <transform.ToMath>: error calling ToMath: KaTeX parse error: Undefined control sequence: \\foo at position 5: c = \\̲f̲o̲o̲{a^2 + b^2}")
})
// See issue 13239.
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ with transform.ToMath "c = \\pm\\sqrt{a^2 + b^2}" }}
{{ with .Err }}
{{ warnf "error: %s" . }}
inline = [['\(', '\)'], ['$', '$']]
-- content/p1.md --
P1_CONTENT
--- layouts/index.html --
+-- layouts/home.html --
Home.
--- layouts/_default/single.html --
+-- layouts/single.html --
Content: {{ .Content }}|
--- layouts/_default/_markup/render-passthrough.html --
+-- layouts/_markup/render-passthrough.html --
{{ $opts := dict "throwOnError" false "displayMode" true }}
{{ transform.ToMath .Inner $opts }}
`
Some inline $1+3$ math.
--- layouts/index.html --
+-- layouts/home.html --
Home.
--- layouts/_default/single.html --
+-- layouts/single.html --
Content: {{ .Content }}|
--- layouts/_default/_markup/render-passthrough.html --
+-- layouts/_markup/render-passthrough.html --
{{ $opts := dict "throwOnError" true "displayMode" true }}
{{- with try (transform.ToMath .Inner $opts ) }}
{{- with .Err }}
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ $macros := dict
"\\addBar" "\\bar{#1}"
"\\bold" "\\mathbf{#1}"
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
--- layouts/index.html --
+-- layouts/home.html --
{{ $yaml := "\n a:\n b: 1\n c:\n d: 2\n" }}
{{ $yaml | transform.Unmarshal | encoding.Jsonify }}
`
"style": "h2"
}
]
--- layouts/index.html --
+-- layouts/home.html --
{{ $markdown := resources.Get "sample.json" | transform.Unmarshal | transform.PortableText }}
Markdown: {{ $markdown }}|