2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
2017-03-07 08:20:39 -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.
|
|
|
|
|
|
|
|
package hugolib
|
|
|
|
|
|
|
|
import (
|
2017-03-22 04:54:56 -04:00
|
|
|
"strings"
|
2017-03-07 08:20:39 -05:00
|
|
|
"testing"
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
qt "github.com/frankban/quicktest"
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/resources/page"
|
|
|
|
|
2017-03-27 14:43:49 -04:00
|
|
|
"github.com/spf13/afero"
|
|
|
|
|
2017-03-08 07:45:33 -05:00
|
|
|
"fmt"
|
|
|
|
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/helpers"
|
|
|
|
"github.com/gohugoio/hugo/output"
|
2017-03-09 13:19:29 -05:00
|
|
|
"github.com/spf13/viper"
|
2017-03-07 08:20:39 -05:00
|
|
|
)
|
|
|
|
|
2017-03-22 04:54:56 -04:00
|
|
|
func TestSiteWithPageOutputs(t *testing.T) {
|
2017-03-23 15:05:10 -04:00
|
|
|
for _, outputs := range [][]string{{"html", "json", "calendar"}, {"json"}} {
|
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
|
|
|
outputs := outputs
|
2017-03-22 04:54:56 -04:00
|
|
|
t.Run(fmt.Sprintf("%v", outputs), func(t *testing.T) {
|
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
|
|
|
t.Parallel()
|
2017-03-22 04:54:56 -04:00
|
|
|
doTestSiteWithPageOutputs(t, outputs)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func doTestSiteWithPageOutputs(t *testing.T, outputs []string) {
|
2017-03-08 07:45:33 -05:00
|
|
|
|
2017-03-22 04:54:56 -04:00
|
|
|
outputsStr := strings.Replace(fmt.Sprintf("%q", outputs), " ", ", ", -1)
|
|
|
|
|
2017-03-08 07:45:33 -05:00
|
|
|
siteConfig := `
|
|
|
|
baseURL = "http://example.com/blog"
|
|
|
|
|
|
|
|
paginate = 1
|
|
|
|
defaultContentLanguage = "en"
|
|
|
|
|
2020-06-16 09:43:50 -04:00
|
|
|
disableKinds = ["section", "term", "taxonomy", "RSS", "sitemap", "robotsTXT", "404"]
|
2017-03-08 07:45:33 -05:00
|
|
|
|
|
|
|
[Taxonomies]
|
|
|
|
tag = "tags"
|
|
|
|
category = "categories"
|
2017-03-27 14:43:49 -04:00
|
|
|
|
|
|
|
defaultContentLanguage = "en"
|
|
|
|
|
2018-07-06 07:33:43 -04:00
|
|
|
|
2017-03-27 14:43:49 -04:00
|
|
|
[languages]
|
|
|
|
|
|
|
|
[languages.en]
|
|
|
|
title = "Title in English"
|
|
|
|
languageName = "English"
|
|
|
|
weight = 1
|
|
|
|
|
|
|
|
[languages.nn]
|
|
|
|
languageName = "Nynorsk"
|
|
|
|
weight = 2
|
|
|
|
title = "Tittel på Nynorsk"
|
|
|
|
|
2017-03-08 07:45:33 -05:00
|
|
|
`
|
|
|
|
|
|
|
|
pageTemplate := `---
|
|
|
|
title: "%s"
|
2017-03-22 04:54:56 -04:00
|
|
|
outputs: %s
|
2017-03-08 07:45:33 -05:00
|
|
|
---
|
|
|
|
# Doc
|
2017-05-06 14:15:28 -04:00
|
|
|
|
|
|
|
{{< myShort >}}
|
2017-09-13 06:32:06 -04:00
|
|
|
|
|
|
|
{{< myOtherShort >}}
|
|
|
|
|
2017-03-08 07:45:33 -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 := newTestSitesBuilder(t).WithConfigFile("toml", siteConfig)
|
|
|
|
b.WithI18n("en.toml", `
|
2017-03-27 14:43:49 -04:00
|
|
|
[elbow]
|
|
|
|
other = "Elbow"
|
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
|
|
|
`, "nn.toml", `
|
2017-03-27 14:43:49 -04:00
|
|
|
[elbow]
|
|
|
|
other = "Olboge"
|
|
|
|
`)
|
|
|
|
|
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.WithTemplates(
|
2017-04-12 15:01:22 -04:00
|
|
|
// Case issue partials #3333
|
|
|
|
"layouts/partials/GoHugo.html", `Go Hugo Partial`,
|
2017-03-27 14:43:49 -04:00
|
|
|
"layouts/_default/baseof.json", `START JSON:{{block "main" .}}default content{{ end }}:END JSON`,
|
|
|
|
"layouts/_default/baseof.html", `START HTML:{{block "main" .}}default content{{ end }}:END HTML`,
|
2017-09-13 06:32:06 -04:00
|
|
|
"layouts/shortcodes/myOtherShort.html", `OtherShort: {{ "<h1>Hi!</h1>" | safeHTML }}`,
|
2017-05-06 14:15:28 -04:00
|
|
|
"layouts/shortcodes/myShort.html", `ShortHTML`,
|
|
|
|
"layouts/shortcodes/myShort.json", `ShortJSON`,
|
2017-03-27 14:43:49 -04:00
|
|
|
|
|
|
|
"layouts/_default/list.json", `{{ define "main" }}
|
|
|
|
List JSON|{{ .Title }}|{{ .Content }}|Alt formats: {{ len .AlternativeOutputFormats -}}|
|
2017-03-22 04:54:56 -04:00
|
|
|
{{- range .AlternativeOutputFormats -}}
|
|
|
|
Alt Output: {{ .Name -}}|
|
|
|
|
{{- end -}}|
|
|
|
|
{{- range .OutputFormats -}}
|
2017-03-27 14:43:49 -04:00
|
|
|
Output/Rel: {{ .Name -}}/{{ .Rel }}|{{ .MediaType }}
|
|
|
|
{{- end -}}
|
|
|
|
{{ with .OutputFormats.Get "JSON" }}
|
|
|
|
<atom:link href={{ .Permalink }} rel="self" type="{{ .MediaType }}" />
|
|
|
|
{{ end }}
|
|
|
|
{{ .Site.Language.Lang }}: {{ T "elbow" -}}
|
|
|
|
{{ end }}
|
|
|
|
`,
|
|
|
|
"layouts/_default/list.html", `{{ define "main" }}
|
|
|
|
List HTML|{{.Title }}|
|
|
|
|
{{- with .OutputFormats.Get "HTML" -}}
|
|
|
|
<atom:link href={{ .Permalink }} rel="self" type="{{ .MediaType }}" />
|
2017-03-22 04:54:56 -04:00
|
|
|
{{- end -}}
|
2017-03-27 14:43:49 -04:00
|
|
|
{{ .Site.Language.Lang }}: {{ T "elbow" -}}
|
2017-04-12 15:01:22 -04:00
|
|
|
Partial Hugo 1: {{ partial "GoHugo.html" . }}
|
|
|
|
Partial Hugo 2: {{ partial "GoHugo" . -}}
|
2017-05-06 14:15:28 -04:00
|
|
|
Content: {{ .Content }}
|
2018-07-06 07:33:43 -04:00
|
|
|
Len Pages: {{ .Kind }} {{ len .Site.RegularPages }} Page Number: {{ .Paginator.PageNumber }}
|
2017-03-27 14:43:49 -04:00
|
|
|
{{ end }}
|
2017-03-22 04:54:56 -04:00
|
|
|
`,
|
2018-07-06 07:33:43 -04:00
|
|
|
"layouts/_default/single.html", `{{ define "main" }}{{ .Content }}{{ end }}`,
|
2017-03-09 13:19:29 -05:00
|
|
|
)
|
2017-03-08 07:45:33 -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.WithContent("_index.md", fmt.Sprintf(pageTemplate, "JSON Home", outputsStr))
|
|
|
|
b.WithContent("_index.nn.md", fmt.Sprintf(pageTemplate, "JSON Nynorsk Heim", outputsStr))
|
2017-03-08 07:45:33 -05:00
|
|
|
|
2018-07-06 07:33:43 -04:00
|
|
|
for i := 1; i <= 10; i++ {
|
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(fmt.Sprintf("p%d.md", i), fmt.Sprintf(pageTemplate, fmt.Sprintf("Page %d", i), outputsStr))
|
2018-07-06 07:33:43 -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.Build(BuildCfg{})
|
2017-03-08 07:45:33 -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
|
|
|
s := b.H.Sites[0]
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(s.language.Lang, qt.Equals, "en")
|
2017-03-27 14:43:49 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
home := s.getPage(page.KindHome)
|
2017-03-08 07:45:33 -05:00
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(home, qt.Not(qt.IsNil))
|
2017-03-08 07:45:33 -05:00
|
|
|
|
2017-03-22 04:54:56 -04:00
|
|
|
lenOut := len(outputs)
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(len(home.OutputFormats()), qt.Equals, lenOut)
|
2017-03-08 07:45:33 -05:00
|
|
|
|
2017-03-22 04:54:56 -04:00
|
|
|
// There is currently always a JSON output to make it simpler ...
|
|
|
|
altFormats := lenOut - 1
|
|
|
|
hasHTML := helpers.InStringArray(outputs, "html")
|
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/index.json",
|
2017-03-22 04:54:56 -04:00
|
|
|
"List JSON",
|
|
|
|
fmt.Sprintf("Alt formats: %d", altFormats),
|
|
|
|
)
|
2017-03-09 13:19:29 -05:00
|
|
|
|
2017-03-22 04:54:56 -04:00
|
|
|
if hasHTML {
|
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/index.json",
|
2017-03-22 04:54:56 -04:00
|
|
|
"Alt Output: HTML",
|
|
|
|
"Output/Rel: JSON/alternate|",
|
|
|
|
"Output/Rel: HTML/canonical|",
|
2017-03-27 14:43:49 -04:00
|
|
|
"en: Elbow",
|
2017-05-06 14:15:28 -04:00
|
|
|
"ShortJSON",
|
2017-09-13 06:32:06 -04:00
|
|
|
"OtherShort: <h1>Hi!</h1>",
|
2017-03-27 14:43:49 -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/index.html",
|
2017-03-27 14:43:49 -04:00
|
|
|
// The HTML entity is a deliberate part of this test: The HTML templates are
|
|
|
|
// parsed with html/template.
|
2018-07-10 05:55:22 -04:00
|
|
|
`List HTML|JSON Home|<atom:link href=http://example.com/blog/ rel="self" type="text/html" />`,
|
2017-03-27 14:43:49 -04:00
|
|
|
"en: Elbow",
|
2017-05-06 14:15:28 -04:00
|
|
|
"ShortHTML",
|
2017-09-13 06:32:06 -04:00
|
|
|
"OtherShort: <h1>Hi!</h1>",
|
2018-07-06 07:33:43 -04:00
|
|
|
"Len Pages: home 10",
|
2017-03-22 04:54:56 -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/page/2/index.html", "Page Number: 2")
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(b.CheckExists("public/page/2/index.json"), qt.Equals, false)
|
2018-07-06 07:33:43 -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/nn/index.html",
|
2017-03-27 14:43:49 -04:00
|
|
|
"List HTML|JSON Nynorsk Heim|",
|
|
|
|
"nn: Olboge")
|
2017-03-22 04:54:56 -04:00
|
|
|
} else {
|
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/index.json",
|
2017-03-22 04:54:56 -04:00
|
|
|
"Output/Rel: JSON/canonical|",
|
2017-03-27 14:43:49 -04:00
|
|
|
// JSON is plain text, so no need to safeHTML this and that
|
2018-07-10 05:55:22 -04:00
|
|
|
`<atom:link href=http://example.com/blog/index.json rel="self" type="application/json" />`,
|
2017-05-06 14:15:28 -04:00
|
|
|
"ShortJSON",
|
2017-09-13 06:32:06 -04:00
|
|
|
"OtherShort: <h1>Hi!</h1>",
|
2017-03-27 14:43:49 -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/nn/index.json",
|
2017-03-27 14:43:49 -04:00
|
|
|
"List JSON|JSON Nynorsk Heim|",
|
|
|
|
"nn: Olboge",
|
2017-05-06 14:15:28 -04:00
|
|
|
"ShortJSON",
|
2017-03-22 04:54:56 -04:00
|
|
|
)
|
|
|
|
}
|
2017-03-08 07:45:33 -05:00
|
|
|
|
2017-03-21 19:25:55 -04:00
|
|
|
of := home.OutputFormats()
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2017-03-21 19:25:55 -04:00
|
|
|
json := of.Get("JSON")
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(json, qt.Not(qt.IsNil))
|
|
|
|
b.Assert(json.RelPermalink(), qt.Equals, "/blog/index.json")
|
|
|
|
b.Assert(json.Permalink(), qt.Equals, "http://example.com/blog/index.json")
|
2017-03-21 19:25:55 -04:00
|
|
|
|
2017-03-23 15:05:10 -04:00
|
|
|
if helpers.InStringArray(outputs, "cal") {
|
|
|
|
cal := of.Get("calendar")
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(cal, qt.Not(qt.IsNil))
|
|
|
|
b.Assert(cal.RelPermalink(), qt.Equals, "/blog/index.ics")
|
|
|
|
b.Assert(cal.Permalink(), qt.Equals, "webcal://example.com/blog/index.ics")
|
2017-03-23 15:05:10 -04:00
|
|
|
}
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(home.HasShortcode("myShort"), qt.Equals, true)
|
|
|
|
b.Assert(home.HasShortcode("doesNotExist"), qt.Equals, false)
|
2017-07-17 17:20:13 -04:00
|
|
|
|
2017-03-08 07:45:33 -05:00
|
|
|
}
|
2017-05-17 11:04:07 -04:00
|
|
|
|
|
|
|
// Issue #3447
|
|
|
|
func TestRedefineRSSOutputFormat(t *testing.T) {
|
|
|
|
siteConfig := `
|
|
|
|
baseURL = "http://example.com/blog"
|
|
|
|
|
|
|
|
paginate = 1
|
|
|
|
defaultContentLanguage = "en"
|
|
|
|
|
2020-06-16 09:43:50 -04:00
|
|
|
disableKinds = ["page", "section", "term", "taxonomy", "sitemap", "robotsTXT", "404"]
|
2017-05-17 11:04:07 -04:00
|
|
|
|
|
|
|
[outputFormats]
|
|
|
|
[outputFormats.RSS]
|
|
|
|
mediatype = "application/rss"
|
|
|
|
baseName = "feed"
|
|
|
|
|
|
|
|
`
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
|
|
|
|
2017-05-17 11:04:07 -04:00
|
|
|
mf := afero.NewMemMapFs()
|
|
|
|
writeToFs(t, mf, "content/foo.html", `foo`)
|
|
|
|
|
|
|
|
th, h := newTestSitesFromConfig(t, mf, siteConfig)
|
|
|
|
|
|
|
|
err := h.Build(BuildCfg{})
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
2017-05-17 11:04:07 -04:00
|
|
|
|
|
|
|
th.assertFileContent("public/feed.xml", "Recent content on")
|
|
|
|
|
2017-05-17 12:57:44 -04:00
|
|
|
s := h.Sites[0]
|
|
|
|
|
|
|
|
//Issue #3450
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(s.Info.RSSLink, qt.Equals, "http://example.com/blog/feed.xml")
|
2017-05-17 12:57:44 -04:00
|
|
|
|
2017-05-17 11:04:07 -04:00
|
|
|
}
|
2017-06-20 02:45:52 -04:00
|
|
|
|
|
|
|
// Issue #3614
|
|
|
|
func TestDotLessOutputFormat(t *testing.T) {
|
|
|
|
siteConfig := `
|
|
|
|
baseURL = "http://example.com/blog"
|
|
|
|
|
|
|
|
paginate = 1
|
|
|
|
defaultContentLanguage = "en"
|
|
|
|
|
2020-06-16 09:43:50 -04:00
|
|
|
disableKinds = ["page", "section", "term", "taxonomy", "sitemap", "robotsTXT", "404"]
|
2017-06-20 02:45:52 -04:00
|
|
|
|
|
|
|
[mediaTypes]
|
|
|
|
[mediaTypes."text/nodot"]
|
|
|
|
delimiter = ""
|
|
|
|
[mediaTypes."text/defaultdelim"]
|
2018-08-28 08:18:12 -04:00
|
|
|
suffixes = ["defd"]
|
2017-06-20 02:45:52 -04:00
|
|
|
[mediaTypes."text/nosuffix"]
|
|
|
|
[mediaTypes."text/customdelim"]
|
2018-08-28 08:18:12 -04:00
|
|
|
suffixes = ["del"]
|
2017-06-20 02:45:52 -04:00
|
|
|
delimiter = "_"
|
|
|
|
|
|
|
|
[outputs]
|
|
|
|
home = [ "DOTLESS", "DEF", "NOS", "CUS" ]
|
|
|
|
|
|
|
|
[outputFormats]
|
|
|
|
[outputFormats.DOTLESS]
|
|
|
|
mediatype = "text/nodot"
|
|
|
|
baseName = "_redirects" # This is how Netlify names their redirect files.
|
|
|
|
[outputFormats.DEF]
|
|
|
|
mediatype = "text/defaultdelim"
|
|
|
|
baseName = "defaultdelimbase"
|
|
|
|
[outputFormats.NOS]
|
|
|
|
mediatype = "text/nosuffix"
|
|
|
|
baseName = "nosuffixbase"
|
|
|
|
[outputFormats.CUS]
|
|
|
|
mediatype = "text/customdelim"
|
|
|
|
baseName = "customdelimbase"
|
|
|
|
|
|
|
|
`
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
|
|
|
|
2017-06-20 02:45:52 -04:00
|
|
|
mf := afero.NewMemMapFs()
|
|
|
|
writeToFs(t, mf, "content/foo.html", `foo`)
|
|
|
|
writeToFs(t, mf, "layouts/_default/list.dotless", `a dotless`)
|
|
|
|
writeToFs(t, mf, "layouts/_default/list.def.defd", `default delimim`)
|
|
|
|
writeToFs(t, mf, "layouts/_default/list.nos", `no suffix`)
|
|
|
|
writeToFs(t, mf, "layouts/_default/list.cus.del", `custom delim`)
|
|
|
|
|
|
|
|
th, h := newTestSitesFromConfig(t, mf, siteConfig)
|
|
|
|
|
|
|
|
err := h.Build(BuildCfg{})
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
2017-06-20 02:45:52 -04:00
|
|
|
|
|
|
|
th.assertFileContent("public/_redirects", "a dotless")
|
|
|
|
th.assertFileContent("public/defaultdelimbase.defd", "default delimim")
|
|
|
|
// This looks weird, but the user has chosen this definition.
|
2018-08-28 08:18:12 -04:00
|
|
|
th.assertFileContent("public/nosuffixbase", "no suffix")
|
2017-06-20 02:45:52 -04:00
|
|
|
th.assertFileContent("public/customdelimbase_del", "custom delim")
|
|
|
|
|
|
|
|
s := h.Sites[0]
|
2019-01-02 06:33:26 -05:00
|
|
|
home := s.getPage(page.KindHome)
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(home, qt.Not(qt.IsNil))
|
2017-06-20 02:45:52 -04:00
|
|
|
|
|
|
|
outputs := home.OutputFormats()
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(outputs.Get("DOTLESS").RelPermalink(), qt.Equals, "/blog/_redirects")
|
|
|
|
c.Assert(outputs.Get("DEF").RelPermalink(), qt.Equals, "/blog/defaultdelimbase.defd")
|
|
|
|
c.Assert(outputs.Get("NOS").RelPermalink(), qt.Equals, "/blog/nosuffixbase")
|
|
|
|
c.Assert(outputs.Get("CUS").RelPermalink(), qt.Equals, "/blog/customdelimbase_del")
|
2017-06-20 02:45:52 -04:00
|
|
|
|
|
|
|
}
|
2018-03-10 05:45:29 -05:00
|
|
|
|
|
|
|
func TestCreateSiteOutputFormats(t *testing.T) {
|
|
|
|
|
2019-08-05 04:19:55 -04:00
|
|
|
t.Run("Basic", func(t *testing.T) {
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
2018-03-10 05:45:29 -05:00
|
|
|
|
2019-08-05 04:19:55 -04:00
|
|
|
outputsConfig := map[string]interface{}{
|
|
|
|
page.KindHome: []string{"HTML", "JSON"},
|
|
|
|
page.KindSection: []string{"JSON"},
|
|
|
|
}
|
2018-03-10 05:45:29 -05:00
|
|
|
|
2019-08-05 04:19:55 -04:00
|
|
|
cfg := viper.New()
|
|
|
|
cfg.Set("outputs", outputsConfig)
|
|
|
|
|
2020-06-16 09:43:50 -04:00
|
|
|
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false)
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(outputs[page.KindSection], deepEqualsOutputFormats, output.Formats{output.JSONFormat})
|
|
|
|
c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.JSONFormat})
|
2019-08-05 04:19:55 -04:00
|
|
|
|
|
|
|
// Defaults
|
2020-06-16 09:43:50 -04:00
|
|
|
c.Assert(outputs[page.KindTerm], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat})
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(outputs[page.KindTaxonomy], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat})
|
|
|
|
c.Assert(outputs[page.KindPage], deepEqualsOutputFormats, output.Formats{output.HTMLFormat})
|
2019-08-05 04:19:55 -04:00
|
|
|
|
|
|
|
// These aren't (currently) in use when rendering in Hugo,
|
|
|
|
// but the pages needs to be assigned an output format,
|
|
|
|
// so these should also be correct/sensible.
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(outputs[kindRSS], deepEqualsOutputFormats, output.Formats{output.RSSFormat})
|
|
|
|
c.Assert(outputs[kindSitemap], deepEqualsOutputFormats, output.Formats{output.SitemapFormat})
|
|
|
|
c.Assert(outputs[kindRobotsTXT], deepEqualsOutputFormats, output.Formats{output.RobotsTxtFormat})
|
|
|
|
c.Assert(outputs[kind404], deepEqualsOutputFormats, output.Formats{output.HTMLFormat})
|
2019-08-05 04:19:55 -04:00
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
// Issue #4528
|
|
|
|
t.Run("Mixed case", func(t *testing.T) {
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
2019-08-05 04:19:55 -04:00
|
|
|
cfg := viper.New()
|
|
|
|
|
|
|
|
outputsConfig := map[string]interface{}{
|
2020-06-16 09:43:50 -04:00
|
|
|
// Note that we in Hugo 0.53.0 renamed this Kind to "taxonomy",
|
|
|
|
// but keep this test to test the legacy mapping.
|
2019-08-05 04:19:55 -04:00
|
|
|
"taxonomyterm": []string{"JSON"},
|
|
|
|
}
|
|
|
|
cfg.Set("outputs", outputsConfig)
|
|
|
|
|
2020-06-16 09:43:50 -04:00
|
|
|
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false)
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
2020-06-16 09:43:50 -04:00
|
|
|
c.Assert(outputs[page.KindTaxonomy], deepEqualsOutputFormats, output.Formats{output.JSONFormat})
|
2019-08-05 04:19:55 -04:00
|
|
|
|
|
|
|
})
|
2018-03-10 05:45:29 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateSiteOutputFormatsInvalidConfig(t *testing.T) {
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
2018-03-10 05:45:29 -05:00
|
|
|
|
|
|
|
outputsConfig := map[string]interface{}{
|
2019-01-02 06:33:26 -05:00
|
|
|
page.KindHome: []string{"FOO", "JSON"},
|
2018-03-10 05:45:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
cfg := viper.New()
|
|
|
|
cfg.Set("outputs", outputsConfig)
|
|
|
|
|
2020-06-16 09:43:50 -04:00
|
|
|
_, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false)
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.Not(qt.IsNil))
|
2018-03-10 05:45:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateSiteOutputFormatsEmptyConfig(t *testing.T) {
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
2018-03-10 05:45:29 -05:00
|
|
|
|
|
|
|
outputsConfig := map[string]interface{}{
|
2019-01-02 06:33:26 -05:00
|
|
|
page.KindHome: []string{},
|
2018-03-10 05:45:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
cfg := viper.New()
|
|
|
|
cfg.Set("outputs", outputsConfig)
|
|
|
|
|
2020-06-16 09:43:50 -04:00
|
|
|
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false)
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat})
|
2018-03-10 05:45:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateSiteOutputFormatsCustomFormats(t *testing.T) {
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
2018-03-10 05:45:29 -05:00
|
|
|
|
|
|
|
outputsConfig := map[string]interface{}{
|
2019-01-02 06:33:26 -05:00
|
|
|
page.KindHome: []string{},
|
2018-03-10 05:45:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
cfg := viper.New()
|
|
|
|
cfg.Set("outputs", outputsConfig)
|
|
|
|
|
|
|
|
var (
|
|
|
|
customRSS = output.Format{Name: "RSS", BaseName: "customRSS"}
|
|
|
|
customHTML = output.Format{Name: "HTML", BaseName: "customHTML"}
|
|
|
|
)
|
|
|
|
|
2020-06-16 09:43:50 -04:00
|
|
|
outputs, err := createSiteOutputFormats(output.Formats{customRSS, customHTML}, cfg.GetStringMap("outputs"), false)
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{customHTML, customRSS})
|
2018-03-10 05:45:29 -05:00
|
|
|
}
|
2019-04-17 07:17:26 -04:00
|
|
|
|
|
|
|
// https://github.com/gohugoio/hugo/issues/5849
|
|
|
|
func TestOutputFormatPermalinkable(t *testing.T) {
|
|
|
|
|
|
|
|
config := `
|
|
|
|
baseURL = "https://example.com"
|
|
|
|
|
2019-04-20 05:50:57 -04:00
|
|
|
|
|
|
|
|
2019-04-17 07:17:26 -04:00
|
|
|
# DAMP is similar to AMP, but not permalinkable.
|
|
|
|
[outputFormats]
|
|
|
|
[outputFormats.damp]
|
|
|
|
mediaType = "text/html"
|
|
|
|
path = "damp"
|
2019-04-19 04:41:56 -04:00
|
|
|
[outputFormats.ramp]
|
|
|
|
mediaType = "text/html"
|
|
|
|
path = "ramp"
|
|
|
|
permalinkable = true
|
2019-04-20 05:50:57 -04:00
|
|
|
[outputFormats.base]
|
|
|
|
mediaType = "text/html"
|
|
|
|
isHTML = true
|
|
|
|
baseName = "that"
|
|
|
|
permalinkable = true
|
|
|
|
[outputFormats.nobase]
|
|
|
|
mediaType = "application/json"
|
|
|
|
permalinkable = true
|
2019-04-17 07:17:26 -04:00
|
|
|
|
|
|
|
`
|
|
|
|
|
|
|
|
b := newTestSitesBuilder(t).WithConfigFile("toml", config)
|
|
|
|
b.WithContent("_index.md", `
|
|
|
|
---
|
|
|
|
Title: Home Sweet Home
|
2019-04-20 05:50:57 -04:00
|
|
|
outputs: [ "html", "amp", "damp", "base" ]
|
2019-04-17 07:17:26 -04:00
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/html-amp.md", `
|
|
|
|
---
|
|
|
|
Title: AMP and HTML
|
|
|
|
outputs: [ "html", "amp" ]
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/html-damp.md", `
|
|
|
|
---
|
|
|
|
Title: DAMP and HTML
|
|
|
|
outputs: [ "html", "damp" ]
|
|
|
|
---
|
|
|
|
|
2019-04-19 04:41:56 -04:00
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/html-ramp.md", `
|
|
|
|
---
|
|
|
|
Title: RAMP and HTML
|
|
|
|
outputs: [ "html", "ramp" ]
|
|
|
|
---
|
|
|
|
|
2019-04-17 07:17:26 -04:00
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/html.md", `
|
|
|
|
---
|
|
|
|
Title: HTML only
|
|
|
|
outputs: [ "html" ]
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/amp.md", `
|
|
|
|
---
|
|
|
|
Title: AMP only
|
|
|
|
outputs: [ "amp" ]
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
2019-04-20 05:50:57 -04:00
|
|
|
b.WithContent("blog/html-base-nobase.md", `
|
|
|
|
---
|
|
|
|
Title: HTML, Base and Nobase
|
|
|
|
outputs: [ "html", "base", "nobase" ]
|
|
|
|
---
|
|
|
|
|
2019-04-19 04:41:56 -04:00
|
|
|
`)
|
|
|
|
|
2019-04-20 05:50:57 -04:00
|
|
|
const commonTemplate = `
|
2019-04-19 04:41:56 -04:00
|
|
|
This RelPermalink: {{ .RelPermalink }}
|
2019-04-20 05:50:57 -04:00
|
|
|
Output Formats: {{ len .OutputFormats }};{{ range .OutputFormats }}{{ .Name }};{{ .RelPermalink }}|{{ end }}
|
2019-04-17 07:17:26 -04:00
|
|
|
|
2019-04-20 05:50:57 -04:00
|
|
|
`
|
2019-04-17 07:17:26 -04:00
|
|
|
|
2019-04-20 05:50:57 -04:00
|
|
|
b.WithTemplatesAdded("index.html", commonTemplate)
|
|
|
|
b.WithTemplatesAdded("_default/single.html", commonTemplate)
|
|
|
|
b.WithTemplatesAdded("_default/single.json", commonTemplate)
|
2019-04-17 07:17:26 -04:00
|
|
|
|
2019-04-20 05:50:57 -04:00
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
|
|
|
b.AssertFileContent("public/index.html",
|
2019-04-19 04:41:56 -04:00
|
|
|
"This RelPermalink: /",
|
2019-04-20 05:50:57 -04:00
|
|
|
"Output Formats: 4;HTML;/|AMP;/amp/|damp;/damp/|base;/that.html|",
|
|
|
|
)
|
2019-04-19 04:41:56 -04:00
|
|
|
|
|
|
|
b.AssertFileContent("public/amp/index.html",
|
2019-04-20 05:50:57 -04:00
|
|
|
"This RelPermalink: /amp/",
|
|
|
|
"Output Formats: 4;HTML;/|AMP;/amp/|damp;/damp/|base;/that.html|",
|
|
|
|
)
|
2019-04-17 07:17:26 -04:00
|
|
|
|
2019-04-19 04:41:56 -04:00
|
|
|
b.AssertFileContent("public/blog/html-amp/index.html",
|
2019-04-20 05:50:57 -04:00
|
|
|
"Output Formats: 2;HTML;/blog/html-amp/|AMP;/amp/blog/html-amp/|",
|
|
|
|
"This RelPermalink: /blog/html-amp/")
|
2019-04-19 04:41:56 -04:00
|
|
|
|
|
|
|
b.AssertFileContent("public/amp/blog/html-amp/index.html",
|
2019-04-20 05:50:57 -04:00
|
|
|
"Output Formats: 2;HTML;/blog/html-amp/|AMP;/amp/blog/html-amp/|",
|
|
|
|
"This RelPermalink: /amp/blog/html-amp/")
|
2019-04-19 04:41:56 -04:00
|
|
|
|
2019-04-20 05:50:57 -04:00
|
|
|
// Damp is not permalinkable
|
2019-04-19 04:41:56 -04:00
|
|
|
b.AssertFileContent("public/damp/blog/html-damp/index.html",
|
|
|
|
"This RelPermalink: /blog/html-damp/",
|
2019-04-20 05:50:57 -04:00
|
|
|
"Output Formats: 2;HTML;/blog/html-damp/|damp;/damp/blog/html-damp/|")
|
2019-04-19 04:41:56 -04:00
|
|
|
|
|
|
|
b.AssertFileContent("public/blog/html-ramp/index.html",
|
|
|
|
"This RelPermalink: /blog/html-ramp/",
|
2019-04-20 05:50:57 -04:00
|
|
|
"Output Formats: 2;HTML;/blog/html-ramp/|ramp;/ramp/blog/html-ramp/|")
|
2019-04-19 04:41:56 -04:00
|
|
|
|
|
|
|
b.AssertFileContent("public/ramp/blog/html-ramp/index.html",
|
|
|
|
"This RelPermalink: /ramp/blog/html-ramp/",
|
2019-04-20 05:50:57 -04:00
|
|
|
"Output Formats: 2;HTML;/blog/html-ramp/|ramp;/ramp/blog/html-ramp/|")
|
|
|
|
|
|
|
|
// https://github.com/gohugoio/hugo/issues/5877
|
|
|
|
outputFormats := "Output Formats: 3;HTML;/blog/html-base-nobase/|base;/blog/html-base-nobase/that.html|nobase;/blog/html-base-nobase/index.json|"
|
|
|
|
|
|
|
|
b.AssertFileContent("public/blog/html-base-nobase/index.json",
|
|
|
|
"This RelPermalink: /blog/html-base-nobase/index.json",
|
|
|
|
outputFormats,
|
|
|
|
)
|
|
|
|
|
|
|
|
b.AssertFileContent("public/blog/html-base-nobase/that.html",
|
|
|
|
"This RelPermalink: /blog/html-base-nobase/that.html",
|
|
|
|
outputFormats,
|
|
|
|
)
|
|
|
|
|
|
|
|
b.AssertFileContent("public/blog/html-base-nobase/index.html",
|
|
|
|
"This RelPermalink: /blog/html-base-nobase/",
|
|
|
|
outputFormats,
|
|
|
|
)
|
2019-04-19 04:41:56 -04:00
|
|
|
|
2019-04-17 07:17:26 -04:00
|
|
|
}
|
2019-08-15 04:30:37 -04:00
|
|
|
|
|
|
|
func TestSiteWithPageNoOutputs(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
b := newTestSitesBuilder(t)
|
|
|
|
b.WithConfigFile("toml", `
|
|
|
|
baseURL = "https://example.com"
|
|
|
|
|
|
|
|
[outputFormats.o1]
|
|
|
|
mediaType = "text/html"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
`)
|
|
|
|
b.WithContent("outputs-empty.md", `---
|
|
|
|
title: "Empty Outputs"
|
|
|
|
outputs: []
|
|
|
|
---
|
|
|
|
|
|
|
|
Word1. Word2.
|
|
|
|
|
|
|
|
`,
|
|
|
|
"outputs-string.md", `---
|
|
|
|
title: "Outputs String"
|
|
|
|
outputs: "o1"
|
|
|
|
---
|
|
|
|
|
|
|
|
Word1. Word2.
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithTemplates("index.html", `
|
|
|
|
{{ range .Site.RegularPages }}
|
|
|
|
WordCount: {{ .WordCount }}
|
|
|
|
{{ end }}
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithTemplates("_default/single.html", `HTML: {{ .Content }}`)
|
|
|
|
b.WithTemplates("_default/single.o1.html", `O1: {{ .Content }}`)
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
|
|
|
b.AssertFileContent(
|
|
|
|
"public/index.html",
|
|
|
|
" WordCount: 2")
|
|
|
|
|
|
|
|
b.AssertFileContent("public/outputs-empty/index.html", "HTML:", "Word1. Word2.")
|
|
|
|
b.AssertFileContent("public/outputs-string/index.html", "O1:", "Word1. Word2.")
|
|
|
|
|
|
|
|
}
|