2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
2015-12-10 17:19:38 -05:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2014-10-18 14:25:10 -04:00
|
|
|
package hugolib
|
|
|
|
|
|
|
|
import (
|
2017-02-20 03:33:35 -05:00
|
|
|
"fmt"
|
2020-12-02 07:23:25 -05:00
|
|
|
"testing"
|
2015-05-20 02:21:21 -04:00
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
qt "github.com/frankban/quicktest"
|
2014-10-18 14:25:10 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2017-02-20 03:33:35 -05:00
|
|
|
menuPageTemplate = `---
|
|
|
|
title: %q
|
|
|
|
weight: %d
|
2016-03-10 04:31:12 -05:00
|
|
|
menu:
|
2017-02-20 03:33:35 -05:00
|
|
|
%s:
|
2017-12-15 12:49:21 -05:00
|
|
|
title: %s
|
2017-02-20 03:33:35 -05:00
|
|
|
weight: %d
|
2016-03-10 04:31:12 -05:00
|
|
|
---
|
2017-02-20 03:33:35 -05:00
|
|
|
# Doc Menu
|
|
|
|
`
|
|
|
|
)
|
2014-12-16 06:08:16 -05:00
|
|
|
|
2021-07-20 06:10:22 -04:00
|
|
|
func TestMenusSectionPagesMenu(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
t.Parallel()
|
2015-05-28 17:05:13 -04:00
|
|
|
|
2017-02-20 03:33:35 -05:00
|
|
|
siteConfig := `
|
|
|
|
baseurl = "http://example.com/"
|
|
|
|
title = "Section Menu"
|
|
|
|
sectionPagesMenu = "sect"
|
|
|
|
`
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
b := newTestSitesBuilder(t).WithConfigFile("toml", siteConfig)
|
|
|
|
|
|
|
|
b.WithTemplates(
|
|
|
|
"partials/menu.html",
|
2017-12-15 12:49:21 -05:00
|
|
|
`{{- $p := .page -}}
|
2017-02-20 03:33:35 -05:00
|
|
|
{{- $m := .menu -}}
|
|
|
|
{{ range (index $p.Site.Menus $m) -}}
|
2017-12-15 12:49:21 -05:00
|
|
|
{{- .URL }}|{{ .Name }}|{{ .Title }}|{{ .Weight -}}|
|
2017-02-20 03:33:35 -05:00
|
|
|
{{- if $p.IsMenuCurrent $m . }}IsMenuCurrent{{ else }}-{{ end -}}|
|
|
|
|
{{- if $p.HasMenuCurrent $m . }}HasMenuCurrent{{ else }}-{{ end -}}|
|
|
|
|
{{- end -}}
|
|
|
|
`,
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
"_default/single.html",
|
2017-02-20 03:33:35 -05:00
|
|
|
`Single|{{ .Title }}
|
|
|
|
Menu Sect: {{ partial "menu.html" (dict "page" . "menu" "sect") }}
|
|
|
|
Menu Main: {{ partial "menu.html" (dict "page" . "menu" "main") }}`,
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
"_default/list.html", "List|{{ .Title }}|{{ .Content }}",
|
2017-02-04 22:20:06 -05:00
|
|
|
)
|
2015-05-09 14:54:11 -04:00
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
b.WithContent(
|
|
|
|
"sect1/p1.md", fmt.Sprintf(menuPageTemplate, "p1", 1, "main", "atitle1", 40),
|
|
|
|
"sect1/p2.md", fmt.Sprintf(menuPageTemplate, "p2", 2, "main", "atitle2", 30),
|
|
|
|
"sect2/p3.md", fmt.Sprintf(menuPageTemplate, "p3", 3, "main", "atitle3", 20),
|
|
|
|
"sect2/p4.md", fmt.Sprintf(menuPageTemplate, "p4", 4, "main", "atitle4", 10),
|
|
|
|
"sect3/p5.md", fmt.Sprintf(menuPageTemplate, "p5", 5, "main", "atitle5", 5),
|
|
|
|
"sect1/_index.md", newTestPage("Section One", "2017-01-01", 100),
|
|
|
|
"sect5/_index.md", newTestPage("Section Five", "2017-01-01", 10),
|
|
|
|
)
|
2016-02-07 06:34:43 -05:00
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
b.Build(BuildCfg{})
|
|
|
|
h := b.H
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2017-02-20 03:33:35 -05:00
|
|
|
s := h.Sites[0]
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(len(s.Menus()), qt.Equals, 2)
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
p1 := s.RegularPages()[0].Menus()
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2017-02-20 03:33:35 -05:00
|
|
|
// There is only one menu in the page, but it is "member of" 2
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(len(p1), qt.Equals, 1)
|
2016-07-28 03:30:58 -04:00
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
b.AssertFileContent("public/sect1/p1/index.html", "Single",
|
2017-12-15 12:49:21 -05:00
|
|
|
"Menu Sect: "+
|
2019-04-19 03:18:12 -04:00
|
|
|
"/sect5/|Section Five|Section Five|10|-|-|"+
|
|
|
|
"/sect1/|Section One|Section One|100|-|HasMenuCurrent|"+
|
|
|
|
"/sect2/|Sect2s|Sect2s|0|-|-|"+
|
|
|
|
"/sect3/|Sect3s|Sect3s|0|-|-|",
|
2017-12-15 12:49:21 -05:00
|
|
|
"Menu Main: "+
|
|
|
|
"/sect3/p5/|p5|atitle5|5|-|-|"+
|
|
|
|
"/sect2/p4/|p4|atitle4|10|-|-|"+
|
|
|
|
"/sect2/p3/|p3|atitle3|20|-|-|"+
|
|
|
|
"/sect1/p2/|p2|atitle2|30|-|-|"+
|
|
|
|
"/sect1/p1/|p1|atitle1|40|IsMenuCurrent|-|",
|
2017-02-20 03:33:35 -05:00
|
|
|
)
|
2014-10-18 14:25:10 -04:00
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
b.AssertFileContent("public/sect2/p3/index.html", "Single",
|
2017-12-15 12:49:21 -05:00
|
|
|
"Menu Sect: "+
|
2019-04-19 03:18:12 -04:00
|
|
|
"/sect5/|Section Five|Section Five|10|-|-|"+
|
|
|
|
"/sect1/|Section One|Section One|100|-|-|"+
|
|
|
|
"/sect2/|Sect2s|Sect2s|0|-|HasMenuCurrent|"+
|
|
|
|
"/sect3/|Sect3s|Sect3s|0|-|-|")
|
2014-10-18 14:25:10 -04:00
|
|
|
}
|
2019-04-12 03:50:36 -04:00
|
|
|
|
2021-05-23 04:42:01 -04:00
|
|
|
// related issue #7594
|
2021-07-20 06:10:22 -04:00
|
|
|
func TestMenusSort(t *testing.T) {
|
2021-05-23 04:42:01 -04:00
|
|
|
b := newTestSitesBuilder(t).WithSimpleConfigFile()
|
|
|
|
|
|
|
|
b.WithTemplatesAdded("index.html", `
|
|
|
|
{{ range $k, $v := .Site.Menus.main }}
|
|
|
|
Default1|{{ $k }}|{{ $v.Weight }}|{{ $v.Name }}|{{ .URL }}|{{ $v.Page }}{{ end }}
|
|
|
|
{{ range $k, $v := .Site.Menus.main.ByWeight }}
|
|
|
|
ByWeight|{{ $k }}|{{ $v.Weight }}|{{ $v.Name }}|{{ .URL }}|{{ $v.Page }}{{ end }}
|
|
|
|
{{ range $k, $v := (.Site.Menus.main.ByWeight).Reverse }}
|
|
|
|
Reverse|{{ $k }}|{{ $v.Weight }}|{{ $v.Name }}|{{ .URL }}|{{ $v.Page }}{{ end }}
|
|
|
|
{{ range $k, $v := .Site.Menus.main }}
|
|
|
|
Default2|{{ $k }}|{{ $v.Weight }}|{{ $v.Name }}|{{ .URL }}|{{ $v.Page }}{{ end }}
|
|
|
|
{{ range $k, $v := .Site.Menus.main.ByWeight }}
|
|
|
|
ByWeight|{{ $k }}|{{ $v.Weight }}|{{ $v.Name }}|{{ .URL }}|{{ $v.Page }}{{ end }}
|
|
|
|
{{ range $k, $v := .Site.Menus.main }}
|
|
|
|
Default3|{{ $k }}|{{ $v.Weight }}|{{ $v.Name }}|{{ .URL }}|{{ $v.Page }}{{ end }}
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("_index.md", `
|
|
|
|
---
|
|
|
|
title: Home
|
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
weight: 100
|
|
|
|
---`)
|
|
|
|
|
|
|
|
b.WithContent("blog/A.md", `
|
|
|
|
---
|
|
|
|
title: "A"
|
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
weight: 10
|
|
|
|
---
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/B.md", `
|
|
|
|
---
|
|
|
|
title: "B"
|
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
weight: 20
|
|
|
|
---
|
|
|
|
`)
|
|
|
|
b.WithContent("blog/C.md", `
|
|
|
|
---
|
|
|
|
title: "C"
|
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
weight: 30
|
|
|
|
---
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
|
|
|
b.AssertFileContent("public/index.html",
|
|
|
|
`Default1|0|10|A|/blog/a/|Page(/blog/A.md)
|
|
|
|
Default1|1|20|B|/blog/b/|Page(/blog/B.md)
|
|
|
|
Default1|2|30|C|/blog/c/|Page(/blog/C.md)
|
|
|
|
Default1|3|100|Home|/|Page(/_index.md)
|
|
|
|
|
|
|
|
ByWeight|0|10|A|/blog/a/|Page(/blog/A.md)
|
|
|
|
ByWeight|1|20|B|/blog/b/|Page(/blog/B.md)
|
|
|
|
ByWeight|2|30|C|/blog/c/|Page(/blog/C.md)
|
|
|
|
ByWeight|3|100|Home|/|Page(/_index.md)
|
|
|
|
|
|
|
|
Reverse|0|100|Home|/|Page(/_index.md)
|
|
|
|
Reverse|1|30|C|/blog/c/|Page(/blog/C.md)
|
|
|
|
Reverse|2|20|B|/blog/b/|Page(/blog/B.md)
|
|
|
|
Reverse|3|10|A|/blog/a/|Page(/blog/A.md)
|
|
|
|
|
|
|
|
Default2|0|10|A|/blog/a/|Page(/blog/A.md)
|
|
|
|
Default2|1|20|B|/blog/b/|Page(/blog/B.md)
|
|
|
|
Default2|2|30|C|/blog/c/|Page(/blog/C.md)
|
|
|
|
Default2|3|100|Home|/|Page(/_index.md)
|
|
|
|
|
|
|
|
ByWeight|0|10|A|/blog/a/|Page(/blog/A.md)
|
|
|
|
ByWeight|1|20|B|/blog/b/|Page(/blog/B.md)
|
|
|
|
ByWeight|2|30|C|/blog/c/|Page(/blog/C.md)
|
|
|
|
ByWeight|3|100|Home|/|Page(/_index.md)
|
|
|
|
|
|
|
|
Default3|0|10|A|/blog/a/|Page(/blog/A.md)
|
|
|
|
Default3|1|20|B|/blog/b/|Page(/blog/B.md)
|
|
|
|
Default3|2|30|C|/blog/c/|Page(/blog/C.md)
|
|
|
|
Default3|3|100|Home|/|Page(/_index.md)`,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-07-20 06:10:22 -04:00
|
|
|
func TestMenusFrontMatter(t *testing.T) {
|
2019-04-12 03:50:36 -04:00
|
|
|
b := newTestSitesBuilder(t).WithSimpleConfigFile()
|
|
|
|
|
|
|
|
b.WithTemplatesAdded("index.html", `
|
|
|
|
Main: {{ len .Site.Menus.main }}
|
|
|
|
Other: {{ len .Site.Menus.other }}
|
|
|
|
{{ range .Site.Menus.main }}
|
|
|
|
* Main|{{ .Name }}: {{ .URL }}
|
|
|
|
{{ end }}
|
|
|
|
{{ range .Site.Menus.other }}
|
|
|
|
* Other|{{ .Name }}: {{ .URL }}
|
|
|
|
{{ end }}
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Issue #5828
|
|
|
|
b.WithContent("blog/page1.md", `
|
|
|
|
---
|
|
|
|
title: "P1"
|
|
|
|
menu: main
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/page2.md", `
|
|
|
|
---
|
|
|
|
title: "P2"
|
|
|
|
menu: [main,other]
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/page3.md", `
|
|
|
|
---
|
|
|
|
title: "P3"
|
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
weight: 30
|
|
|
|
---
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
|
|
|
b.AssertFileContent("public/index.html",
|
|
|
|
"Main: 3", "Other: 1",
|
|
|
|
"Main|P1: /blog/page1/",
|
|
|
|
"Other|P2: /blog/page2/",
|
|
|
|
)
|
|
|
|
}
|
2019-04-19 03:18:12 -04:00
|
|
|
|
|
|
|
// https://github.com/gohugoio/hugo/issues/5849
|
2021-07-20 06:10:22 -04:00
|
|
|
func TestMenusPageMultipleOutputFormats(t *testing.T) {
|
2019-04-19 03:18:12 -04:00
|
|
|
config := `
|
|
|
|
baseURL = "https://example.com"
|
|
|
|
|
|
|
|
# DAMP is similar to AMP, but not permalinkable.
|
|
|
|
[outputFormats]
|
|
|
|
[outputFormats.damp]
|
|
|
|
mediaType = "text/html"
|
|
|
|
path = "damp"
|
|
|
|
|
|
|
|
`
|
|
|
|
|
|
|
|
b := newTestSitesBuilder(t).WithConfigFile("toml", config)
|
|
|
|
b.WithContent("_index.md", `
|
|
|
|
---
|
|
|
|
Title: Home Sweet Home
|
|
|
|
outputs: [ "html", "amp" ]
|
|
|
|
menu: "main"
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/html-amp.md", `
|
|
|
|
---
|
|
|
|
Title: AMP and HTML
|
|
|
|
outputs: [ "html", "amp" ]
|
|
|
|
menu: "main"
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/html.md", `
|
|
|
|
---
|
|
|
|
Title: HTML only
|
|
|
|
outputs: [ "html" ]
|
|
|
|
menu: "main"
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/amp.md", `
|
|
|
|
---
|
|
|
|
Title: AMP only
|
|
|
|
outputs: [ "amp" ]
|
|
|
|
menu: "main"
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithTemplatesAdded("index.html", `{{ range .Site.Menus.main }}{{ .Title }}|{{ .URL }}|{{ end }}`)
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
2019-08-01 04:19:19 -04:00
|
|
|
b.AssertFileContent("public/index.html", "AMP and HTML|/blog/html-amp/|AMP only|/amp/blog/amp/|Home Sweet Home|/|HTML only|/blog/html/|")
|
|
|
|
b.AssertFileContent("public/amp/index.html", "AMP and HTML|/amp/blog/html-amp/|AMP only|/amp/blog/amp/|Home Sweet Home|/amp/|HTML only|/blog/html/|")
|
2019-04-19 03:18:12 -04:00
|
|
|
}
|
2019-05-27 16:57:57 -04:00
|
|
|
|
|
|
|
// https://github.com/gohugoio/hugo/issues/5989
|
2021-07-20 06:10:22 -04:00
|
|
|
func TestMenusPageSortByDate(t *testing.T) {
|
2019-05-27 16:57:57 -04:00
|
|
|
b := newTestSitesBuilder(t).WithSimpleConfigFile()
|
|
|
|
|
|
|
|
b.WithContent("blog/a.md", `
|
|
|
|
---
|
|
|
|
Title: A
|
|
|
|
date: 2019-01-01
|
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
identifier: "a"
|
|
|
|
weight: 1
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/b.md", `
|
|
|
|
---
|
|
|
|
Title: B
|
|
|
|
date: 2018-01-02
|
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
parent: "a"
|
|
|
|
weight: 100
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/c.md", `
|
|
|
|
---
|
|
|
|
Title: C
|
|
|
|
date: 2019-01-03
|
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
parent: "a"
|
|
|
|
weight: 10
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithTemplatesAdded("index.html", `{{ range .Site.Menus.main }}{{ .Title }}|Children:
|
|
|
|
{{- $children := sort .Children ".Page.Date" "desc" }}{{ range $children }}{{ .Title }}|{{ end }}{{ end }}
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
|
|
|
b.AssertFileContent("public/index.html", "A|Children:C|B|")
|
|
|
|
}
|
2020-11-22 16:09:59 -05:00
|
|
|
|
2021-07-30 04:56:45 -04:00
|
|
|
// Issue #8825
|
|
|
|
func TestMenuParamsEmptyYaml(t *testing.T) {
|
|
|
|
b := newTestSitesBuilder(t).WithConfigFile("yaml", `
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithTemplates("index.html", `{{ site.Menus }}`)
|
|
|
|
|
|
|
|
b.WithContent("p1.md", `---
|
|
|
|
menus:
|
|
|
|
main:
|
|
|
|
identity: journal
|
|
|
|
weight: 2
|
|
|
|
params:
|
|
|
|
---
|
|
|
|
`)
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
}
|
|
|
|
|
2020-11-22 16:09:59 -05:00
|
|
|
func TestMenuParams(t *testing.T) {
|
2021-07-20 05:32:50 -04:00
|
|
|
b := newTestSitesBuilder(t).WithConfigFile("toml", `
|
|
|
|
[[menus.main]]
|
|
|
|
identifier = "contact"
|
|
|
|
title = "Contact Us"
|
|
|
|
url = "mailto:noreply@example.com"
|
|
|
|
weight = 300
|
|
|
|
[menus.main.params]
|
|
|
|
foo = "foo_config"
|
|
|
|
key2 = "key2_config"
|
|
|
|
camelCase = "camelCase_config"
|
|
|
|
`)
|
2020-11-22 16:09:59 -05:00
|
|
|
|
|
|
|
b.WithTemplatesAdded("index.html", `
|
|
|
|
Main: {{ len .Site.Menus.main }}
|
|
|
|
{{ range .Site.Menus.main }}
|
2021-07-20 05:32:50 -04:00
|
|
|
foo: {{ .Params.foo }}
|
|
|
|
key2: {{ .Params.KEy2 }}
|
|
|
|
camelCase: {{ .Params.camelcase }}
|
2020-11-22 16:09:59 -05:00
|
|
|
{{ end }}
|
|
|
|
`)
|
|
|
|
|
2021-07-20 05:32:50 -04:00
|
|
|
b.WithContent("_index.md", `
|
2020-11-22 16:09:59 -05:00
|
|
|
---
|
2021-07-20 05:32:50 -04:00
|
|
|
title: "Home"
|
2020-11-22 16:09:59 -05:00
|
|
|
menu:
|
|
|
|
main:
|
2021-07-20 05:32:50 -04:00
|
|
|
weight: 10
|
2020-11-22 16:09:59 -05:00
|
|
|
params:
|
2021-07-20 05:32:50 -04:00
|
|
|
foo: "foo_content"
|
|
|
|
key2: "key2_content"
|
|
|
|
camelCase: "camelCase_content"
|
2020-11-22 16:09:59 -05:00
|
|
|
---
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
2021-07-20 05:32:50 -04:00
|
|
|
b.AssertFileContent("public/index.html", `
|
|
|
|
Main: 2
|
|
|
|
|
|
|
|
foo: foo_content
|
|
|
|
key2: key2_content
|
|
|
|
camelCase: camelCase_content
|
|
|
|
|
|
|
|
foo: foo_config
|
|
|
|
key2: key2_config
|
|
|
|
camelCase: camelCase_config
|
|
|
|
`)
|
2020-11-22 16:09:59 -05:00
|
|
|
}
|
2021-07-20 06:10:22 -04:00
|
|
|
|
|
|
|
func TestMenusShadowMembers(t *testing.T) {
|
|
|
|
b := newTestSitesBuilder(t).WithConfigFile("toml", `
|
|
|
|
[[menus.main]]
|
|
|
|
identifier = "contact"
|
|
|
|
pageRef = "contact"
|
|
|
|
title = "Contact Us"
|
|
|
|
url = "mailto:noreply@example.com"
|
|
|
|
weight = 1
|
|
|
|
[[menus.main]]
|
|
|
|
pageRef = "/blog/post3"
|
|
|
|
title = "My Post 3"
|
|
|
|
url = "/blog/post3"
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
commonTempl := `
|
|
|
|
Main: {{ len .Site.Menus.main }}
|
|
|
|
{{ range .Site.Menus.main }}
|
|
|
|
{{ .Title }}|HasMenuCurrent: {{ $.HasMenuCurrent "main" . }}|Page: {{ .Page }}
|
|
|
|
{{ .Title }}|IsMenuCurrent: {{ $.IsMenuCurrent "main" . }}|Page: {{ .Page }}
|
|
|
|
{{ end }}
|
|
|
|
`
|
|
|
|
|
|
|
|
b.WithTemplatesAdded("index.html", commonTempl)
|
|
|
|
b.WithTemplatesAdded("_default/single.html", commonTempl)
|
|
|
|
|
|
|
|
b.WithContent("_index.md", `
|
|
|
|
---
|
|
|
|
title: "Home"
|
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
weight: 10
|
|
|
|
---
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/_index.md", `
|
|
|
|
---
|
|
|
|
title: "Blog"
|
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
weight: 20
|
|
|
|
---
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/post1.md", `
|
|
|
|
---
|
|
|
|
title: "My Post 1: With No Menu Defined"
|
|
|
|
---
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/post2.md", `
|
|
|
|
---
|
|
|
|
title: "My Post 2: With Menu Defined"
|
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
weight: 30
|
|
|
|
---
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/post3.md", `
|
|
|
|
---
|
|
|
|
title: "My Post 2: With No Menu Defined"
|
|
|
|
---
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("contact.md", `
|
|
|
|
---
|
|
|
|
title: "Contact: With No Menu Defined"
|
|
|
|
---
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
|
|
|
b.AssertFileContent("public/index.html", `
|
|
|
|
Main: 5
|
|
|
|
Home|HasMenuCurrent: false|Page: Page(/_index.md)
|
|
|
|
Blog|HasMenuCurrent: false|Page: Page(/blog/_index.md)
|
|
|
|
My Post 2: With Menu Defined|HasMenuCurrent: false|Page: Page(/blog/post2.md)
|
|
|
|
My Post 3|HasMenuCurrent: false|Page: Page(/blog/post3.md)
|
|
|
|
Contact Us|HasMenuCurrent: false|Page: Page(/contact.md)
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.AssertFileContent("public/blog/post1/index.html", `
|
|
|
|
Home|HasMenuCurrent: false|Page: Page(/_index.md)
|
|
|
|
Blog|HasMenuCurrent: true|Page: Page(/blog/_index.md)
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.AssertFileContent("public/blog/post2/index.html", `
|
|
|
|
Home|HasMenuCurrent: false|Page: Page(/_index.md)
|
|
|
|
Blog|HasMenuCurrent: true|Page: Page(/blog/_index.md)
|
|
|
|
Blog|IsMenuCurrent: false|Page: Page(/blog/_index.md)
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.AssertFileContent("public/blog/post3/index.html", `
|
|
|
|
Home|HasMenuCurrent: false|Page: Page(/_index.md)
|
|
|
|
Blog|HasMenuCurrent: true|Page: Page(/blog/_index.md)
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.AssertFileContent("public/contact/index.html", `
|
|
|
|
Contact Us|HasMenuCurrent: false|Page: Page(/contact.md)
|
|
|
|
Contact Us|IsMenuCurrent: true|Page: Page(/contact.md)
|
|
|
|
Blog|HasMenuCurrent: false|Page: Page(/blog/_index.md)
|
|
|
|
Blog|IsMenuCurrent: false|Page: Page(/blog/_index.md)
|
|
|
|
`)
|
|
|
|
}
|
2022-05-25 12:46:42 -04:00
|
|
|
|
|
|
|
// Issue 9846
|
|
|
|
func TestMenuHasMenuCurrentSection(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
files := `
|
|
|
|
-- config.toml --
|
|
|
|
disableKinds = ['RSS','sitemap','taxonomy','term']
|
|
|
|
[[menu.main]]
|
|
|
|
name = 'Home'
|
|
|
|
pageRef = '/'
|
|
|
|
weight = 1
|
|
|
|
|
|
|
|
[[menu.main]]
|
|
|
|
name = 'Tests'
|
|
|
|
pageRef = '/tests'
|
|
|
|
weight = 2
|
|
|
|
[[menu.main]]
|
|
|
|
name = 'Test 1'
|
|
|
|
pageRef = '/tests/test-1'
|
|
|
|
parent = 'Tests'
|
|
|
|
weight = 1
|
|
|
|
|
|
|
|
-- content/tests/test-1.md --
|
|
|
|
---
|
|
|
|
title: "Test 1"
|
|
|
|
---
|
|
|
|
-- layouts/_default/list.html --
|
|
|
|
{{ range site.Menus.main }}
|
|
|
|
{{ .Name }}|{{ .URL }}|IsMenuCurrent = {{ $.IsMenuCurrent "main" . }}|HasMenuCurrent = {{ $.HasMenuCurrent "main" . }}|
|
|
|
|
{{ range .Children }}
|
|
|
|
{{ .Name }}|{{ .URL }}|IsMenuCurrent = {{ $.IsMenuCurrent "main" . }}|HasMenuCurrent = {{ $.HasMenuCurrent "main" . }}|
|
|
|
|
{{ end }}
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
{{/* Some tests for issue 9925 */}}
|
|
|
|
{{ $page := .Site.GetPage "tests/test-1" }}
|
|
|
|
{{ $section := site.GetPage "tests" }}
|
|
|
|
|
|
|
|
Home IsAncestor Self: {{ site.Home.IsAncestor site.Home }}
|
|
|
|
Home IsDescendant Self: {{ site.Home.IsDescendant site.Home }}
|
|
|
|
Section IsAncestor Self: {{ $section.IsAncestor $section }}
|
|
|
|
Section IsDescendant Self: {{ $section.IsDescendant $section}}
|
|
|
|
Page IsAncestor Self: {{ $page.IsAncestor $page }}
|
|
|
|
Page IsDescendant Self: {{ $page.IsDescendant $page}}
|
|
|
|
`
|
|
|
|
|
|
|
|
b := NewIntegrationTestBuilder(
|
|
|
|
IntegrationTestConfig{
|
|
|
|
T: t,
|
|
|
|
TxtarString: files,
|
|
|
|
},
|
|
|
|
).Build()
|
|
|
|
|
|
|
|
b.AssertFileContent("public/tests/index.html", `
|
|
|
|
Tests|/tests/|IsMenuCurrent = true|HasMenuCurrent = false
|
|
|
|
Home IsAncestor Self: false
|
|
|
|
Home IsDescendant Self: false
|
|
|
|
Section IsAncestor Self: false
|
|
|
|
Section IsDescendant Self: false
|
|
|
|
Page IsAncestor Self: false
|
|
|
|
Page IsDescendant Self: false
|
|
|
|
`)
|
|
|
|
}
|
2023-01-04 12:24:36 -05:00
|
|
|
|
|
|
|
func TestMenusNewConfigSetup(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
files := `
|
|
|
|
-- hugo.toml --
|
|
|
|
baseURL = "https://example.com"
|
|
|
|
title = "Hugo Menu Test"
|
|
|
|
[menus]
|
|
|
|
[[menus.main]]
|
|
|
|
name = "Home"
|
|
|
|
url = "/"
|
|
|
|
pre = "<span>"
|
|
|
|
post = "</span>"
|
|
|
|
weight = 1
|
|
|
|
-- layouts/index.html --
|
|
|
|
{{ range $i, $e := site.Menus.main }}
|
|
|
|
Menu Item: {{ $i }}: {{ .Pre }}{{ .Name }}{{ .Post }}|{{ .URL }}|
|
|
|
|
{{ end }}
|
|
|
|
`
|
|
|
|
|
|
|
|
b := NewIntegrationTestBuilder(
|
|
|
|
IntegrationTestConfig{
|
|
|
|
T: t,
|
|
|
|
TxtarString: files,
|
|
|
|
},
|
|
|
|
).Build()
|
|
|
|
|
|
|
|
b.AssertFileContent("public/index.html", `
|
|
|
|
Menu Item: 0: <span>Home</span>|/|
|
|
|
|
`)
|
|
|
|
|
|
|
|
}
|