2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
2018-04-10 13:16:09 -04: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 commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2021-06-09 04:58:18 -04:00
|
|
|
"github.com/gohugoio/hugo/config"
|
|
|
|
|
2020-01-31 03:09:11 -05:00
|
|
|
"github.com/spf13/afero"
|
|
|
|
|
|
|
|
"github.com/gohugoio/hugo/hugofs"
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/common/types"
|
|
|
|
|
2018-04-13 02:42:29 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
qt "github.com/frankban/quicktest"
|
2018-04-10 13:16:09 -04:00
|
|
|
)
|
|
|
|
|
2018-04-11 14:17:28 -04:00
|
|
|
func TestExecute(t *testing.T) {
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
2018-04-11 14:17:28 -04:00
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
createSite := func(c *qt.C) string {
|
|
|
|
dir := createSimpleTestSite(t, testSiteConfig{})
|
|
|
|
return dir
|
2020-01-31 03:09:11 -05:00
|
|
|
}
|
2018-04-11 14:17:28 -04:00
|
|
|
|
2020-01-31 03:09:11 -05:00
|
|
|
c.Run("hugo", func(c *qt.C) {
|
2022-03-21 04:35:15 -04:00
|
|
|
dir := createSite(c)
|
2020-01-31 03:09:11 -05:00
|
|
|
resp := Execute([]string{"-s=" + dir})
|
|
|
|
c.Assert(resp.Err, qt.IsNil)
|
|
|
|
result := resp.Result
|
|
|
|
c.Assert(len(result.Sites) == 1, qt.Equals, true)
|
2022-09-17 05:25:37 -04:00
|
|
|
c.Assert(len(result.Sites[0].RegularPages()) == 2, qt.Equals, true)
|
2020-01-31 03:09:11 -05:00
|
|
|
c.Assert(result.Sites[0].Info.Params()["myparam"], qt.Equals, "paramproduction")
|
|
|
|
})
|
|
|
|
|
|
|
|
c.Run("hugo, set environment", func(c *qt.C) {
|
2022-03-21 04:35:15 -04:00
|
|
|
dir := createSite(c)
|
2020-01-31 03:09:11 -05:00
|
|
|
resp := Execute([]string{"-s=" + dir, "-e=staging"})
|
|
|
|
c.Assert(resp.Err, qt.IsNil)
|
|
|
|
result := resp.Result
|
|
|
|
c.Assert(result.Sites[0].Info.Params()["myparam"], qt.Equals, "paramstaging")
|
|
|
|
})
|
|
|
|
|
|
|
|
c.Run("convert toJSON", func(c *qt.C) {
|
2022-03-21 04:35:15 -04:00
|
|
|
dir := createSite(c)
|
2020-01-31 03:09:11 -05:00
|
|
|
output := filepath.Join(dir, "myjson")
|
|
|
|
resp := Execute([]string{"convert", "toJSON", "-s=" + dir, "-e=staging", "-o=" + output})
|
|
|
|
c.Assert(resp.Err, qt.IsNil)
|
|
|
|
converted := readFileFrom(c, filepath.Join(output, "content", "p1.md"))
|
|
|
|
c.Assert(converted, qt.Equals, "{\n \"title\": \"P1\",\n \"weight\": 1\n}\n\nContent\n\n", qt.Commentf(converted))
|
|
|
|
})
|
|
|
|
|
|
|
|
c.Run("config, set environment", func(c *qt.C) {
|
2022-03-21 04:35:15 -04:00
|
|
|
dir := createSite(c)
|
2020-01-31 03:09:11 -05:00
|
|
|
out, err := captureStdout(func() error {
|
|
|
|
resp := Execute([]string{"config", "-s=" + dir, "-e=staging"})
|
|
|
|
return resp.Err
|
|
|
|
})
|
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(out, qt.Contains, "params = map[myparam:paramstaging]", qt.Commentf(out))
|
|
|
|
})
|
|
|
|
|
|
|
|
c.Run("deploy, environment set", func(c *qt.C) {
|
2022-03-21 04:35:15 -04:00
|
|
|
dir := createSite(c)
|
2020-01-31 03:09:11 -05:00
|
|
|
resp := Execute([]string{"deploy", "-s=" + dir, "-e=staging", "--target=mydeployment", "--dryRun"})
|
|
|
|
c.Assert(resp.Err, qt.Not(qt.IsNil))
|
2020-12-04 22:43:03 -05:00
|
|
|
c.Assert(resp.Err.Error(), qt.Contains, `no driver registered for "hugocloud"`)
|
2020-01-31 03:09:11 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
c.Run("list", func(c *qt.C) {
|
2022-03-21 04:35:15 -04:00
|
|
|
dir := createSite(c)
|
2020-01-31 03:09:11 -05:00
|
|
|
out, err := captureStdout(func() error {
|
|
|
|
resp := Execute([]string{"list", "all", "-s=" + dir, "-e=staging"})
|
|
|
|
return resp.Err
|
|
|
|
})
|
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(out, qt.Contains, "p1.md")
|
|
|
|
})
|
|
|
|
|
|
|
|
c.Run("new theme", func(c *qt.C) {
|
2022-03-21 04:35:15 -04:00
|
|
|
dir := createSite(c)
|
2020-01-31 03:09:11 -05:00
|
|
|
themesDir := filepath.Join(dir, "mythemes")
|
|
|
|
resp := Execute([]string{"new", "theme", "mytheme", "-s=" + dir, "-e=staging", "--themesDir=" + themesDir})
|
|
|
|
c.Assert(resp.Err, qt.IsNil)
|
|
|
|
themeTOML := readFileFrom(c, filepath.Join(themesDir, "mytheme", "theme.toml"))
|
|
|
|
c.Assert(themeTOML, qt.Contains, "name = \"Mytheme\"")
|
|
|
|
})
|
|
|
|
|
|
|
|
c.Run("new site", func(c *qt.C) {
|
2022-03-21 04:35:15 -04:00
|
|
|
dir := createSite(c)
|
2020-01-31 03:09:11 -05:00
|
|
|
siteDir := filepath.Join(dir, "mysite")
|
|
|
|
resp := Execute([]string{"new", "site", siteDir, "-e=staging"})
|
|
|
|
c.Assert(resp.Err, qt.IsNil)
|
|
|
|
config := readFileFrom(c, filepath.Join(siteDir, "config.toml"))
|
2021-07-27 13:07:10 -04:00
|
|
|
c.Assert(config, qt.Contains, "baseURL = 'http://example.org/'")
|
2020-01-31 03:09:11 -05:00
|
|
|
checkNewSiteInited(c, siteDir)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkNewSiteInited(c *qt.C, basepath string) {
|
|
|
|
paths := []string{
|
|
|
|
filepath.Join(basepath, "archetypes"),
|
2022-11-20 11:10:39 -05:00
|
|
|
filepath.Join(basepath, "assets"),
|
|
|
|
filepath.Join(basepath, "content"),
|
2020-01-31 03:09:11 -05:00
|
|
|
filepath.Join(basepath, "data"),
|
2022-11-20 11:10:39 -05:00
|
|
|
filepath.Join(basepath, "layouts"),
|
|
|
|
filepath.Join(basepath, "static"),
|
|
|
|
filepath.Join(basepath, "themes"),
|
2020-01-31 03:09:11 -05:00
|
|
|
filepath.Join(basepath, "config.toml"),
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, path := range paths {
|
|
|
|
_, err := os.Stat(path)
|
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func readFileFrom(c *qt.C, filename string) string {
|
|
|
|
c.Helper()
|
|
|
|
filename = filepath.Clean(filename)
|
|
|
|
b, err := afero.ReadFile(hugofs.Os, filename)
|
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
return string(b)
|
2018-04-11 14:17:28 -04:00
|
|
|
}
|
|
|
|
|
2020-09-09 10:51:13 -04:00
|
|
|
func TestFlags(t *testing.T) {
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
2018-04-13 02:42:29 -04:00
|
|
|
|
|
|
|
noOpRunE := func(cmd *cobra.Command, args []string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
2020-09-09 10:51:13 -04:00
|
|
|
name string
|
2018-04-13 02:42:29 -04:00
|
|
|
args []string
|
2020-09-09 10:51:13 -04:00
|
|
|
check func(c *qt.C, cmd *serverCmd)
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
// https://github.com/gohugoio/hugo/issues/7642
|
|
|
|
name: "ignoreVendorPaths",
|
|
|
|
args: []string{"server", "--ignoreVendorPaths=github.com/**"},
|
|
|
|
check: func(c *qt.C, cmd *serverCmd) {
|
2022-03-21 04:35:15 -04:00
|
|
|
cfg := config.NewWithTestDefaults()
|
2020-09-09 10:51:13 -04:00
|
|
|
cmd.flagsToConfig(cfg)
|
|
|
|
c.Assert(cfg.Get("ignoreVendorPaths"), qt.Equals, "github.com/**")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Persistent flags",
|
2020-12-02 07:23:25 -05:00
|
|
|
args: []string{
|
|
|
|
"server",
|
2020-09-09 10:51:13 -04:00
|
|
|
"--config=myconfig.toml",
|
|
|
|
"--configDir=myconfigdir",
|
|
|
|
"--contentDir=mycontent",
|
|
|
|
"--disableKinds=page,home",
|
|
|
|
"--environment=testing",
|
|
|
|
"--configDir=myconfigdir",
|
|
|
|
"--layoutDir=mylayouts",
|
|
|
|
"--theme=mytheme",
|
|
|
|
"--gc",
|
|
|
|
"--themesDir=mythemes",
|
|
|
|
"--cleanDestinationDir",
|
|
|
|
"--navigateToChanged",
|
|
|
|
"--disableLiveReload",
|
|
|
|
"--noHTTPCache",
|
2022-02-15 07:03:36 -05:00
|
|
|
"--printI18nWarnings",
|
2020-09-09 10:51:13 -04:00
|
|
|
"--destination=/tmp/mydestination",
|
|
|
|
"-b=https://example.com/b/",
|
|
|
|
"--port=1366",
|
|
|
|
"--renderToDisk",
|
|
|
|
"--source=mysource",
|
2022-02-15 06:57:49 -05:00
|
|
|
"--printPathWarnings",
|
2022-02-15 09:26:18 -05:00
|
|
|
"--printUnusedTemplates",
|
2020-09-09 10:51:13 -04:00
|
|
|
},
|
|
|
|
check: func(c *qt.C, sc *serverCmd) {
|
|
|
|
c.Assert(sc, qt.Not(qt.IsNil))
|
|
|
|
c.Assert(sc.navigateToChanged, qt.Equals, true)
|
|
|
|
c.Assert(sc.disableLiveReload, qt.Equals, true)
|
|
|
|
c.Assert(sc.noHTTPCache, qt.Equals, true)
|
|
|
|
c.Assert(sc.renderToDisk, qt.Equals, true)
|
|
|
|
c.Assert(sc.serverPort, qt.Equals, 1366)
|
|
|
|
c.Assert(sc.environment, qt.Equals, "testing")
|
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
cfg := config.NewWithTestDefaults()
|
2020-09-09 10:51:13 -04:00
|
|
|
sc.flagsToConfig(cfg)
|
|
|
|
c.Assert(cfg.GetString("publishDir"), qt.Equals, "/tmp/mydestination")
|
|
|
|
c.Assert(cfg.GetString("contentDir"), qt.Equals, "mycontent")
|
|
|
|
c.Assert(cfg.GetString("layoutDir"), qt.Equals, "mylayouts")
|
|
|
|
c.Assert(cfg.GetStringSlice("theme"), qt.DeepEquals, []string{"mytheme"})
|
|
|
|
c.Assert(cfg.GetString("themesDir"), qt.Equals, "mythemes")
|
|
|
|
c.Assert(cfg.GetString("baseURL"), qt.Equals, "https://example.com/b/")
|
|
|
|
|
|
|
|
c.Assert(cfg.Get("disableKinds"), qt.DeepEquals, []string{"page", "home"})
|
|
|
|
|
|
|
|
c.Assert(cfg.GetBool("gc"), qt.Equals, true)
|
|
|
|
|
2022-02-15 06:57:49 -05:00
|
|
|
// The flag is named printPathWarnings
|
2020-09-09 10:51:13 -04:00
|
|
|
c.Assert(cfg.GetBool("logPathWarnings"), qt.Equals, true)
|
|
|
|
|
2022-02-15 07:03:36 -05:00
|
|
|
// The flag is named printI18nWarnings
|
2020-09-09 10:51:13 -04:00
|
|
|
c.Assert(cfg.GetBool("logI18nWarnings"), qt.Equals, true)
|
2020-12-02 07:23:25 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2018-04-13 02:42:29 -04:00
|
|
|
|
|
|
|
for _, test := range tests {
|
2020-09-09 10:51:13 -04:00
|
|
|
c.Run(test.name, func(c *qt.C) {
|
|
|
|
b := newCommandsBuilder()
|
|
|
|
root := b.addAll().build()
|
2018-04-13 02:42:29 -04:00
|
|
|
|
2020-09-09 10:51:13 -04:00
|
|
|
for _, cmd := range b.commands {
|
|
|
|
if cmd.getCommand() == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// We are only intereseted in the flag handling here.
|
|
|
|
cmd.getCommand().RunE = noOpRunE
|
2018-04-16 02:23:32 -04:00
|
|
|
}
|
2020-09-09 10:51:13 -04:00
|
|
|
rootCmd := root.getCommand()
|
|
|
|
rootCmd.SetArgs(test.args)
|
|
|
|
c.Assert(rootCmd.Execute(), qt.IsNil)
|
|
|
|
test.check(c, b.commands[0].(*serverCmd))
|
|
|
|
})
|
2018-04-13 02:42:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandsExecute(t *testing.T) {
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
2018-04-10 13:16:09 -04:00
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
dir := createSimpleTestSite(t, testSiteConfig{})
|
|
|
|
dirOut := t.TempDir()
|
2018-04-10 13:16:09 -04:00
|
|
|
|
|
|
|
sourceFlag := fmt.Sprintf("-s=%s", dir)
|
|
|
|
|
|
|
|
tests := []struct {
|
2018-04-11 02:31:18 -04:00
|
|
|
commands []string
|
|
|
|
flags []string
|
|
|
|
expectErrToContain string
|
2018-04-10 13:16:09 -04:00
|
|
|
}{
|
2018-04-11 02:31:18 -04:00
|
|
|
// TODO(bep) permission issue on my OSX? "operation not permitted" {[]string{"check", "ulimit"}, nil, false},
|
|
|
|
{[]string{"env"}, nil, ""},
|
|
|
|
{[]string{"version"}, nil, ""},
|
2018-04-10 13:16:09 -04:00
|
|
|
// no args = hugo build
|
2018-04-11 02:31:18 -04:00
|
|
|
{nil, []string{sourceFlag}, ""},
|
2018-04-11 02:39:39 -04:00
|
|
|
{nil, []string{sourceFlag, "--renderToMemory"}, ""},
|
2022-01-30 18:33:15 -05:00
|
|
|
{[]string{"completion", "bash"}, nil, ""},
|
|
|
|
{[]string{"completion", "fish"}, nil, ""},
|
|
|
|
{[]string{"completion", "powershell"}, nil, ""},
|
|
|
|
{[]string{"completion", "zsh"}, nil, ""},
|
2018-04-11 04:09:45 -04:00
|
|
|
{[]string{"config"}, []string{sourceFlag}, ""},
|
2018-04-11 02:31:18 -04:00
|
|
|
{[]string{"convert", "toTOML"}, []string{sourceFlag, "-o=" + filepath.Join(dirOut, "toml")}, ""},
|
|
|
|
{[]string{"convert", "toYAML"}, []string{sourceFlag, "-o=" + filepath.Join(dirOut, "yaml")}, ""},
|
|
|
|
{[]string{"convert", "toJSON"}, []string{sourceFlag, "-o=" + filepath.Join(dirOut, "json")}, ""},
|
|
|
|
{[]string{"gen", "chromastyles"}, []string{"--style=manni"}, ""},
|
|
|
|
{[]string{"gen", "doc"}, []string{"--dir=" + filepath.Join(dirOut, "doc")}, ""},
|
|
|
|
{[]string{"gen", "man"}, []string{"--dir=" + filepath.Join(dirOut, "man")}, ""},
|
|
|
|
{[]string{"list", "drafts"}, []string{sourceFlag}, ""},
|
|
|
|
{[]string{"list", "expired"}, []string{sourceFlag}, ""},
|
|
|
|
{[]string{"list", "future"}, []string{sourceFlag}, ""},
|
|
|
|
{[]string{"new", "new-page.md"}, []string{sourceFlag}, ""},
|
|
|
|
{[]string{"new", "site", filepath.Join(dirOut, "new-site")}, nil, ""},
|
|
|
|
{[]string{"unknowncommand"}, nil, "unknown command"},
|
2018-04-10 13:16:09 -04:00
|
|
|
// TODO(bep) cli refactor fix https://github.com/gohugoio/hugo/issues/4450
|
2018-04-11 02:31:18 -04:00
|
|
|
//{[]string{"new", "theme", filepath.Join(dirOut, "new-theme")}, nil,false},
|
2018-04-10 13:16:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2022-03-21 04:35:15 -04:00
|
|
|
name := "hugo"
|
|
|
|
if len(test.commands) > 0 {
|
|
|
|
name = test.commands[0]
|
2018-04-11 02:31:18 -04:00
|
|
|
}
|
2022-03-21 04:35:15 -04:00
|
|
|
c.Run(name, func(c *qt.C) {
|
|
|
|
b := newCommandsBuilder().addAll().build()
|
|
|
|
hugoCmd := b.getCommand()
|
|
|
|
test.flags = append(test.flags, "--quiet")
|
|
|
|
hugoCmd.SetArgs(append(test.commands, test.flags...))
|
|
|
|
|
|
|
|
// TODO(bep) capture output and add some simple asserts
|
|
|
|
// TODO(bep) misspelled subcommands does not return an error. We should investigate this
|
|
|
|
// but before that, check for "Error: unknown command".
|
|
|
|
|
|
|
|
_, err := hugoCmd.ExecuteC()
|
|
|
|
if test.expectErrToContain != "" {
|
|
|
|
c.Assert(err, qt.Not(qt.IsNil))
|
|
|
|
c.Assert(err.Error(), qt.Contains, test.expectErrToContain)
|
|
|
|
} else {
|
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
}
|
2018-04-10 13:16:09 -04:00
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
// Assert that we have not left any development debug artifacts in
|
|
|
|
// the code.
|
|
|
|
if b.c != nil {
|
|
|
|
_, ok := b.c.publishDirFs.(types.DevMarker)
|
|
|
|
c.Assert(ok, qt.Equals, false)
|
|
|
|
}
|
|
|
|
})
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2018-04-10 13:16:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-01 02:40:53 -05:00
|
|
|
type testSiteConfig struct {
|
|
|
|
configTOML string
|
|
|
|
contentDir string
|
|
|
|
}
|
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
func createSimpleTestSite(t testing.TB, cfg testSiteConfig) string {
|
|
|
|
dir := t.TempDir()
|
2018-04-10 13:16:09 -04:00
|
|
|
|
2019-02-01 02:40:53 -05:00
|
|
|
cfgStr := `
|
2018-04-10 13:16:09 -04:00
|
|
|
|
|
|
|
baseURL = "https://example.org"
|
|
|
|
title = "Hugo Commands"
|
|
|
|
|
2020-01-31 03:09:11 -05:00
|
|
|
|
2019-02-01 02:40:53 -05:00
|
|
|
`
|
|
|
|
|
|
|
|
contentDir := "content"
|
|
|
|
|
|
|
|
if cfg.configTOML != "" {
|
|
|
|
cfgStr = cfg.configTOML
|
|
|
|
}
|
|
|
|
if cfg.contentDir != "" {
|
|
|
|
contentDir = cfg.contentDir
|
|
|
|
}
|
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
os.MkdirAll(filepath.Join(dir, "public"), 0777)
|
2020-01-31 03:09:11 -05:00
|
|
|
|
2019-02-01 02:40:53 -05:00
|
|
|
// Just the basic. These are for CLI tests, not site testing.
|
2022-03-21 04:35:15 -04:00
|
|
|
writeFile(t, filepath.Join(dir, "config.toml"), cfgStr)
|
|
|
|
writeFile(t, filepath.Join(dir, "config", "staging", "params.toml"), `myparam="paramstaging"`)
|
|
|
|
writeFile(t, filepath.Join(dir, "config", "staging", "deployment.toml"), `
|
2020-01-31 03:09:11 -05:00
|
|
|
[[targets]]
|
|
|
|
name = "mydeployment"
|
|
|
|
URL = "hugocloud://hugotestbucket"
|
|
|
|
`)
|
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
writeFile(t, filepath.Join(dir, "config", "testing", "params.toml"), `myparam="paramtesting"`)
|
|
|
|
writeFile(t, filepath.Join(dir, "config", "production", "params.toml"), `myparam="paramproduction"`)
|
2018-04-10 13:16:09 -04:00
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
writeFile(t, filepath.Join(dir, "static", "myfile.txt"), `Hello World!`)
|
2022-03-11 02:07:37 -05:00
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
writeFile(t, filepath.Join(dir, contentDir, "p1.md"), `
|
2018-04-10 13:16:09 -04:00
|
|
|
---
|
|
|
|
title: "P1"
|
|
|
|
weight: 1
|
|
|
|
---
|
|
|
|
|
|
|
|
Content
|
|
|
|
|
2022-09-17 05:25:37 -04:00
|
|
|
`)
|
|
|
|
|
|
|
|
writeFile(t, filepath.Join(dir, contentDir, "hügö.md"), `
|
|
|
|
---
|
|
|
|
weight: 2
|
|
|
|
---
|
|
|
|
|
|
|
|
This is hügö.
|
|
|
|
|
2018-04-10 13:16:09 -04:00
|
|
|
`)
|
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
writeFile(t, filepath.Join(dir, "layouts", "_default", "single.html"), `
|
2018-04-10 13:16:09 -04:00
|
|
|
|
2022-09-17 05:25:37 -04:00
|
|
|
Single: {{ .Title }}|{{ .Content }}
|
2018-04-10 13:16:09 -04:00
|
|
|
|
2022-09-13 05:33:42 -04:00
|
|
|
`)
|
|
|
|
|
|
|
|
writeFile(t, filepath.Join(dir, "layouts", "404.html"), `
|
|
|
|
404: {{ .Title }}|Not Found.
|
|
|
|
|
2018-04-10 13:16:09 -04:00
|
|
|
`)
|
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
writeFile(t, filepath.Join(dir, "layouts", "_default", "list.html"), `
|
2018-04-10 13:16:09 -04:00
|
|
|
|
|
|
|
List: {{ .Title }}
|
2018-11-15 03:28:02 -05:00
|
|
|
Environment: {{ hugo.Environment }}
|
2018-04-10 13:16:09 -04:00
|
|
|
|
2022-04-18 04:28:54 -04:00
|
|
|
For issue 9788:
|
|
|
|
{{ $foo :="abc" | resources.FromString "foo.css" | minify | resources.PostProcess }}
|
|
|
|
PostProcess: {{ $foo.RelPermalink }}
|
|
|
|
|
2018-04-10 13:16:09 -04:00
|
|
|
`)
|
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
return dir
|
2018-04-10 13:16:09 -04:00
|
|
|
}
|
|
|
|
|
2022-02-21 13:12:04 -05:00
|
|
|
func writeFile(t testing.TB, filename, content string) {
|
2018-04-10 13:16:09 -04:00
|
|
|
must(t, os.MkdirAll(filepath.Dir(filename), os.FileMode(0755)))
|
2023-02-18 17:43:26 -05:00
|
|
|
must(t, os.WriteFile(filename, []byte(content), os.FileMode(0755)))
|
2018-04-10 13:16:09 -04:00
|
|
|
}
|
|
|
|
|
2022-02-21 13:12:04 -05:00
|
|
|
func must(t testing.TB, err error) {
|
2018-04-10 13:16:09 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|