Create a struct with all of Hugo's config options

Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes #10896
Closes #10620
This commit is contained in:
Bjørn Erik Pedersen 2023-01-04 18:24:36 +01:00
parent 6aededf6b4
commit 241b21b0fd
337 changed files with 13377 additions and 14898 deletions

View file

@ -0,0 +1,7 @@
# Testing various error situations.
! hugo mods
stderr 'Did you mean this\?'
! hugo mod clea
stderr 'Did you mean this\?'

View file

@ -0,0 +1,4 @@
# Test the completion commands.
hugo completion -h
stdout 'Generate the autocompletion script for hugo for the specified shell.'

View file

@ -0,0 +1,19 @@
# Test the config command.
hugo config -h
stdout 'Print the site configuration'
hugo config
stdout '\"baseurl\": \"https://example.com/\",'
hugo config mounts -h
stdout 'Print the configured file mounts'
hugo config mounts
stdout '\"source\": \"content\",'
# Test files
-- hugo.toml --
baseURL="https://example.com/"
title="My New Hugo Site"

View file

@ -0,0 +1,42 @@
# Test the convert commands.
hugo convert -h
stdout 'Convert your content'
hugo convert toJSON -h
stdout 'to use JSON for the front matter'
hugo convert toTOML -h
stdout 'to use TOML for the front matter'
hugo convert toYAML -h
stdout 'to use YAML for the front matter'
hugo convert toJSON -o myjsoncontent
stdout 'processing 3 content files'
grep '^{' myjsoncontent/content/mytoml.md
grep '^{' myjsoncontent/content/myjson.md
grep '^{' myjsoncontent/content/myyaml.md
hugo convert toYAML -o myyamlcontent
stdout 'processing 3 content files'
hugo convert toTOML -o mytomlcontent
stdout 'processing 3 content files'
-- hugo.toml --
baseURL = "http://example.org/"
-- content/mytoml.md --
+++
title = "TOML"
+++
TOML content
-- content/myjson.md --
{
"title": "JSON"
}
JSON content
-- content/myyaml.md --
---
title: YAML
---
YAML content

View file

@ -0,0 +1,24 @@
# Test the deploy command.
hugo deploy -h
stdout 'Deploy your site to a Cloud provider\.'
mkdir mybucket
hugo deploy --target mydeployment
grep 'hello' mybucket/index.html
replace public/index.html 'hello' 'changed'
hugo deploy --target mydeployment --invalidateCDN --dryRun
stdout 'Would upload: index.html'
stdout 'Would invalidate CloudFront CDN with ID foobar'
-- hugo.toml --
disableKinds = ["RSS", "sitemap", "robotsTXT", "404", "taxonomy", "term"]
baseURL = "https://example.org/"
[deployment]
[[deployment.targets]]
name = "myfirst"
url="gs://asdfasdf"
[[deployment.targets]]
name = "mydeployment"
url="file://./mybucket"
cloudFrontDistributionID = "foobar"
-- public/index.html --
<html><body>hello</body></html>

View file

@ -0,0 +1,5 @@
# Test the hugo env command.
hugo env
stdout 'GOARCH'
! stderr .

View file

@ -0,0 +1,19 @@
# Test the gen commands.
# Note that adding new commands will require updating the NUM_COMMANDS value.
env NUM_COMMANDS=41
hugo gen -h
stdout 'A collection of several useful generators\.'
hugo gen doc --dir clidocs
checkfilecount $NUM_COMMANDS clidocs
hugo gen man -h
stdout 'up-to-date man pages'
hugo gen man --dir manpages
checkfilecount $NUM_COMMANDS manpages
hugo gen chromastyles -h
stdout 'Generate CSS stylesheet for the Chroma code highlighter'
hugo gen chromastyles --style monokai
stdout 'color: #f8f8f2'

View file

@ -0,0 +1,19 @@
# Test the hugo command.
hugo
stdout 'Pages.*|1'
stdout 'Total in'
checkfile public/index.html
checkfile public/p1/index.html
-- hugo.toml --
baseURL = "http://example.org/"
disableKinds = ["RSS", "sitemap", "robotsTXT", "404", "taxonomy", "term"]
-- layouts/index.html --
Home.
-- layouts/_default/single.html --
Title: {{ .Title }}
-- content/p1.md --
---
title: "P1"
---

View file

@ -0,0 +1,18 @@
# Testing error output.
# The hugo mod get command handles flags a little special, but the -h flag should print the help.
hugo mod get -h
stdout 'Resolves dependencies in your current Hugo Project'
# Invalid flag. Should print an error message to stderr and the help to stdout.
! hugo --asdf
stderr 'unknown flag: --asdf'
stdout 'hugo is the main command'
# This should fail the build, print an error message to stderr, but no help output.
! hugo
! stdout 'hugo is the main command'
stderr 'failed to load config'
-- hugo.toml --
invalid: toml

View file

@ -0,0 +1,27 @@
# Test the hugo command.
hugo --baseURL http://example.com/ --destination ${WORK}/newpublic --clock 2021-11-06T22:30:00.00+09:00 -e staging --config ${WORK}/myconfig --configDir ${WORK}/myconfigdir -s mysource
stdout 'Pages.*|1'
stdout 'Total in'
grep 'Home: http://example.com/, Time: 2021-11-06' newpublic/index.html
grep 'Environment: staging, foo: bar, bar: baz' newpublic/index.html
hugo --quiet
! stdout .
-- myconfig.toml --
baseURL = "http://example.org/"
disableKinds = ["RSS", "sitemap", "robotsTXT", "404", "taxonomy", "term"]
[params]
foo = "bar"
-- myconfigdir/_default/params.toml --
bar = "baz"
-- mysource/layouts/index.html --
Home: {{ .Permalink }}, Time: {{ now }}
Environment: {{ hugo.Environment }}, foo: {{ .Site.Params.foo }}, bar: {{ .Site.Params.bar }}
-- mysource/layouts/_default/single.html --
Title: {{ .Title }}
-- mysource/content/p1.md --
---
title: "P1"
---

View file

@ -0,0 +1,28 @@
# Test the hugo command.
# See https://github.com/rogpeppe/go-internal/issues/228
[windows] skip
hugo -w &
sleep 3
grep 'P1start' public/p1/index.html
replace content/p1.md 'P1start' 'P1end'
sleep 2
grep 'P1end' public/p1/index.html
stop
-- hugo.toml --
baseURL = "http://example.org/"
disableKinds = ["RSS", "sitemap", "robotsTXT", "404", "taxonomy", "term"]
-- layouts/index.html --
Home.
-- layouts/_default/single.html --
Title: {{ .Title }}| {{ .Content }}
-- content/p1.md --
---
title: "P1"
---
P1start

View file

@ -0,0 +1,19 @@
# Test the import jekyll command.
hugo import -h
stdout 'Import your site from other web site generators like Jekyll\.'
hugo import jekyll -h
stdout 'hugo import from Jekyll\.'
hugo import jekyll myjekyllsite myhugosite
checkfilecount 1 myhugosite/content/post
grep 'example\.org' myhugosite/hugo.yaml
# A simple Jekyll site.
-- myjekyllsite/_posts/2012-01-18-hello-world.markdown --
---
layout: post
title: "Hello World"
---
Hello world!

View file

@ -0,0 +1,34 @@
# Test the hugo list commands.
hugo list drafts
! stderr .
stdout 'draft.md,2019-01-01T00:00:00Z'
hugo list future
stdout 'future.md,2030-01-01T00:00:00Z'
hugo list expired
stdout 'expired.md,2018-01-01T00:00:00Z'
hugo list all
stdout 'future.md,2030-01-01T00:00:00Z'
stdout 'draft.md,2019-01-01T00:00:00Z'
stdout 'expired.md,2018-01-01T00:00:00Z'
-- hugo.toml --
baseURL = "https://example.org/"
disableKinds = ["taxonomy", "term"]
-- content/draft.md --
---
draft: true
date: 2019-01-01
---
-- content/expired.md --
---
date: 2018-01-01
expiryDate: 2019-01-01
---
-- content/future.md --
---
date: 2030-01-01
---

View file

@ -0,0 +1,44 @@
# Test the hugo mod commands.
dostounix golden/vendor.txt
dostounix golden/go.mod.testsubmod
hugo mod graph
stdout 'empty-hugo'
hugo mod verify
! stderr .
hugo mod get -u
! stderr .
hugo mod get -u ./...
! stderr .
hugo mod vendor
! stderr .
cmp _vendor/modules.txt golden/vendor.txt
hugo mod clean
! stderr .
stdout 'hugo: removed 1 dirs in module cache for \"github.com/bep/empty-hugo-module\"'
hugo mod clean --all
stdout 'Deleted 2\d{2} files from module cache\.'
cd submod
hugo mod init testsubmod
cmpenv go.mod $WORK/golden/go.mod.testsubmod
-- hugo.toml --
title = "Hugo Modules Test"
[module]
[[module.imports]]
path="github.com/bep/empty-hugo-module"
[[module.imports.mounts]]
source="README.md"
target="content/_index.md"
-- go.mod --
go 1.19
module github.com/gohugoio/testmod
-- submod/hugo.toml --
title = "Hugo Sub Module"
-- golden/vendor.txt --
# github.com/bep/empty-hugo-module v1.0.0
-- golden/go.mod.testsubmod --
module testsubmod
go ${GOVERSION}

View file

@ -0,0 +1,23 @@
# Test mod npm.
hugo mod npm pack
cmp package.hugo.json golden/package.hugo.json
-- hugo.toml --
baseURL = "https://example.org/"
-- package.json --
{
"name": "test",
"version": "1.0.0",
"dependencies": {
"mod": "foo-bar"
}
}
-- golden/package.hugo.json --
{
"name": "test",
"version": "1.0.0",
"dependencies": {
"mod": "foo-bar"
}
}

View file

@ -0,0 +1,21 @@
# Test hugo mod tidy.
dostounix golden/go.mod.cleaned
hugo mod tidy
cmp go.mod golden/go.mod.cleaned
-- hugo.toml --
title = "Hugo Modules Test"
-- go.mod --
go 1.19
require github.com/bep/empty-hugo-module v1.0.0
module github.com/gohugoio/testmod
-- golden/go.mod.cleaned --
go 1.19
module github.com/gohugoio/testmod

View file

@ -0,0 +1,27 @@
# Test the new command.
hugo new site -h
stdout 'Create a new site in the provided directory'
hugo new site mysite
stdout 'Congratulations! Your new Hugo site is created in'
cd mysite
checkfile hugo.toml
hugo new theme -h
stdout 'Create a new site in the provided directory'
hugo new theme mytheme
stdout 'Creating theme'
cd themes
cd mytheme
checkfile theme.toml
checkfile hugo.toml
exists layouts/_default/list.html
exists layouts/_default/single.html
cd $WORK/mysite
hugo new -h
stdout 'Create a new content file.'
hugo new posts/my-first-post.md
checkfile content/posts/my-first-post.md

View file

@ -0,0 +1,30 @@
# Test the hugo server command.
# We run these tests in parallel so let Hugo decide which port to use.
hugo server &
waitServer
httpget $HUGOTEST_BASEURL_0 'Title: Hugo Server Test' $HUGOTEST_BASEURL_0 'ServerPort: \d{4,5}' 'myenv: thedevelopment' 'livereload\.js' 'Env: development' 'IsServer: true'
httpget ${HUGOTEST_BASEURL_0}doesnotexist 'custom 404'
# By defauilt, the server renders to memory.
! exists public/index.html
stopServer
! stderr .
-- hugo.toml --
title = "Hugo Server Test"
baseURL = "https://example.org/"
disableKinds = ["taxonomy", "term", "sitemap"]
-- config/production/params.toml --
myenv = "theproduction"
-- config/development/params.toml --
myenv = "thedevelopment"
-- layouts/index.html --
<body>
Title: {{ .Title }}|BaseURL: {{ site.BaseURL }}|ServerPort: {{ site.ServerPort }}|myenv: {{ .Site.Params.myenv }}|Env: {{ hugo.Environment }}|IsServer: {{ site.IsServer }}|
</body>
-- layouts/404.html --
custom 404

View file

@ -0,0 +1,43 @@
# Test the hugo server command when editing the config file.
# We run these tests in parallel so let Hugo decide which port to use.
hugo server &
waitServer
httpget $HUGOTEST_BASEURL_0 'Title: Hugo Server Test' $HUGOTEST_BASEURL_0
mv edits/title.toml hugo.toml
httpget $HUGOTEST_BASEURL_0 'Title: Hugo New Server Test' $HUGOTEST_BASEURL_0
mv edits/addlanguage.toml hugo.toml
httpget $HUGOTEST_BASEURL_0 'Title: Hugo New Server Test' $HUGOTEST_BASEURL_0
httpget ${HUGOTEST_BASEURL_0}nn/ 'Hugo Nynorsk Server Test' ${HUGOTEST_BASEURL_0}nn/
stopServer
! stderr .
-- hugo.toml --
title = "Hugo Server Test"
baseURL = "https://example.org/"
-- edits/title.toml --
title = "Hugo New Server Test"
baseURL = "https://example.org/"
-- edits/addlanguage.toml --
title = "Hugo New Server Test"
baseURL = "https://example.org/"
[languages]
[languages.en]
languageName = "English"
weight = 1
[languages.nn]
languageName = "Nynorsk"
title = "Hugo Nynorsk Server Test"
weight = 2
-- layouts/index.html --
Title: {{ .Title }}|BaseURL: {{ .Permalink }}|

View file

@ -0,0 +1,55 @@
# Test the hugo server command when editing content.
# We run these tests in parallel so let Hugo decide which port to use.
# Render to disk so we can check the /public dir.
hugo server --renderToDisk &
waitServer
httpget ${HUGOTEST_BASEURL_0}p1/ 'Title: P1' $HUGOTEST_BASEURL_0
ls public/p2
cp stdout lsp2_1.txt
ls public/staticfiles
stdout 'static\.txt'
cp stdout lsstaticfiles_1.txt
replace $WORK/content/p1/index.md 'P1' 'P1 New'
httpget ${HUGOTEST_BASEURL_0}p1/ 'Title: P1 New' $HUGOTEST_BASEURL_0
ls public/p2
cp stdout lsp2_2.txt
cmp lsp2_1.txt lsp2_2.txt
ls public/staticfiles
cp stdout lsstaticfiles_2.txt
cmp lsstaticfiles_1.txt lsstaticfiles_2.txt
stopServer
! stderr .
-- hugo.toml --
title = "Hugo Server Test"
baseURL = "https://example.org/"
disableKinds = ["taxonomy", "term", "sitemap"]
-- layouts/index.html --
Title: {{ .Title }}|BaseURL: {{ site.BaseURL }}|
-- layouts/_default/single.html --
Title: {{ .Title }}|BaseURL: {{ site.BaseURL }}|
-- content/_index.md --
---
title: Hugo Home
---
-- content/p1/index.md --
---
title: P1
---
-- content/p2/index.md --
---
title: P2
---
-- static/staticfiles/static.txt --
static

View file

@ -0,0 +1,32 @@
# Test the hugo server command.
# We run these tests in parallel so let Hugo decide which port to use.
hugo server &
waitServer
httpget $HUGOTEST_BASEURL_0 'Title: Hugo Server Test' $HUGOTEST_BASEURL_0
httpget $HUGOTEST_BASEURL_1 'Title: Hugo Serveur Test' $HUGOTEST_BASEURL_1
stopServer
! stderr .
-- hugo.toml --
title = "Hugo Server Test"
baseURL = "https://example.org/"
disableKinds = ["taxonomy", "term", "sitemap"]
[languages]
[languages.en]
baseURL = "https://en.example.org/"
languageName = "English"
title = "Hugo Server Test"
weight = 1
[languages.fr]
baseURL = "https://fr.example.org/"
title = "Hugo Serveur Test"
languageName = "Français"
weight = 2
-- layouts/index.html --
Title: {{ .Title }}|BaseURL: {{ site.BaseURL }}|

View file

@ -0,0 +1,25 @@
# Test the hugo server command.
# We run these tests in parallel so let Hugo decide which port to use.
hugo server --renderStaticToDisk &
waitServer
httpget $HUGOTEST_BASEURL_0 'Title: Hugo Server Test' $HUGOTEST_BASEURL_0
! exists public/index.html
exists public/mystatic.txt
stopServer
! stderr .
-- hugo.toml --
title = "Hugo Server Test"
baseURL = "https://example.org/"
disableKinds = ["taxonomy", "term", "sitemap"]
-- static/mystatic.txt --
This is a static file.
-- layouts/index.html --
Title: {{ .Title }}|BaseURL: {{ site.BaseURL }}|

View file

@ -0,0 +1,25 @@
# Test the hugo server command.
# We run these tests in parallel so let Hugo decide which port to use.
hugo server &
waitServer
httpget $HUGOTEST_BASEURL_0 'Title: Hugo Server Test' $HUGOTEST_BASEURL_0
! exists public/index.html
! exists public/mystatic.txt
stopServer
! stderr .
-- hugo.toml --
title = "Hugo Server Test"
baseURL = "https://example.org/"
disableKinds = ["taxonomy", "term", "sitemap"]
-- static/mystatic.txt --
This is a static file.
-- layouts/index.html --
Title: {{ .Title }}|BaseURL: {{ site.BaseURL }}|

View file

@ -0,0 +1,7 @@
# Test the hugo version command.
hugo -h
stdout 'hugo is the main command, used to build your Hugo site'
hugo version
stdout 'hugo v.* BuildDate=unknown'