mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-31 10:42:38 +00:00
Compare commits
55 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f746a8724 | |||
| 6aa72acaf9 | |||
| 9885e7020d | |||
| 91101d24f2 | |||
| 637995ba8f | |||
| f1de5d2a04 | |||
| 4b0c194fb3 | |||
| 8de4ffb294 | |||
| 1f5a15aba0 | |||
| 8897113666 | |||
| e91d3cff98 | |||
| e7bd51698e | |||
| 1fad3832a9 | |||
| 8b52626915 | |||
| 5c5508817f | |||
| 81a7b63900 | |||
| 88ecc3b753 | |||
| 1191467c05 | |||
| 60c24fc5ee | |||
| 41137077bc | |||
| 5bb1564575 | |||
| 76993369a0 | |||
| de7137cc35 | |||
| a2edf04c27 | |||
| 956f915f77 | |||
| a2a4166f6d | |||
| 39f582f9f4 | |||
| 2501de7aab | |||
| 06cc8673fa | |||
| 71fae99189 | |||
| 8af04745fb | |||
| dde9d9d544 | |||
| 892b49110e | |||
| c5a63a3b4f | |||
| 61d3d20129 | |||
| b13d0a68e6 | |||
| d9594a96fc | |||
| 4a5cc2dd26 | |||
| 9cad8d38ca | |||
| cfa0801815 | |||
| f024a5050e | |||
| 80704bc9a1 | |||
| 3682027a51 | |||
| 44628616af | |||
| 0fc86783ee | |||
| e9fbadacc3 | |||
| 2a7bb1c7c9 | |||
| b7b49fb0f8 | |||
| 5f2adad2c7 | |||
| a837976731 | |||
| 0918e087ec | |||
| 4ea94c451d | |||
| 5d2cbee989 | |||
| 723e3f4342 | |||
| d913f46a8b |
@@ -3,3 +3,4 @@
|
||||
imports.*
|
||||
dist/
|
||||
public/
|
||||
.DS_Store
|
||||
@@ -101,6 +101,7 @@ Build the extended edition:
|
||||
```text
|
||||
CGO_ENABLED=1 go install -tags extended github.com/gohugoio/hugo@latest
|
||||
```
|
||||
|
||||
## Star History
|
||||
|
||||
[](https://star-history.com/#gohugoio/hugo&Timeline)
|
||||
@@ -154,7 +155,7 @@ github.com/bep/clocks="v0.5.0"
|
||||
github.com/bep/debounce="v1.2.0"
|
||||
github.com/bep/gitmap="v1.6.0"
|
||||
github.com/bep/goat="v0.5.0"
|
||||
github.com/bep/godartsass/v2="v2.3.0"
|
||||
github.com/bep/godartsass/v2="v2.3.2"
|
||||
github.com/bep/golibsass="v1.2.0"
|
||||
github.com/bep/gowebp="v0.3.0"
|
||||
github.com/bep/imagemeta="v0.8.3"
|
||||
@@ -189,7 +190,7 @@ github.com/gohugoio/locales="v0.14.0"
|
||||
github.com/gohugoio/localescompressed="v1.0.1"
|
||||
github.com/google/go-cmp="v0.6.0"
|
||||
github.com/gorilla/websocket="v1.5.3"
|
||||
github.com/hairyhenderson/go-codeowners="v0.6.1"
|
||||
github.com/hairyhenderson/go-codeowners="v0.7.0"
|
||||
github.com/hashicorp/golang-lru/v2="v2.0.7"
|
||||
github.com/invopop/yaml="v0.2.0"
|
||||
github.com/jdkato/prose="v1.2.1"
|
||||
@@ -218,30 +219,32 @@ github.com/russross/blackfriday/v2="v2.1.0"
|
||||
github.com/sass/dart-sass/compiler="1.81.0"
|
||||
github.com/sass/dart-sass/implementation="1.81.0"
|
||||
github.com/sass/dart-sass/protocol="3.1.0"
|
||||
github.com/sass/libsass="3.6.6"
|
||||
github.com/spf13/afero="v1.11.0"
|
||||
github.com/spf13/cast="v1.7.0"
|
||||
github.com/spf13/cast="v1.7.1"
|
||||
github.com/spf13/cobra="v1.8.1"
|
||||
github.com/spf13/fsync="v0.10.1"
|
||||
github.com/spf13/pflag="v1.0.5"
|
||||
github.com/tdewolff/minify/v2="v2.21.1"
|
||||
github.com/tdewolff/parse/v2="v2.7.18"
|
||||
github.com/tetratelabs/wazero="v1.8.1"
|
||||
github.com/tdewolff/minify/v2="v2.20.37"
|
||||
github.com/tdewolff/parse/v2="v2.7.15"
|
||||
github.com/tetratelabs/wazero="v1.8.2"
|
||||
github.com/webmproject/libwebp="v1.3.2"
|
||||
github.com/yuin/goldmark-emoji="v1.0.4"
|
||||
github.com/yuin/goldmark="v1.7.8"
|
||||
go.uber.org/automaxprocs="v1.5.3"
|
||||
golang.org/x/crypto="v0.29.0"
|
||||
golang.org/x/crypto="v0.31.0"
|
||||
golang.org/x/exp="v0.0.0-20221031165847-c99f073a8326"
|
||||
golang.org/x/image="v0.22.0"
|
||||
golang.org/x/mod="v0.22.0"
|
||||
golang.org/x/net="v0.31.0"
|
||||
golang.org/x/sync="v0.9.0"
|
||||
golang.org/x/sys="v0.27.0"
|
||||
golang.org/x/text="v0.20.0"
|
||||
golang.org/x/tools="v0.27.0"
|
||||
google.golang.org/protobuf="v1.35.1"
|
||||
golang.org/x/net="v0.33.0"
|
||||
golang.org/x/sync="v0.10.0"
|
||||
golang.org/x/sys="v0.28.0"
|
||||
golang.org/x/text="v0.21.0"
|
||||
golang.org/x/tools="v0.28.0"
|
||||
google.golang.org/protobuf="v1.35.2"
|
||||
gopkg.in/yaml.v2="v2.4.0"
|
||||
gopkg.in/yaml.v3="v3.0.1"
|
||||
howett.net/plist="v1.0.0"
|
||||
rsc.io/qr="v0.2.0"
|
||||
software.sslmate.com/src/go-pkcs12="v0.2.0"
|
||||
```
|
||||
</details>
|
||||
|
||||
@@ -447,6 +447,8 @@ func (r *rootCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Set up the global logger early to allow info deprecations during config load.
|
||||
loggers.InitGlobalLogger(r.logger.Level(), false)
|
||||
|
||||
r.changesFromBuild = make(chan []identity.Identity, 10)
|
||||
|
||||
@@ -538,6 +540,7 @@ Complete documentation is available at https://gohugo.io/.`
|
||||
cmd.PersistentFlags().StringP("themesDir", "", "", "filesystem path to themes directory")
|
||||
_ = cmd.MarkFlagDirname("themesDir")
|
||||
cmd.PersistentFlags().StringP("ignoreVendorPaths", "", "", "ignores any _vendor for module paths matching the given Glob pattern")
|
||||
cmd.PersistentFlags().BoolP("noBuildLock", "", false, "don't create .hugo_build.lock file")
|
||||
_ = cmd.RegisterFlagCompletionFunc("ignoreVendorPaths", cobra.NoFileCompletions)
|
||||
cmd.PersistentFlags().String("clock", "", "set the clock used by Hugo, e.g. --clock 2021-11-06T22:30:00.00+09:00")
|
||||
_ = cmd.RegisterFlagCompletionFunc("clock", cobra.NoFileCompletions)
|
||||
@@ -593,7 +596,6 @@ func applyLocalFlagsBuild(cmd *cobra.Command, r *rootCommand) {
|
||||
cmd.Flags().BoolVar(&r.forceSyncStatic, "forceSyncStatic", false, "copy all files when static is changed.")
|
||||
cmd.Flags().BoolP("noTimes", "", false, "don't sync modification time of files")
|
||||
cmd.Flags().BoolP("noChmod", "", false, "don't sync permission mode of files")
|
||||
cmd.Flags().BoolP("noBuildLock", "", false, "don't create .hugo_build.lock file")
|
||||
cmd.Flags().BoolP("printI18nWarnings", "", false, "print missing translations")
|
||||
cmd.Flags().BoolP("printPathWarnings", "", false, "print warnings on duplicate target paths etc.")
|
||||
cmd.Flags().BoolP("printUnusedTemplates", "", false, "print warnings on unused templates.")
|
||||
|
||||
+5
-3
@@ -43,8 +43,9 @@ func newConfigCommand() *configCommand {
|
||||
type configCommand struct {
|
||||
r *rootCommand
|
||||
|
||||
format string
|
||||
lang string
|
||||
format string
|
||||
lang string
|
||||
printZero bool
|
||||
|
||||
commands []simplecobra.Commander
|
||||
}
|
||||
@@ -78,7 +79,7 @@ func (c *configCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, arg
|
||||
dec.SetIndent("", " ")
|
||||
dec.SetEscapeHTML(false)
|
||||
|
||||
if err := dec.Encode(parser.ReplacingJSONMarshaller{Value: config, KeysToLower: true, OmitEmpty: true}); err != nil {
|
||||
if err := dec.Encode(parser.ReplacingJSONMarshaller{Value: config, KeysToLower: true, OmitEmpty: !c.printZero}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -115,6 +116,7 @@ func (c *configCommand) Init(cd *simplecobra.Commandeer) error {
|
||||
cmd.Flags().StringVar(&c.format, "format", "toml", "preferred file format (toml, yaml or json)")
|
||||
_ = cmd.RegisterFlagCompletionFunc("format", cobra.FixedCompletions([]string{"toml", "yaml", "json"}, cobra.ShellCompDirectiveNoFileComp))
|
||||
cmd.Flags().StringVar(&c.lang, "lang", "", "the language to display config for. Defaults to the first language defined.")
|
||||
cmd.Flags().BoolVar(&c.printZero, "printZero", false, `include config options with zero values (e.g. false, 0, "") in the output`)
|
||||
_ = cmd.RegisterFlagCompletionFunc("lang", cobra.NoFileCompletions)
|
||||
applyLocalFlagsBuildConfig(cmd, c.r)
|
||||
|
||||
|
||||
@@ -38,6 +38,19 @@ func XXHashFromReader(r io.Reader) (uint64, int64, error) {
|
||||
return h.Sum64(), size, nil
|
||||
}
|
||||
|
||||
// XxHashFromReaderHexEncoded calculates the xxHash for the given reader
|
||||
// and returns the hash as a hex encoded string.
|
||||
func XxHashFromReaderHexEncoded(r io.Reader) (string, error) {
|
||||
h := getXxHashReadFrom()
|
||||
defer putXxHashReadFrom(h)
|
||||
_, err := io.Copy(h, r)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
hash := h.Sum(nil)
|
||||
return hex.EncodeToString(hash), nil
|
||||
}
|
||||
|
||||
// XXHashFromString calculates the xxHash for the given string.
|
||||
func XXHashFromString(s string) (uint64, error) {
|
||||
h := xxhash.New()
|
||||
@@ -70,6 +83,13 @@ func HashString(vs ...any) string {
|
||||
return strconv.FormatUint(hash, 10)
|
||||
}
|
||||
|
||||
// HashStringHex returns a hash from the given elements as a hex encoded string.
|
||||
// See HashString for more information.
|
||||
func HashStringHex(vs ...any) string {
|
||||
hash := HashUint64(vs...)
|
||||
return strconv.FormatUint(hash, 16)
|
||||
}
|
||||
|
||||
var hashOptsPool = sync.Pool{
|
||||
New: func() any {
|
||||
return &hashstructure.HashOptions{
|
||||
|
||||
@@ -142,3 +142,16 @@ func BenchmarkHashString(b *testing.B) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkHashMap(b *testing.B) {
|
||||
m := map[string]interface{}{}
|
||||
for i := 0; i < 1000; i++ {
|
||||
m[fmt.Sprintf("key%d", i)] = i
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
HashString(m)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,8 +258,27 @@ func openFile(filename string, fs afero.Fs) (afero.File, string, error) {
|
||||
return f, realFilename, nil
|
||||
}
|
||||
|
||||
// Cause returns the underlying error or itself if it does not implement Unwrap.
|
||||
// Cause returns the underlying error, that is,
|
||||
// it unwraps errors until it finds one that does not implement
|
||||
// the Unwrap method.
|
||||
// For a shallow variant, see Unwrap.
|
||||
func Cause(err error) error {
|
||||
type unwrapper interface {
|
||||
Unwrap() error
|
||||
}
|
||||
|
||||
for err != nil {
|
||||
cause, ok := err.(unwrapper)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
err = cause.Unwrap()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Unwrap returns the underlying error or itself if it does not implement Unwrap.
|
||||
func Unwrap(err error) error {
|
||||
if u := errors.Unwrap(err); u != nil {
|
||||
return u
|
||||
}
|
||||
@@ -267,7 +286,7 @@ func Cause(err error) error {
|
||||
}
|
||||
|
||||
func extractFileTypePos(err error) (string, text.Position) {
|
||||
err = Cause(err)
|
||||
err = Unwrap(err)
|
||||
|
||||
var fileType string
|
||||
|
||||
|
||||
+85
-17
@@ -26,7 +26,10 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/bep/logg"
|
||||
"github.com/cli/safeexec"
|
||||
"github.com/gohugoio/hugo/common/loggers"
|
||||
"github.com/gohugoio/hugo/common/maps"
|
||||
"github.com/gohugoio/hugo/config"
|
||||
"github.com/gohugoio/hugo/config/security"
|
||||
)
|
||||
@@ -86,7 +89,7 @@ var WithEnviron = func(env []string) func(c *commandeer) {
|
||||
}
|
||||
|
||||
// New creates a new Exec using the provided security config.
|
||||
func New(cfg security.Config, workingDir string) *Exec {
|
||||
func New(cfg security.Config, workingDir string, log loggers.Logger) *Exec {
|
||||
var baseEnviron []string
|
||||
for _, v := range os.Environ() {
|
||||
k, _ := config.SplitEnvVar(v)
|
||||
@@ -96,9 +99,11 @@ func New(cfg security.Config, workingDir string) *Exec {
|
||||
}
|
||||
|
||||
return &Exec{
|
||||
sc: cfg,
|
||||
workingDir: workingDir,
|
||||
baseEnviron: baseEnviron,
|
||||
sc: cfg,
|
||||
workingDir: workingDir,
|
||||
infol: log.InfoCommand("exec"),
|
||||
baseEnviron: baseEnviron,
|
||||
newNPXRunnerCache: maps.NewCache[string, func(arg ...any) (Runner, error)](),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,12 +129,14 @@ func SafeCommand(name string, arg ...string) (*exec.Cmd, error) {
|
||||
type Exec struct {
|
||||
sc security.Config
|
||||
workingDir string
|
||||
infol logg.LevelLogger
|
||||
|
||||
// os.Environ filtered by the Exec.OsEnviron whitelist filter.
|
||||
baseEnviron []string
|
||||
|
||||
npxInit sync.Once
|
||||
npxAvailable bool
|
||||
newNPXRunnerCache *maps.Cache[string, func(arg ...any) (Runner, error)]
|
||||
npxInit sync.Once
|
||||
npxAvailable bool
|
||||
}
|
||||
|
||||
func (e *Exec) New(name string, arg ...any) (Runner, error) {
|
||||
@@ -155,25 +162,86 @@ func (e *Exec) new(name string, fullyQualifiedName string, arg ...any) (Runner,
|
||||
return cm.command(arg...)
|
||||
}
|
||||
|
||||
type binaryLocation int
|
||||
|
||||
func (b binaryLocation) String() string {
|
||||
switch b {
|
||||
case binaryLocationNodeModules:
|
||||
return "node_modules/.bin"
|
||||
case binaryLocationNpx:
|
||||
return "npx"
|
||||
case binaryLocationPath:
|
||||
return "PATH"
|
||||
}
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
const (
|
||||
binaryLocationNodeModules binaryLocation = iota + 1
|
||||
binaryLocationNpx
|
||||
binaryLocationPath
|
||||
)
|
||||
|
||||
// Npx will in order:
|
||||
// 1. Try fo find the binary in the WORKINGDIR/node_modules/.bin directory.
|
||||
// 2. If not found, and npx is available, run npx --no-install <name> <args>.
|
||||
// 3. Fall back to the PATH.
|
||||
// If name is "tailwindcss", we will try the PATH as the second option.
|
||||
func (e *Exec) Npx(name string, arg ...any) (Runner, error) {
|
||||
// npx is slow, so first try the common case.
|
||||
nodeBinFilename := filepath.Join(e.workingDir, nodeModulesBinPath, name)
|
||||
_, err := safeexec.LookPath(nodeBinFilename)
|
||||
if err == nil {
|
||||
return e.new(name, nodeBinFilename, arg...)
|
||||
if err := e.sc.CheckAllowedExec(name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
e.checkNpx()
|
||||
if e.npxAvailable {
|
||||
r, err := e.npx(name, arg...)
|
||||
if err == nil {
|
||||
return r, nil
|
||||
|
||||
newRunner, err := e.newNPXRunnerCache.GetOrCreate(name, func() (func(...any) (Runner, error), error) {
|
||||
type tryFunc func() func(...any) (Runner, error)
|
||||
tryFuncs := map[binaryLocation]tryFunc{
|
||||
binaryLocationNodeModules: func() func(...any) (Runner, error) {
|
||||
nodeBinFilename := filepath.Join(e.workingDir, nodeModulesBinPath, name)
|
||||
_, err := safeexec.LookPath(nodeBinFilename)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return func(arg2 ...any) (Runner, error) {
|
||||
return e.new(name, nodeBinFilename, arg2...)
|
||||
}
|
||||
},
|
||||
binaryLocationNpx: func() func(...any) (Runner, error) {
|
||||
e.checkNpx()
|
||||
if !e.npxAvailable {
|
||||
return nil
|
||||
}
|
||||
return func(arg2 ...any) (Runner, error) {
|
||||
return e.npx(name, arg2...)
|
||||
}
|
||||
},
|
||||
binaryLocationPath: func() func(...any) (Runner, error) {
|
||||
if _, err := safeexec.LookPath(name); err != nil {
|
||||
return nil
|
||||
}
|
||||
return func(arg2 ...any) (Runner, error) {
|
||||
return e.New(name, arg2...)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
locations := []binaryLocation{binaryLocationNodeModules, binaryLocationNpx, binaryLocationPath}
|
||||
if name == "tailwindcss" {
|
||||
// See https://github.com/gohugoio/hugo/issues/13221#issuecomment-2574801253
|
||||
locations = []binaryLocation{binaryLocationNodeModules, binaryLocationPath, binaryLocationNpx}
|
||||
}
|
||||
for _, loc := range locations {
|
||||
if f := tryFuncs[loc](); f != nil {
|
||||
e.infol.Logf("resolve %q using %s", name, loc)
|
||||
return f, nil
|
||||
}
|
||||
}
|
||||
return nil, &NotFoundError{name: name, method: fmt.Sprintf("in %s", locations[len(locations)-1])}
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e.New(name, arg...)
|
||||
|
||||
return newRunner(arg...)
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -48,16 +48,16 @@ func TestHasBytesWriter(t *testing.T) {
|
||||
|
||||
for i := 0; i < 22; i++ {
|
||||
h, w := neww()
|
||||
fmt.Fprintf(w, rndStr()+"abc __foobar"+rndStr())
|
||||
fmt.Fprint(w, rndStr()+"abc __foobar"+rndStr())
|
||||
c.Assert(h.Patterns[0].Match, qt.Equals, true)
|
||||
|
||||
h, w = neww()
|
||||
fmt.Fprintf(w, rndStr()+"abc __f")
|
||||
fmt.Fprintf(w, "oo bar"+rndStr())
|
||||
fmt.Fprint(w, rndStr()+"abc __f")
|
||||
fmt.Fprint(w, "oo bar"+rndStr())
|
||||
c.Assert(h.Patterns[0].Match, qt.Equals, true)
|
||||
|
||||
h, w = neww()
|
||||
fmt.Fprintf(w, rndStr()+"abc __moo bar")
|
||||
fmt.Fprint(w, rndStr()+"abc __moo bar")
|
||||
c.Assert(h.Patterns[0].Match, qt.Equals, false)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -423,7 +423,7 @@ func DeprecateLevel(item, alternative, version string, level logg.Level) {
|
||||
msg = fmt.Sprintf("%s was deprecated in Hugo %s and will be removed in a future release. %s", item, version, alternative)
|
||||
}
|
||||
|
||||
loggers.Log().Logger().WithLevel(level).WithField(loggers.FieldNameCmd, "deprecated").Logf(msg)
|
||||
loggers.Log().Logger().WithLevel(level).WithField(loggers.FieldNameCmd, "deprecated").Logf("%s", msg)
|
||||
}
|
||||
|
||||
// We usually do about one minor version a month.
|
||||
|
||||
@@ -17,7 +17,7 @@ package hugo
|
||||
// This should be the only one.
|
||||
var CurrentVersion = Version{
|
||||
Major: 0,
|
||||
Minor: 141,
|
||||
Minor: 142,
|
||||
PatchLevel: 0,
|
||||
Suffix: "-DEV",
|
||||
Suffix: "",
|
||||
}
|
||||
|
||||
+1
-1
@@ -228,7 +228,7 @@ func UrlFromFilename(filename string) (*url.URL, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UrlToFilename converts the URL s to a filename.
|
||||
// UrlStringToFilename converts the URL s to a filename.
|
||||
// If ParseRequestURI fails, the input is just converted to OS specific slashes and returned.
|
||||
func UrlStringToFilename(s string) (string, bool) {
|
||||
u, err := url.ParseRequestURI(s)
|
||||
|
||||
@@ -133,22 +133,3 @@ func NewBool(b bool) *bool {
|
||||
type PrintableValueProvider interface {
|
||||
PrintableValue() any
|
||||
}
|
||||
|
||||
var _ PrintableValueProvider = Result[any]{}
|
||||
|
||||
// Result is a generic result type.
|
||||
type Result[T any] struct {
|
||||
// The result value.
|
||||
Value T
|
||||
|
||||
// The error value.
|
||||
Err error
|
||||
}
|
||||
|
||||
// PrintableValue returns the value or panics if there is an error.
|
||||
func (r Result[T]) PrintableValue() any {
|
||||
if r.Err != nil {
|
||||
panic(r.Err)
|
||||
}
|
||||
return r.Value
|
||||
}
|
||||
|
||||
@@ -301,6 +301,18 @@ func (c *Config) CompileConfig(logger loggers.Logger) error {
|
||||
}
|
||||
}
|
||||
|
||||
defaultOutputFormat := outputFormats[0]
|
||||
c.DefaultOutputFormat = strings.ToLower(c.DefaultOutputFormat)
|
||||
if c.DefaultOutputFormat != "" {
|
||||
f, found := outputFormats.GetByName(c.DefaultOutputFormat)
|
||||
if !found {
|
||||
return fmt.Errorf("unknown default output format %q", c.DefaultOutputFormat)
|
||||
}
|
||||
defaultOutputFormat = f
|
||||
} else {
|
||||
c.DefaultOutputFormat = defaultOutputFormat.Name
|
||||
}
|
||||
|
||||
disabledLangs := make(map[string]bool)
|
||||
for _, lang := range c.DisableLanguages {
|
||||
disabledLangs[lang] = true
|
||||
@@ -390,23 +402,46 @@ func (c *Config) CompileConfig(logger loggers.Logger) error {
|
||||
c.Pagination.Path = c.PaginatePath
|
||||
}
|
||||
|
||||
// Legacy privacy values.
|
||||
if c.Privacy.Twitter.Disable {
|
||||
hugo.Deprecate("site config key privacy.twitter.disable", "Use privacy.x.disable instead.", "v0.141.0")
|
||||
c.Privacy.X.Disable = c.Privacy.Twitter.Disable
|
||||
}
|
||||
|
||||
if c.Privacy.Twitter.EnableDNT {
|
||||
hugo.Deprecate("site config key privacy.twitter.enableDNT", "Use privacy.x.enableDNT instead.", "v0.141.0")
|
||||
c.Privacy.X.EnableDNT = c.Privacy.Twitter.EnableDNT
|
||||
}
|
||||
|
||||
if c.Privacy.Twitter.Simple {
|
||||
hugo.Deprecate("site config key privacy.twitter.simple", "Use privacy.x.simple instead.", "v0.141.0")
|
||||
c.Privacy.X.Simple = c.Privacy.Twitter.Simple
|
||||
}
|
||||
|
||||
// Legacy services values.
|
||||
if c.Services.Twitter.DisableInlineCSS {
|
||||
hugo.Deprecate("site config key services.twitter.disableInlineCSS", "Use services.x.disableInlineCSS instead.", "v0.141.0")
|
||||
c.Services.X.DisableInlineCSS = c.Services.Twitter.DisableInlineCSS
|
||||
}
|
||||
|
||||
c.C = &ConfigCompiled{
|
||||
Timeout: timeout,
|
||||
BaseURL: baseURL,
|
||||
BaseURLLiveReload: baseURL,
|
||||
DisabledKinds: disabledKinds,
|
||||
DisabledLanguages: disabledLangs,
|
||||
IgnoredLogs: ignoredLogIDs,
|
||||
KindOutputFormats: kindOutputFormats,
|
||||
ContentTypes: media.DefaultContentTypes.FromTypes(c.MediaTypes.Config),
|
||||
CreateTitle: helpers.GetTitleFunc(c.TitleCaseStyle),
|
||||
IsUglyURLSection: isUglyURL,
|
||||
IgnoreFile: ignoreFile,
|
||||
SegmentFilter: c.Segments.Config.Get(func(s string) { logger.Warnf("Render segment %q not found in configuration", s) }, c.RootConfig.RenderSegments...),
|
||||
MainSections: c.MainSections,
|
||||
Clock: clock,
|
||||
HTTPCache: httpCache,
|
||||
transientErr: transientErr,
|
||||
Timeout: timeout,
|
||||
BaseURL: baseURL,
|
||||
BaseURLLiveReload: baseURL,
|
||||
DisabledKinds: disabledKinds,
|
||||
DisabledLanguages: disabledLangs,
|
||||
IgnoredLogs: ignoredLogIDs,
|
||||
KindOutputFormats: kindOutputFormats,
|
||||
DefaultOutputFormat: defaultOutputFormat,
|
||||
ContentTypes: media.DefaultContentTypes.FromTypes(c.MediaTypes.Config),
|
||||
CreateTitle: helpers.GetTitleFunc(c.TitleCaseStyle),
|
||||
IsUglyURLSection: isUglyURL,
|
||||
IgnoreFile: ignoreFile,
|
||||
SegmentFilter: c.Segments.Config.Get(func(s string) { logger.Warnf("Render segment %q not found in configuration", s) }, c.RootConfig.RenderSegments...),
|
||||
MainSections: c.MainSections,
|
||||
Clock: clock,
|
||||
HTTPCache: httpCache,
|
||||
transientErr: transientErr,
|
||||
}
|
||||
|
||||
for _, s := range allDecoderSetups {
|
||||
@@ -430,22 +465,23 @@ func (c *Config) IsLangDisabled(lang string) bool {
|
||||
|
||||
// ConfigCompiled holds values and functions that are derived from the config.
|
||||
type ConfigCompiled struct {
|
||||
Timeout time.Duration
|
||||
BaseURL urls.BaseURL
|
||||
BaseURLLiveReload urls.BaseURL
|
||||
ServerInterface string
|
||||
KindOutputFormats map[string]output.Formats
|
||||
ContentTypes media.ContentTypes
|
||||
DisabledKinds map[string]bool
|
||||
DisabledLanguages map[string]bool
|
||||
IgnoredLogs map[string]bool
|
||||
CreateTitle func(s string) string
|
||||
IsUglyURLSection func(section string) bool
|
||||
IgnoreFile func(filename string) bool
|
||||
SegmentFilter segments.SegmentFilter
|
||||
MainSections []string
|
||||
Clock time.Time
|
||||
HTTPCache httpcache.ConfigCompiled
|
||||
Timeout time.Duration
|
||||
BaseURL urls.BaseURL
|
||||
BaseURLLiveReload urls.BaseURL
|
||||
ServerInterface string
|
||||
KindOutputFormats map[string]output.Formats
|
||||
DefaultOutputFormat output.Format
|
||||
ContentTypes media.ContentTypes
|
||||
DisabledKinds map[string]bool
|
||||
DisabledLanguages map[string]bool
|
||||
IgnoredLogs map[string]bool
|
||||
CreateTitle func(s string) string
|
||||
IsUglyURLSection func(section string) bool
|
||||
IgnoreFile func(filename string) bool
|
||||
SegmentFilter segments.SegmentFilter
|
||||
MainSections []string
|
||||
Clock time.Time
|
||||
HTTPCache httpcache.ConfigCompiled
|
||||
|
||||
// This is set to the last transient error found during config compilation.
|
||||
// With themes/modules we compute the configuration in multiple passes, and
|
||||
@@ -505,6 +541,10 @@ type RootConfig struct {
|
||||
// Set this to true to put all languages below their language ID.
|
||||
DefaultContentLanguageInSubdir bool
|
||||
|
||||
// The default output format to use for the site.
|
||||
// If not set, we will use the first output format.
|
||||
DefaultOutputFormat string
|
||||
|
||||
// Disable generation of redirect to the default language when DefaultContentLanguageInSubdir is enabled.
|
||||
DisableDefaultLanguageRedirect bool
|
||||
|
||||
|
||||
@@ -470,7 +470,7 @@ func (l *configLoader) loadModules(configs *Configs, ignoreModuleDoesNotExist bo
|
||||
ignoreVendor, _ = hglob.GetGlob(hglob.NormalizePath(s))
|
||||
}
|
||||
|
||||
ex := hexec.New(conf.Security, workingDir)
|
||||
ex := hexec.New(conf.Security, workingDir, l.Logger)
|
||||
|
||||
hook := func(m *modules.ModulesConfig) error {
|
||||
for _, tc := range m.AllModules {
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import (
|
||||
func DecodeNamespace[S, C any](configSource any, buildConfig func(any) (C, any, error)) (*ConfigNamespace[S, C], error) {
|
||||
// Calculate the hash of the input (not including any defaults applied later).
|
||||
// This allows us to introduce new config options without breaking the hash.
|
||||
h := hashing.HashString(configSource)
|
||||
h := hashing.HashStringHex(configSource)
|
||||
|
||||
// Build the config
|
||||
c, ext, err := buildConfig(configSource)
|
||||
|
||||
@@ -43,7 +43,7 @@ func TestNamespace(t *testing.T) {
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(ns, qt.Not(qt.IsNil))
|
||||
c.Assert(ns.SourceStructure, qt.DeepEquals, map[string]interface{}{"foo": "bar"})
|
||||
c.Assert(ns.SourceHash, qt.Equals, "1450430416588600409")
|
||||
c.Assert(ns.SourceHash, qt.Equals, "1420f6c7782f7459")
|
||||
c.Assert(ns.Config, qt.DeepEquals, &tstNsExt{Foo: "bar"})
|
||||
c.Assert(ns.Signature(), qt.DeepEquals, []*tstNsExt(nil))
|
||||
}
|
||||
|
||||
@@ -30,9 +30,10 @@ type Config struct {
|
||||
Disqus Disqus
|
||||
GoogleAnalytics GoogleAnalytics
|
||||
Instagram Instagram
|
||||
Twitter Twitter
|
||||
Twitter Twitter // deprecated in favor of X in v0.141.0
|
||||
Vimeo Vimeo
|
||||
YouTube YouTube
|
||||
X X
|
||||
}
|
||||
|
||||
// Disqus holds the privacy configuration settings related to the Disqus template.
|
||||
@@ -58,7 +59,8 @@ type Instagram struct {
|
||||
Simple bool
|
||||
}
|
||||
|
||||
// Twitter holds the privacy configuration settingsrelated to the Twitter shortcode.
|
||||
// Twitter holds the privacy configuration settings related to the Twitter shortcode.
|
||||
// Deprecated in favor of X in v0.141.0.
|
||||
type Twitter struct {
|
||||
Service `mapstructure:",squash"`
|
||||
|
||||
@@ -70,7 +72,7 @@ type Twitter struct {
|
||||
Simple bool
|
||||
}
|
||||
|
||||
// Vimeo holds the privacy configuration settingsrelated to the Vimeo shortcode.
|
||||
// Vimeo holds the privacy configuration settings related to the Vimeo shortcode.
|
||||
type Vimeo struct {
|
||||
Service `mapstructure:",squash"`
|
||||
|
||||
@@ -84,7 +86,7 @@ type Vimeo struct {
|
||||
Simple bool
|
||||
}
|
||||
|
||||
// YouTube holds the privacy configuration settingsrelated to the YouTube shortcode.
|
||||
// YouTube holds the privacy configuration settings related to the YouTube shortcode.
|
||||
type YouTube struct {
|
||||
Service `mapstructure:",squash"`
|
||||
|
||||
@@ -94,6 +96,20 @@ type YouTube struct {
|
||||
PrivacyEnhanced bool
|
||||
}
|
||||
|
||||
// X holds the privacy configuration settings related to the X shortcode.
|
||||
type X struct {
|
||||
Service `mapstructure:",squash"`
|
||||
|
||||
// When set to true, the X post and its embedded page on your site are not
|
||||
// used for purposes that include personalized suggestions and personalized
|
||||
// ads.
|
||||
EnableDNT bool
|
||||
|
||||
// If simple mode is enabled, a static and no-JS version of the X post will
|
||||
// be built.
|
||||
Simple bool
|
||||
}
|
||||
|
||||
// DecodeConfig creates a privacy Config from a given Hugo configuration.
|
||||
func DecodeConfig(cfg config.Provider) (pc Config, err error) {
|
||||
if !cfg.IsSet(privacyConfigKey) {
|
||||
|
||||
@@ -40,6 +40,10 @@ simple = true
|
||||
disable = true
|
||||
enableDNT = true
|
||||
simple = true
|
||||
[privacy.x]
|
||||
disable = true
|
||||
enableDNT = true
|
||||
simple = true
|
||||
[privacy.vimeo]
|
||||
disable = true
|
||||
enableDNT = true
|
||||
@@ -61,7 +65,8 @@ simple = true
|
||||
pc.GoogleAnalytics.RespectDoNotTrack, pc.Instagram.Disable,
|
||||
pc.Instagram.Simple, pc.Twitter.Disable, pc.Twitter.EnableDNT,
|
||||
pc.Twitter.Simple, pc.Vimeo.Disable, pc.Vimeo.EnableDNT, pc.Vimeo.Simple,
|
||||
pc.YouTube.PrivacyEnhanced, pc.YouTube.Disable,
|
||||
pc.YouTube.PrivacyEnhanced, pc.YouTube.Disable, pc.X.Disable, pc.X.EnableDNT,
|
||||
pc.X.Simple,
|
||||
}
|
||||
|
||||
c.Assert(got, qt.All(qt.Equals), true)
|
||||
|
||||
@@ -31,7 +31,8 @@ type Config struct {
|
||||
Disqus Disqus
|
||||
GoogleAnalytics GoogleAnalytics
|
||||
Instagram Instagram
|
||||
Twitter Twitter
|
||||
Twitter Twitter // deprecated in favor of X in v0.141.0
|
||||
X X
|
||||
RSS RSS
|
||||
}
|
||||
|
||||
@@ -61,6 +62,7 @@ type Instagram struct {
|
||||
}
|
||||
|
||||
// Twitter holds the functional configuration settings related to the Twitter shortcodes.
|
||||
// Deprecated in favor of X in v0.141.0.
|
||||
type Twitter struct {
|
||||
// The Simple variant of Twitter is decorated with a basic set of inline styles.
|
||||
// This means that if you want to provide your own CSS, you want
|
||||
@@ -68,6 +70,14 @@ type Twitter struct {
|
||||
DisableInlineCSS bool
|
||||
}
|
||||
|
||||
// X holds the functional configuration settings related to the X shortcodes.
|
||||
type X struct {
|
||||
// The Simple variant of X is decorated with a basic set of inline styles.
|
||||
// This means that if you want to provide your own CSS, you want
|
||||
// to disable the inline CSS provided by Hugo.
|
||||
DisableInlineCSS bool
|
||||
}
|
||||
|
||||
// RSS holds the functional configuration settings related to the RSS feeds.
|
||||
type RSS struct {
|
||||
// Limit the number of pages.
|
||||
|
||||
@@ -36,6 +36,8 @@ id = "ga_id"
|
||||
disableInlineCSS = true
|
||||
[services.twitter]
|
||||
disableInlineCSS = true
|
||||
[services.x]
|
||||
disableInlineCSS = true
|
||||
`
|
||||
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
+6
-4
@@ -82,11 +82,13 @@ func NewContent(h *hugolib.HugoSites, kind, targetPath string, force bool) error
|
||||
b.setArcheTypeFilenameToUse(ext)
|
||||
|
||||
withBuildLock := func() (string, error) {
|
||||
unlock, err := h.BaseFs.LockBuild()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to acquire a build lock: %s", err)
|
||||
if !h.Configs.Base.NoBuildLock {
|
||||
unlock, err := h.BaseFs.LockBuild()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to acquire a build lock: %s", err)
|
||||
}
|
||||
defer unlock()
|
||||
}
|
||||
defer unlock()
|
||||
|
||||
if b.isDir {
|
||||
return "", b.buildDir()
|
||||
|
||||
Vendored
+1
-1
@@ -188,7 +188,7 @@ func (d *Deps) Init() error {
|
||||
}
|
||||
|
||||
if d.ExecHelper == nil {
|
||||
d.ExecHelper = hexec.New(d.Conf.GetConfigSection("security").(security.Config), d.Conf.WorkingDir())
|
||||
d.ExecHelper = hexec.New(d.Conf.GetConfigSection("security").(security.Config), d.Conf.WorkingDir(), d.Log)
|
||||
}
|
||||
|
||||
if d.MemCache == nil {
|
||||
|
||||
@@ -18,3 +18,8 @@ h6:first-of-type {
|
||||
h6 ~ p {
|
||||
margin: 0.5em 0 2em 0;
|
||||
}
|
||||
|
||||
/* QR codes */
|
||||
img.qrcode {
|
||||
width: initial;
|
||||
}
|
||||
|
||||
@@ -5333,6 +5333,11 @@ h6:first-of-type {
|
||||
h6 ~ p {
|
||||
margin: 0.5em 0 2em 0;
|
||||
}
|
||||
/* QR codes */
|
||||
img.qrcode {
|
||||
width: auto;
|
||||
width: initial;
|
||||
}
|
||||
.nested-blockquote blockquote {
|
||||
border-left: 4px solid #0594CB;
|
||||
padding-left: 1em;
|
||||
|
||||
@@ -5,15 +5,6 @@
|
||||
utm_campaign = "hugosponsor"
|
||||
bgcolor = "#ffffff"
|
||||
|
||||
[[banners]]
|
||||
name = "Route4Me"
|
||||
link = "https://route4me.com/"
|
||||
title = "Route Planning & Route Optimization Software"
|
||||
no_query_params = true
|
||||
utm_campaign = "hugosponsor"
|
||||
bgcolor = "#334799"
|
||||
link_attr = "style='color: #ffffff; font-weight: bold; text-decoration: none; text-align: center'"
|
||||
|
||||
[[banners]]
|
||||
name = "GoLand"
|
||||
title = "The complete IDE crafted for professional Go developers."
|
||||
@@ -21,3 +12,11 @@
|
||||
link = "https://www.jetbrains.com/go/?utm_source=OSS&utm_medium=referral&utm_campaign=hugo"
|
||||
logo = "images/sponsors/goland.svg"
|
||||
bgcolor = "#f4f4f4"
|
||||
|
||||
[[banners]]
|
||||
name = "Your Company?"
|
||||
link = "https://bep.is/en/hugo-sponsor-2023-01/"
|
||||
utm_campaign = "hugosponsor"
|
||||
show_on_hover = true
|
||||
bgcolor = "#4e4f4f"
|
||||
link_attr = "style='color: #ffffff; font-weight: bold; text-decoration: none; text-align: center'"
|
||||
|
||||
+1
-6
@@ -98,12 +98,7 @@ either of these shortcodes in conjunction with this render hook.
|
||||
{{- end }}
|
||||
|
||||
{{- /* Determine content path for warning and error messages. */}}
|
||||
{{- $contentPath := "" }}
|
||||
{{- with .Page.File }}
|
||||
{{- $contentPath = .Path }}
|
||||
{{- else }}
|
||||
{{- $contentPath = .Path }}
|
||||
{{- end }}
|
||||
{{- $contentPath := .Page.String }}
|
||||
|
||||
{{- /* Parse destination. */}}
|
||||
{{- $u := urls.Parse .Destination }}
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ You must call this shortcode using the {{% %}} notation.
|
||||
*/}}
|
||||
|
||||
{{- with .Get 0 }}
|
||||
{{- with site.GetPage . }}
|
||||
{{- with $.Page.GetPage . }}
|
||||
{{- .RenderShortcodes }}
|
||||
{{- else }}
|
||||
{{- errorf "The %q shortcode was unable to find %q. See %s" $.Name . $.Position }}
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
# github.com/gohugoio/gohugoioTheme v0.0.0-20241119115653-b92d27ede3e1
|
||||
|
||||
# github.com/gohugoio/gohugoioTheme v0.0.0-20250106044328-feb60697e056
|
||||
|
||||
@@ -29,6 +29,7 @@ See each sub-command's help for details on how to use the generated script.
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -52,6 +52,7 @@ hugo completion bash
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -43,6 +43,7 @@ hugo completion fish [flags]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -40,6 +40,7 @@ hugo completion powershell [flags]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -54,6 +54,7 @@ hugo completion zsh [flags]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -24,6 +24,7 @@ hugo config [command] [flags]
|
||||
--format string preferred file format (toml, yaml or json) (default "toml")
|
||||
-h, --help help for config
|
||||
--lang string the language to display config for. Defaults to the first language defined.
|
||||
--printZero include config options with zero values (e.g. false, 0, "") in the output
|
||||
--renderSegments strings named segments to render (configured in the segments config)
|
||||
-t, --theme strings themes to use (located in /themes/THEMENAME/)
|
||||
```
|
||||
@@ -38,6 +39,7 @@ hugo config [command] [flags]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -32,6 +32,7 @@ hugo config mounts [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -31,6 +31,7 @@ See convert's subcommands toJSON, toTOML and toYAML for more information.
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -32,6 +32,7 @@ hugo convert toJSON [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
-o, --output string filesystem path to write files to
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
|
||||
@@ -32,6 +32,7 @@ hugo convert toTOML [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
-o, --output string filesystem path to write files to
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
|
||||
@@ -32,6 +32,7 @@ hugo convert toYAML [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
-o, --output string filesystem path to write files to
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
|
||||
@@ -42,6 +42,7 @@ hugo deploy [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -31,6 +31,7 @@ hugo env [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -27,6 +27,7 @@ Generate documentation for your project using Hugo's documentation engine, inclu
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -37,6 +37,7 @@ hugo gen chromastyles [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -37,6 +37,7 @@ hugo gen doc [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -34,6 +34,7 @@ hugo gen man [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -29,6 +29,7 @@ Import requires a subcommand, e.g. `hugo import jekyll jekyll_root_path target_p
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -34,6 +34,7 @@ hugo import jekyll [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -29,6 +29,7 @@ List requires a subcommand, e.g. hugo list drafts
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -31,6 +31,7 @@ hugo list all [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -31,6 +31,7 @@ hugo list drafts [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -31,6 +31,7 @@ hugo list expired [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -31,6 +31,7 @@ hugo list future [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -31,6 +31,7 @@ hugo list published [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -38,6 +38,7 @@ See https://gohugo.io/hugo-modules/ for more information.
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -38,6 +38,7 @@ hugo mod clean [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -62,6 +62,7 @@ hugo mod get [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -39,6 +39,7 @@ hugo mod graph [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -43,6 +43,7 @@ hugo mod init [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -31,6 +31,7 @@ hugo mod npm [command] [flags]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -46,6 +46,7 @@ hugo mod npm pack [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -32,6 +32,7 @@ hugo mod tidy [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -38,6 +38,7 @@ hugo mod vendor [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -37,6 +37,7 @@ hugo mod verify [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -34,6 +34,7 @@ Ensure you run this within the root directory of your site.
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -46,6 +46,7 @@ hugo new content [path] [flags]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -35,6 +35,7 @@ hugo new site [path] [flags]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -34,6 +34,7 @@ hugo new theme [name] [flags]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -50,7 +50,6 @@ hugo server [command] [flags]
|
||||
--liveReloadPort int port for live reloading (i.e. 443 in HTTPS proxy situations) (default -1)
|
||||
--minify minify any supported output format (HTML, XML etc.)
|
||||
-N, --navigateToChanged navigate to changed content file on live browser reload
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--noChmod don't sync permission mode of files
|
||||
--noHTTPCache prevent HTTP caching
|
||||
--noTimes don't sync modification time of files
|
||||
@@ -85,6 +84,7 @@ hugo server [command] [flags]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -28,6 +28,7 @@ hugo server trust [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -31,6 +31,7 @@ hugo version [flags] [args]
|
||||
-e, --environment string build environment
|
||||
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
|
||||
--logLevel string log level (debug|info|warn|error)
|
||||
--noBuildLock don't create .hugo_build.lock file
|
||||
--quiet build in quiet mode
|
||||
-M, --renderToMemory render to memory (mostly useful when running the server)
|
||||
-s, --source string filesystem path to read files relative from
|
||||
|
||||
@@ -21,12 +21,12 @@ To list up to 5 related pages (which share the same _date_ or _keyword_ paramete
|
||||
{{< code file=layouts/partials/related.html >}}
|
||||
{{ $related := .Site.RegularPages.Related . | first 5 }}
|
||||
{{ with $related }}
|
||||
<h3>See Also</h3>
|
||||
<ul>
|
||||
{{ range . }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
<h3>See Also</h3>
|
||||
<ul>
|
||||
{{ range . }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ Hugo renders this to:
|
||||
</details>
|
||||
```
|
||||
|
||||
The details shortcode accepts these named arguments:
|
||||
The `details` shortcode accepts these named arguments:
|
||||
|
||||
summary
|
||||
: (`string`) The content of the child `summary` element rendered from Markdown to HTML. Default is `Details`.
|
||||
@@ -333,6 +333,106 @@ Access nested values by [chaining] the [identifiers]:
|
||||
{{</* param my.nested.param */>}}
|
||||
```
|
||||
|
||||
### qr
|
||||
|
||||
{{% note %}}
|
||||
To override Hugo's embedded `qr` shortcode, copy the [source code] to a file with the same name in the layouts/shortcodes directory.
|
||||
|
||||
[source code]: {{% eturl qr %}}
|
||||
{{% /note %}}
|
||||
|
||||
The `qr` shortcode encodes the given text into a [QR code] using the specified options and renders the resulting image.
|
||||
|
||||
[QR code]: https://en.wikipedia.org/wiki/QR_code
|
||||
|
||||
Use the self-closing syntax to pass the text as an argument:
|
||||
|
||||
```text
|
||||
{{</* qr text="https://gohugo.io" /*/>}}
|
||||
```
|
||||
|
||||
Or insert the text between the opening and closing tags:
|
||||
|
||||
```text
|
||||
{{</* qr */>}}
|
||||
https://gohugo.io
|
||||
{{</* /qr */>}}
|
||||
```
|
||||
|
||||
Both of the above produce this image:
|
||||
|
||||
{{< qr text="https://gohugo.io" class="qrcode" />}}
|
||||
|
||||
To create a QR code for a phone number:
|
||||
|
||||
```text
|
||||
{{</* qr text="tel:+12065550101" /*/>}}
|
||||
```
|
||||
|
||||
{{< qr text="tel:+12065550101" class="qrcode" />}}
|
||||
|
||||
To create a QR code containing contact information in the [vCard] format:
|
||||
|
||||
[vCard]: https://en.wikipedia.org/wiki/VCard
|
||||
|
||||
```text
|
||||
{{</* qr level="low" scale=2 alt="QR code of vCard for John Smith" */>}}
|
||||
BEGIN:VCARD
|
||||
VERSION:2.1
|
||||
N;CHARSET=UTF-8:Smith;John;R.;Dr.;PhD
|
||||
FN;CHARSET=UTF-8:Dr. John R. Smith, PhD.
|
||||
ORG;CHARSET=UTF-8:ABC Widgets
|
||||
TITLE;CHARSET=UTF-8:Vice President Engineering
|
||||
TEL;TYPE=WORK:+12065550101
|
||||
EMAIL;TYPE=WORK:jsmith@example.org
|
||||
END:VCARD
|
||||
{{</* /qr */>}}
|
||||
```
|
||||
|
||||
{{< qr level="low" scale=2 alt="QR code of vCard for John Smith" class="qrcode" >}}
|
||||
BEGIN:VCARD
|
||||
VERSION:2.1
|
||||
N;CHARSET=UTF-8:Smith;John;R.;Dr.;PhD
|
||||
FN;CHARSET=UTF-8:Dr. John R. Smith, PhD.
|
||||
ORG;CHARSET=UTF-8:ABC Widgets
|
||||
TITLE;CHARSET=UTF-8:Vice President Engineering
|
||||
TEL;TYPE=WORK:+12065550101
|
||||
EMAIL;TYPE=WORK:jsmith@example.org
|
||||
END:VCARD
|
||||
{{< /qr >}}
|
||||
|
||||
Internally this shortcode calls the `images.QR` function. Please read the [related documentation] for implementation details and guidance.
|
||||
|
||||
[related documentation]: /functions/images/qr/
|
||||
|
||||
The `qr` shortcode accepts these named arguments:
|
||||
|
||||
text
|
||||
: (`string`) The text to encode, falling back to the text between the opening and closing shortcode tags.
|
||||
|
||||
level
|
||||
: (`string`) The error correction level to use when encoding the text, one of `low`, `medium`, `quartile`, or `high`. Default is `medium`.
|
||||
|
||||
scale
|
||||
: (`int`) The number of image pixels per QR code module. Must be greater than or equal to 2. Default is `4`.
|
||||
|
||||
targetDir
|
||||
: (`string`) The subdirectory within the [`publishDir`] where Hugo will place the generated image.
|
||||
|
||||
[`publishDir`]: /getting-started/configuration/#publishdir
|
||||
|
||||
alt
|
||||
: (`string`) The `alt` attribute of the `img` element.
|
||||
|
||||
class
|
||||
: (`string`) The `class` attribute of the `img` element.
|
||||
|
||||
id
|
||||
: (`string`) The `id` attribute of the `img` element.
|
||||
|
||||
title
|
||||
: (`string`) The `title` attribute of the `img` element.
|
||||
|
||||
### ref
|
||||
|
||||
{{% note %}}
|
||||
|
||||
@@ -7,7 +7,7 @@ action:
|
||||
aliases: [dict]
|
||||
related:
|
||||
- functions/collections/Slice
|
||||
returnType: mapany
|
||||
returnType: map[string]any
|
||||
signatures: ['collections.Dictionary [VALUE...]']
|
||||
aliases: [/functions/dict]
|
||||
---
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: collections.Querify
|
||||
description: Returns a URL query string composed of the given key-value pairs.
|
||||
description: Returns a URL query string composed of the given key-value pairs, encoded and sorted by key.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
@@ -13,18 +13,18 @@ action:
|
||||
aliases: [/functions/querify]
|
||||
---
|
||||
|
||||
Specify the key-value pairs as individual arguments, or as a slice. The following are equivalent:
|
||||
|
||||
Specify the key-value pairs as a map, a slice, or a sequence of scalar values. For example, the following are equivalent:
|
||||
|
||||
```go-html-template
|
||||
{{ collections.Querify "a" 1 "b" 2 }}
|
||||
{{ collections.Querify (dict "a" 1 "b" 2) }}
|
||||
{{ collections.Querify (slice "a" 1 "b" 2) }}
|
||||
{{ collections.Querify "a" 1 "b" 2 }}
|
||||
```
|
||||
|
||||
To append a query string to a URL:
|
||||
|
||||
```go-html-template
|
||||
{{ $qs := collections.Querify "a" 1 "b" 2 }}
|
||||
{{ $qs := collections.Querify (dict "a" 1 "b" 2) }}
|
||||
{{ $href := printf "https://example.org?%s" $qs }}
|
||||
|
||||
<a href="{{ $href }}">Link</a>
|
||||
@@ -35,3 +35,16 @@ Hugo renders this to:
|
||||
```html
|
||||
<a href="https://example.org?a=1&b=2">Link</a>
|
||||
```
|
||||
|
||||
You can also pass in a map from your site configuration or front matter. For example:
|
||||
|
||||
{{< code-toggle file=content/example.md fm=true >}}
|
||||
title = 'Example'
|
||||
[params.query]
|
||||
a = 1
|
||||
b = 2
|
||||
{{< /code-toggle >}}
|
||||
|
||||
```go-html-template
|
||||
{{ collections.Querify .Params.query }}
|
||||
```
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
---
|
||||
title: images.QR
|
||||
description: Encodes the given text into a QR code using the specified options, returning an image resource.
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related: []
|
||||
returnType: images.ImageResource
|
||||
signatures: ['images.QR TEXT OPTIONS']
|
||||
toc: true
|
||||
math: true
|
||||
---
|
||||
|
||||
{{< new-in 0.141.0 >}}
|
||||
|
||||
The `images.QR` function encodes the given text into a [QR code] using the specified options, returning an image resource. The size of the generated image depends on three factors:
|
||||
|
||||
- Data length: Longer text necessitates a larger image to accommodate the increased information density.
|
||||
- Error correction level: Higher error correction levels enhance the QR code's resistance to damage, but this typically results in a slightly larger image size to maintain readability.
|
||||
- Pixels per module: The number of image pixels assigned to each individual module (the smallest unit of the QR code) directly impacts the overall image size. A higher pixel count per module leads to a larger, higher-resolution image.
|
||||
|
||||
Although the default option values are sufficient for most applications, you should test the rendered QR code both on-screen and in print.
|
||||
|
||||
[QR code]: https://en.wikipedia.org/wiki/QR_code
|
||||
|
||||
## Options
|
||||
|
||||
level
|
||||
: (`string`) The error correction level to use when encoding the text, one of `low`, `medium`, `quartile`, or `high`. Default is `medium`.
|
||||
|
||||
Error correction level|Redundancy
|
||||
:--|:--|:--
|
||||
low|20%
|
||||
medium|38%
|
||||
quartile|55%
|
||||
high|65%
|
||||
|
||||
scale
|
||||
: (`int`) The number of image pixels per QR code module. Must be greater than or equal to `2`. Default is `4`.
|
||||
|
||||
targetDir
|
||||
: (`string`) The subdirectory within the [`publishDir`] where Hugo will place the generated image. Use Unix-style slashes (`/`) to separarate path segments. If empty or not provided, the image is placed directly in the `publishDir` root. Hugo automatically creates the necessary subdirectories if they don't exist.
|
||||
|
||||
[`publishDir`]: /getting-started/configuration/#publishdir
|
||||
|
||||
## Examples
|
||||
|
||||
To create a QR code using the default values for `level` and `scale`:
|
||||
|
||||
```go-html-template
|
||||
{{ $text := "https://gohugo.io" }}
|
||||
{{ with images.QR $text }}
|
||||
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{< qr text="https://gohugo.io" class="qrcode" />}}
|
||||
|
||||
Specify `level`, `scale`, and `targetDir` as needed to achieve the desired result:
|
||||
|
||||
```go-html-template
|
||||
{{ $text := "https://gohugo.io" }}
|
||||
{{ $opts := dict
|
||||
"level" "high"
|
||||
"scale" 3
|
||||
"targetDir" "codes"
|
||||
}}
|
||||
{{ with images.QR $text $opts }}
|
||||
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{< qr text="https://gohugo.io" level="high" scale=3 targetDir="codes" class="qrcode" />}}
|
||||
|
||||
## Scale
|
||||
|
||||
As you decrease the size of a QR code, the maximum distance at which it can be reliably scanned by a device also decreases.
|
||||
|
||||
In the example above, we set the `scale` to `2`, resulting in a QR code where each module consists of 2x2 pixels. While this might be sufficient for on-screen display, it's likely to be problematic when printed at 600 dpi.
|
||||
|
||||
\[ \frac{2\:px}{module} \times \frac{1\:inch}{600\:px} \times \frac{25.4\:mm}{1\:inch} = \frac{0.085\:mm}{module} \]
|
||||
|
||||
This module size is half of the commonly recommended minimum of 0.170 mm.\
|
||||
If the QR code will be printed, use the default `scale` value of `4` pixels per module.
|
||||
|
||||
Avoid using Hugo's image processing methods to resize QR codes. Resizing can introduce blurring due to anti-aliasing when a QR code module occupies a fractional number of pixels.
|
||||
|
||||
{{% note %}}
|
||||
Always test the rendered QR code both on-screen and in print.
|
||||
{{% /note %}}
|
||||
|
||||
## Shortcode
|
||||
|
||||
Call the `qr` shortcode to insert a QR code into your content.
|
||||
|
||||
Use the self-closing syntax to pass the text as an argument:
|
||||
|
||||
```text
|
||||
{{</* qr text="https://gohugo.io" /*/>}}
|
||||
```
|
||||
|
||||
Or insert the text between the opening and closing tags:
|
||||
|
||||
```text
|
||||
{{</* qr */>}}
|
||||
https://gohugo.io
|
||||
{{</* /qr */>}}
|
||||
```
|
||||
|
||||
The `qr` shortcode accepts several arguments including `level` and `scale`. See the [related documentation] for details.
|
||||
|
||||
[related documentation]: /content-management/shortcodes/#qr
|
||||
@@ -37,6 +37,10 @@ x
|
||||
y
|
||||
: (`int`) The vertical offset, in pixels, relative to the top of the image. Default is `10`.
|
||||
|
||||
alignx
|
||||
{{< new-in 0.141.0 >}}
|
||||
: (`string`) The horizontal alignment of the text relative to the `x` position. One of `left`, `center`, or `right`. Default is `left`.
|
||||
|
||||
[global resource]: /getting-started/glossary/#global-resource
|
||||
[page resource]: /getting-started/glossary/#page-resource
|
||||
[remote resource]: /getting-started/glossary/#remote-resource
|
||||
|
||||
@@ -3,8 +3,9 @@ title: js.Babel
|
||||
description: Compiles the given JavaScript resource with Babel.
|
||||
categories: []
|
||||
keywords: []
|
||||
weight: 100
|
||||
action:
|
||||
aliases: [babel]
|
||||
aliases: [babel,/hugo-pipes/babel/]
|
||||
related:
|
||||
- functions/js/Build
|
||||
- functions/resources/Fingerprint
|
||||
|
||||
@@ -0,0 +1,331 @@
|
||||
---
|
||||
title: js.Batch
|
||||
description: Build JavaScript bundle groups with global code splitting and flexible hooks/runners setup.
|
||||
weight: 50
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/js/Build
|
||||
- functions/js/Babel
|
||||
- functions/resources/Fingerprint
|
||||
- functions/resources/Minify
|
||||
returnType: js.Batcher
|
||||
signatures: ['js.Batch [ID]']
|
||||
toc: true
|
||||
---
|
||||
|
||||
{{% note %}}
|
||||
For a runnable example of this feature, see [this test and demo repo](https://github.com/bep/hugojsbatchdemo/).
|
||||
{{% /note %}}
|
||||
|
||||
The Batch `ID` is used to create the base directory for this batch. Forward slashes are allowed. `js.Batch` returns an object with an API with this structure:
|
||||
|
||||
* [Group]
|
||||
* [Script]
|
||||
* [SetOptions]
|
||||
* [Instance]
|
||||
* [SetOptions]
|
||||
* [Runner]
|
||||
* [SetOptions]
|
||||
* [Config]
|
||||
* [SetOptions]
|
||||
|
||||
|
||||
## Group
|
||||
|
||||
The `Group` method take an `ID` (`string`) as argument. No slashes. It returns an object with these methods:
|
||||
|
||||
|
||||
#### Script
|
||||
|
||||
The `Script` method takes an `ID` (`string`) as argument. No slashes. It returns an [OptionsSetter] that can be used to set [script options] for this script.
|
||||
|
||||
```go-html-template
|
||||
{{ with js.Batch "js/mybatch" }}
|
||||
{{ with .Group "mygroup" }}
|
||||
{{ with .Script "myscript" }}
|
||||
{{ .SetOptions (dict "resource" (resources.Get "myscript.js")) }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
`SetOptions` takes a [script options] map. Note that if you want the script to be handled by a [runner], you need to set the `export` option to match what you want to pass on to the runner (default is `*`).
|
||||
|
||||
#### Instance
|
||||
|
||||
The `Instance` method takes two `string` arguments `SCRIPT_ID` and `INSTANCE_ID`. No slashes. It returns an [OptionsSetter] that can be used to set [params options] for this instance.
|
||||
|
||||
```go-html-template
|
||||
{{ with js.Batch "js/mybatch" }}
|
||||
{{ with .Group "mygroup" }}
|
||||
{{ with .Instance "myscript" "myinstance" }}
|
||||
{{ .SetOptions (dict "params" (dict "param1" "value1")) }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
`SetOptions` takes a [params options] map. The instance options will be passed to any [runner] script in the same group, as JSON.
|
||||
|
||||
|
||||
#### Runner
|
||||
|
||||
The `Runner` method takes an `ID` (`string`) as argument. No slashes. It returns an [OptionsSetter] that can be used to set [script options] for this runner.
|
||||
|
||||
```go-html-template
|
||||
{{ with js.Batch "js/mybatch" }}
|
||||
{{ with .Group "mygroup" }}
|
||||
{{ with .Runner "myrunner" }}
|
||||
{{ .SetOptions (dict "resource" (resources.Get "myrunner.js")) }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
`SetOptions` takes a [script options] map.
|
||||
|
||||
The runner will receive a data structure with all instances for that group with a live binding of the [JavaScript import] of the defined `export`.
|
||||
|
||||
The runner script's export must be a function that takes one argument, the group data structure. An example of a group data structure as JSON is:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "leaflet",
|
||||
"scripts": [
|
||||
{
|
||||
"id": "mapjsx",
|
||||
"binding": JAVASCRIPT_BINDING,
|
||||
"instances": [
|
||||
{
|
||||
"id": "0",
|
||||
"params": {
|
||||
"c": "h-64",
|
||||
"lat": 48.8533173846729,
|
||||
"lon": 2.3497416090232535,
|
||||
"r": "map.jsx",
|
||||
"title": "Cathédrale Notre-Dame de Paris",
|
||||
"zoom": 23
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "1",
|
||||
"params": {
|
||||
"c": "h-64",
|
||||
"lat": 59.96300872062237,
|
||||
"lon": 10.663529183196863,
|
||||
"r": "map.jsx",
|
||||
"title": "Holmenkollen",
|
||||
"zoom": 3
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Below is an example of a runner script that uses React to render elements. Note that the export (`default`) must match the `export` option in the [script options] (`default` is the default value for runner scripts) (runnable versions of examples on this page can be found at [js.Batch Demo Repo]):
|
||||
|
||||
|
||||
```js
|
||||
import * as ReactDOM from 'react-dom/client';
|
||||
import * as React from 'react';
|
||||
|
||||
export default function Run(group) {
|
||||
console.log('Running react-create-elements.js', group);
|
||||
const scripts = group.scripts;
|
||||
for (const script of scripts) {
|
||||
for (const instance of script.instances) {
|
||||
/* This is a convention in this project. */
|
||||
let elId = `${script.id}-${instance.id}`;
|
||||
let el = document.getElementById(elId);
|
||||
if (!el) {
|
||||
console.warn(`Element with id ${elId} not found`);
|
||||
continue;
|
||||
}
|
||||
const root = ReactDOM.createRoot(el);
|
||||
const reactEl = React.createElement(script.binding, instance.params);
|
||||
root.render(reactEl);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Config
|
||||
|
||||
Returns an [OptionsSetter] that can be used to set [build options] for the batch.
|
||||
|
||||
These are mostly the same as for [js.Build], but note that:
|
||||
|
||||
* `targetPath` is set automatically (there may be multiple outputs).
|
||||
* `format` must be `esm`, currently the only format supporting [code splitting].
|
||||
* `params` will be available in the `@params/config` namespace in the scripts. This way you can import both the [script] or [runner] params and the [config] params with:
|
||||
|
||||
```js
|
||||
import * as params from "@params";
|
||||
import * as config from "@params/config";
|
||||
```
|
||||
|
||||
Setting the `Config` for a batch can be done from any template (including shortcode templates), but will only be set once (the first will win):
|
||||
|
||||
```go-html-template
|
||||
{{ with js.Batch "js/mybatch" }}
|
||||
{{ with .Config }}
|
||||
{{ .SetOptions (dict
|
||||
"target" "es2023"
|
||||
"format" "esm"
|
||||
"jsx" "automatic"
|
||||
"loaders" (dict ".png" "dataurl")
|
||||
"minify" true
|
||||
"params" (dict "param1" "value1")
|
||||
)
|
||||
}}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
### Build Options
|
||||
|
||||
format
|
||||
: (`string`) Currently only `esm` is supported in [ESBuild's code splitting].
|
||||
|
||||
{{% include "./_common/options.md" %}}
|
||||
|
||||
### Script Options
|
||||
|
||||
resource
|
||||
: The resource to build. This can be a file resource or a virtual resource.
|
||||
|
||||
export
|
||||
: The export to bind the runner to. Set it to `*` to export the [entire namespace](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#namespace_import). Default is `default` for [runner] scripts and `*` for other [scripts](#script).
|
||||
|
||||
importContext
|
||||
: An additional context for resolving imports. Hugo will always check this one first before falling back to `assets` and `node_modules`. A common use of this is to resolve imports inside a page bundle. See [import context](#import-context).
|
||||
|
||||
params
|
||||
: A map of parameters that will be passed to the script as JSON. These gets bound to the `@params` namespace:
|
||||
```js
|
||||
import * as params from '@params';
|
||||
```
|
||||
|
||||
### Script Options
|
||||
|
||||
### Params Options
|
||||
|
||||
params
|
||||
: A map of parameters that will be passed to the script as JSON.
|
||||
|
||||
### Import Context
|
||||
|
||||
Hugo will, by default, first try to resolve any import in [assets](/hugo-pipes/introduction/#asset-directory) and, if not found, let [ESBuild] resolve it (e.g. from `node_modules`). The `importContext` option can be used to set the first context for resolving imports. A common use of this is to resolve imports inside a [page bundle](/content-management/page-bundles/).
|
||||
|
||||
```go-html-template
|
||||
{{ $common := resources.Match "/js/headlessui/*.*" }}
|
||||
{{ $importContext := (slice $.Page ($common.Mount "/js/headlessui" ".")) }}
|
||||
```
|
||||
|
||||
You can pass any object that implements [Resource.Get](/methods/page/resources/#get). Pass a slice to set multiple contexts.
|
||||
|
||||
The example above uses [`Resources.Mount`] to resolve a folder inside `assets` relative to the page bundle.
|
||||
|
||||
### OptionsSetter
|
||||
|
||||
An `OptionsSetter` is a special object that is returned once only. This means that you should wrap it with [with]:
|
||||
|
||||
```go-html-template
|
||||
{{ with .Script "myscript" }}
|
||||
{{ .SetOptions (dict "resource" (resources.Get "myscript.js"))}}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
The `Build` method returns an object with the following structure:
|
||||
|
||||
* Groups (map)
|
||||
* [`Resources`]
|
||||
|
||||
Eeach [`Resource`] will be of media type `application/javascript` or `text/css`.
|
||||
|
||||
In a template you would typically handle one group with a given `ID` (e.g. scripts for the current section). Because of the concurrent build, this needs to be done in a [`templates.Defer`] block:
|
||||
|
||||
{{% note %}}
|
||||
The [`templates.Defer`] acts as a synchronisation point to handle scripts added concurrently by different templates. If you have a setup with where the batch is created in one go (in one template), you don't need it.
|
||||
|
||||
See [this discussion](https://discourse.gohugo.io/t/js-batch-with-simple-global-script/53002/5?u=bep) for more.
|
||||
|
||||
[`templates.Defer`]: /functions/templates/defer/
|
||||
{{% /note %}}
|
||||
|
||||
```go-html-template
|
||||
{{ $group := .group }}
|
||||
{{ with (templates.Defer (dict "key" $group "data" $group )) }}
|
||||
{{ with (js.Batch "js/mybatch") }}
|
||||
{{ with .Build }}
|
||||
{{ with index .Groups $ }}
|
||||
{{ range . }}
|
||||
{{ $s := . }}
|
||||
{{ if eq $s.MediaType.SubType "css" }}
|
||||
<link href="{{ $s.RelPermalink }}" rel="stylesheet" />
|
||||
{{ else }}
|
||||
<script src="{{ $s.RelPermalink }}" type="module"></script>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
|
||||
## Known Issues
|
||||
|
||||
In the official documentation for [ESBuild's code splitting], there's a warning note in the header. The two issues are:
|
||||
|
||||
* `esm` is currently the only implemented output format. This means that it will not work for very old browsers. See [caniuse](https://caniuse.com/?search=ESM).
|
||||
* There's a known import ordering issue.
|
||||
|
||||
We have not seen the ordering issue as a problem during our [extensive testing](https://github.com/bep/hugojsbatchdemo) of this new feature with different libraries. There are two main cases:
|
||||
|
||||
1. Undefined execution order of imports, see [this comment](https://github.com/evanw/esbuild/issues/399#issuecomment-1458680887)
|
||||
2. Only one execution order of imports, see [this comment](https://github.com/evanw/esbuild/issues/399#issuecomment-735355932)
|
||||
|
||||
Many would say that both of the above are [code smells](https://en.wikipedia.org/wiki/Code_smell). The first one has a simple workaround in Hugo. Define the import order in its own script and make sure it gets passed early to ESBuild, e.g. by putting it in a script group with a name that comes early in the alphabet.
|
||||
|
||||
```js
|
||||
import './lib2.js';
|
||||
import './lib1.js';
|
||||
|
||||
console.log('entrypoints-workaround.js');
|
||||
|
||||
```
|
||||
|
||||
[build options]: #build-options
|
||||
[`Resource`]: https://gohugo.io/methods/resource/
|
||||
[`Resources`]: /methods/page/resources/
|
||||
[`Resources.Mount`]: /methods/page/resources/#mount
|
||||
[`templates.Defer`]: /functions/templates/defer/
|
||||
[code splitting]: https://esbuild.github.io/api/#splitting
|
||||
[config]: #config
|
||||
[ESBuild's code splitting]: https://esbuild.github.io/api/#splitting
|
||||
[ESBuild]: https://github.com/evanw/esbuild
|
||||
[group]: #group
|
||||
[instance]: #instance
|
||||
[JavaScript import]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
|
||||
[js.Batch Demo Repo]: https://github.com/bep/hugojsbatchdemo/
|
||||
[js.Build]: https://gohugo.io/hugo-pipes/js/#options
|
||||
[map]: https://gohugo.io/functions/collections/dictionary/
|
||||
[OptionsSetter]: #optionssetter
|
||||
[page bundles]: https://gohugo.io/content-management/page-bundles/
|
||||
[params options]: #params-options
|
||||
[runner]: #runner
|
||||
[script options]: #script-options
|
||||
[script]: #script
|
||||
[SetOptions]: #optionssetter
|
||||
[with]: https://gohugo.io/functions/go-template/with/
|
||||
@@ -1,6 +1,7 @@
|
||||
---
|
||||
title: js.Build
|
||||
description: Bundles, transpiles, tree shakes, and minifies JavaScript resources.
|
||||
weight: 30
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
@@ -45,94 +46,10 @@ targetPath
|
||||
: (`string`) If not set, the source path will be used as the base target path.
|
||||
Note that the target path's extension may change if the target MIME type is different, e.g. when the source is TypeScript.
|
||||
|
||||
params
|
||||
: (`map` or `slice`) Params that can be imported as JSON in your JS files, e.g.
|
||||
|
||||
```go-html-template
|
||||
{{ $js := resources.Get "js/main.js" | js.Build (dict "params" (dict "api" "https://example.org/api")) }}
|
||||
```
|
||||
And then in your JS file:
|
||||
|
||||
```js
|
||||
import * as params from '@params';
|
||||
```
|
||||
|
||||
Note that this is meant for small data sets, e.g. configuration settings. For larger data, please put/mount the files into `/assets` and import them directly.
|
||||
|
||||
minify
|
||||
: (`bool`)Let `js.Build` handle the minification.
|
||||
|
||||
inject
|
||||
: (`slice`) This option allows you to automatically replace a global variable with an import from another file. The path names must be relative to `assets`. See https://esbuild.github.io/api/#inject
|
||||
|
||||
shims
|
||||
: (`map`) This option allows swapping out a component with another. A common use case is to load dependencies like React from a CDN (with _shims_) when in production, but running with the full bundled `node_modules` dependency during development:
|
||||
|
||||
```go-html-template
|
||||
{{ $shims := dict "react" "js/shims/react.js" "react-dom" "js/shims/react-dom.js" }}
|
||||
{{ $js = $js | js.Build dict "shims" $shims }}
|
||||
```
|
||||
|
||||
The _shim_ files may look like these:
|
||||
|
||||
```js
|
||||
// js/shims/react.js
|
||||
module.exports = window.React;
|
||||
```
|
||||
|
||||
```js
|
||||
// js/shims/react-dom.js
|
||||
module.exports = window.ReactDOM;
|
||||
```
|
||||
|
||||
With the above, these imports should work in both scenarios:
|
||||
|
||||
```js
|
||||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom/client';
|
||||
```
|
||||
|
||||
target
|
||||
: (`string`) The language target. One of: `es5`, `es2015`, `es2016`, `es2017`, `es2018`, `es2019`, `es2020` or `esnext`. Default is `esnext`.
|
||||
|
||||
externals
|
||||
: (`slice`) External dependencies. Use this to trim dependencies you know will never be executed. See https://esbuild.github.io/api/#external
|
||||
|
||||
defines
|
||||
: (`map`) Allow to define a set of string replacement to be performed when building. Should be a map where each key is to be replaced by its value.
|
||||
|
||||
```go-html-template
|
||||
{{ $defines := dict "process.env.NODE_ENV" `"development"` }}
|
||||
```
|
||||
|
||||
format
|
||||
: (`string`) The output format. One of: `iife`, `cjs`, `esm`. Default is `iife`, a self-executing function, suitable for inclusion as a `<script>` tag.
|
||||
|
||||
sourceMap
|
||||
: (`string`) Whether to generate `inline` or `external` source maps from esbuild. External source maps will be written to the target with the output file name + ".map". Input source maps can be read from js.Build and node modules and combined into the output source maps. By default, source maps are not created.
|
||||
|
||||
JSX {{< new-in 0.124.0 >}}
|
||||
: (`string`) How to handle/transform JSX syntax. One of: `transform`, `preserve`, `automatic`. Default is `transform`. Notably, the `automatic` transform was introduced in React 17+ and will cause the necessary JSX helper functions to be imported automatically. See https://esbuild.github.io/api/#jsx
|
||||
|
||||
JSXImportSource {{< new-in 0.124.0 >}}
|
||||
: (`string`) Which library to use to automatically import its JSX helper functions from. This only works if `JSX` is set to `automatic`. The specified library needs to be installed through npm and expose certain exports. See https://esbuild.github.io/api/#jsx-import-source
|
||||
|
||||
The combination of `JSX` and `JSXImportSource` is helpful if you want to use a non-React JSX library like Preact, e.g.:
|
||||
|
||||
```go-html-template
|
||||
{{ $js := resources.Get "js/main.jsx" | js.Build (dict "JSX" "automatic" "JSXImportSource" "preact") }}
|
||||
```
|
||||
|
||||
With the above, you can use Preact components and JSX without having to manually import `h` and `Fragment` every time:
|
||||
|
||||
```jsx
|
||||
import { render } from 'preact';
|
||||
|
||||
const App = () => <>Hello world!</>;
|
||||
|
||||
const container = document.getElementById('app');
|
||||
if (container) render(<App />, container);
|
||||
```
|
||||
{{% include "./_common/options.md" %}}
|
||||
|
||||
### Import JS code from /assets
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
cascade:
|
||||
_build:
|
||||
list: never
|
||||
publishResources: false
|
||||
render: never
|
||||
---
|
||||
|
||||
<!--
|
||||
Files within this headless branch bundle are Markdown snippets. Each file must contain front matter delimiters, though front matter fields are not required.
|
||||
|
||||
Include the rendered content using the "include" shortcode.
|
||||
-->
|
||||
@@ -0,0 +1,99 @@
|
||||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
params
|
||||
: (`map` or `slice`) Params that can be imported as JSON in your JS files, e.g.
|
||||
|
||||
```go-html-template
|
||||
{{ $js := resources.Get "js/main.js" | js.Build (dict "params" (dict "api" "https://example.org/api")) }}
|
||||
```
|
||||
And then in your JS file:
|
||||
|
||||
```js
|
||||
import * as params from '@params';
|
||||
```
|
||||
|
||||
Note that this is meant for small data sets, e.g. configuration settings. For larger data, please put/mount the files into `/assets` and import them directly.
|
||||
|
||||
minify
|
||||
: (`bool`)Let `js.Build` handle the minification.
|
||||
|
||||
loaders
|
||||
: (`map`) {{< new-in "0.140.0" >}} Configuring a loader for a given file type lets you load that file type with an import statement or a require call. For example configuring the .png file extension to use the data URL loader means importing a .png file gives you a data URLcontaining the contents of that image. Loaders available are `none`, `base64`, `binary`, `copy`, `css`, `dataurl`, `default`, `empty`, `file`, `global-css`, `js`, `json`, `jsx`, `local-css`, `text`, `ts`, `tsx`. See https://esbuild.github.io/api/#loader
|
||||
|
||||
inject
|
||||
: (`slice`) This option allows you to automatically replace a global variable with an import from another file. The path names must be relative to `assets`. See https://esbuild.github.io/api/#inject
|
||||
|
||||
shims
|
||||
: (`map`) This option allows swapping out a component with another. A common use case is to load dependencies like React from a CDN (with _shims_) when in production, but running with the full bundled `node_modules` dependency during development:
|
||||
|
||||
```go-html-template
|
||||
{{ $shims := dict "react" "js/shims/react.js" "react-dom" "js/shims/react-dom.js" }}
|
||||
{{ $js = $js | js.Build dict "shims" $shims }}
|
||||
```
|
||||
|
||||
The _shim_ files may look like these:
|
||||
|
||||
```js
|
||||
// js/shims/react.js
|
||||
module.exports = window.React;
|
||||
```
|
||||
|
||||
```js
|
||||
// js/shims/react-dom.js
|
||||
module.exports = window.ReactDOM;
|
||||
```
|
||||
|
||||
With the above, these imports should work in both scenarios:
|
||||
|
||||
```js
|
||||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom/client';
|
||||
```
|
||||
|
||||
target
|
||||
: (`string`) The language target. One of: `es5`, `es2015`, `es2016`, `es2017`, `es2018`, `es2019`, `es2020` or `esnext`. Default is `esnext`.
|
||||
|
||||
platform {{< new-in 0.140.0 >}}
|
||||
: (`string`) One of `browser`, `node`, `neutral`. Default is `browser`. See https://esbuild.github.io/api/#platform
|
||||
|
||||
externals
|
||||
: (`slice`) External dependencies. Use this to trim dependencies you know will never be executed. See https://esbuild.github.io/api/#external
|
||||
|
||||
defines
|
||||
: (`map`) Allow to define a set of string replacement to be performed when building. Should be a map where each key is to be replaced by its value.
|
||||
|
||||
```go-html-template
|
||||
{{ $defines := dict "process.env.NODE_ENV" `"development"` }}
|
||||
```
|
||||
|
||||
sourceMap
|
||||
: (`string`) Whether to generate `inline`, `linked` or `external` source maps from esbuild. Linked and external source maps will be written to the target with the output file name + ".map". When `linked` a `sourceMappingURL` will also be written to the output file. By default, source maps are not created. Note that the `linked` option was added in Hugo 0.140.0.
|
||||
|
||||
sourcesContent {{< new-in 0.140.0 >}}
|
||||
: (`bool`) Whether to include the content of the source files in the source map. By default, this is `true`.
|
||||
|
||||
|
||||
JSX {{< new-in 0.124.0 >}}
|
||||
: (`string`) How to handle/transform JSX syntax. One of: `transform`, `preserve`, `automatic`. Default is `transform`. Notably, the `automatic` transform was introduced in React 17+ and will cause the necessary JSX helper functions to be imported automatically. See https://esbuild.github.io/api/#jsx
|
||||
|
||||
JSXImportSource {{< new-in 0.124.0 >}}
|
||||
: (`string`) Which library to use to automatically import its JSX helper functions from. This only works if `JSX` is set to `automatic`. The specified library needs to be installed through npm and expose certain exports. See https://esbuild.github.io/api/#jsx-import-source
|
||||
|
||||
The combination of `JSX` and `JSXImportSource` is helpful if you want to use a non-React JSX library like Preact, e.g.:
|
||||
|
||||
```go-html-template
|
||||
{{ $js := resources.Get "js/main.jsx" | js.Build (dict "JSX" "automatic" "JSXImportSource" "preact") }}
|
||||
```
|
||||
|
||||
With the above, you can use Preact components and JSX without having to manually import `h` and `Fragment` every time:
|
||||
|
||||
```jsx
|
||||
import { render } from 'preact';
|
||||
|
||||
const App = () => <>Hello world!</>;
|
||||
|
||||
const container = document.getElementById('app');
|
||||
if (container) render(<App />, container);
|
||||
```
|
||||
@@ -25,53 +25,55 @@ LANG
|
||||
: The language of the code to highlight. Choose from one of the [supported languages]. Case-insensitive.
|
||||
|
||||
OPTIONS
|
||||
: A map, or comma-separated list, of zero or more [options]. Set default values in [site configuration].
|
||||
: A map or comma-separated list of zero or more options. Set default values in [site configuration].
|
||||
|
||||
## Options
|
||||
|
||||
lineNos
|
||||
: Boolean. Default is `false`.\
|
||||
Display a number at the beginning of each line.
|
||||
|
||||
lineNumbersInTable
|
||||
: Boolean. Default is `true`.\
|
||||
Render the highlighted code in an HTML table with two cells. The left table cell contains the line numbers. The right table cell contains the code, allowing a user to select and copy the code without line numbers. Irrelevant if `lineNos` is `false`.
|
||||
|
||||
anchorLineNos
|
||||
: Boolean. Default is `false`.\
|
||||
Render each line number as an HTML anchor element, and set the `id` attribute of the surrounding `<span>` to the line number. Irrelevant if `lineNos` is `false`.
|
||||
: (`bool`) Whether to render each line number as an HTML anchor element, setting the `id` attribute of the surrounding `span` element to the line number. Irrelevant if `lineNos` is `false`. Default is `false`.
|
||||
|
||||
lineAnchors
|
||||
: String. Default is `""`.\
|
||||
When rendering a line number as an HTML anchor element, prepend this value to the `id` attribute of the surrounding `<span>`. This provides unique `id` attributes when a page contains two or more code blocks. Irrelevant if `lineNos` or `anchorLineNos` is `false`.
|
||||
|
||||
lineNoStart
|
||||
: Integer. Default is `1`.\
|
||||
The number to display at the beginning of the first line. Irrelevant if `lineNos` is `false`.
|
||||
|
||||
hl_Lines
|
||||
: String. Default is `""`.\
|
||||
A space-delimited list of lines to emphasize within the highlighted code. To emphasize lines 2, 3, 4, and 7, set this value to `2-4 7`. This option is independent of the `lineNoStart` option.
|
||||
|
||||
hl_inline
|
||||
: Boolean. Default is `false`.\
|
||||
Render the highlighted code without a wrapping container.
|
||||
|
||||
style
|
||||
: String. Default is `monokai`.\
|
||||
The CSS styles to apply to the highlighted code. See the [style gallery] for examples. Case-sensitive.
|
||||
|
||||
noClasses
|
||||
: Boolean. Default is `true`.\
|
||||
Use inline CSS styles instead of an external CSS file. To use an external CSS file, set this value to `false` and [generate the file with the hugo client][hugo client].
|
||||
|
||||
tabWidth
|
||||
: Integer. Default is `4`.\
|
||||
Substitute this number of spaces for each tab character in your highlighted code. Irrelevant if `noClasses` is `false`.
|
||||
codeFences
|
||||
: (`bool`) Whether to highlight fenced code blocks. Default is `true`.
|
||||
|
||||
guessSyntax
|
||||
: Boolean. Default is `false`.\
|
||||
If the `LANG` argument is blank or an unrecognized language, auto-detect the language if possible, otherwise use a fallback language.
|
||||
: (`bool`) Whether to automatically detect the language if the `LANG` argument is blank or set to a language for which there is no corresponding [lexer]. Falls back to a plain text lexer if unable to automatically detect the language. Default is `false`.
|
||||
|
||||
[lexer]: /getting-started/glossary/#lexer
|
||||
|
||||
{{% note %}}
|
||||
The Chroma syntax highlighter includes lexers for approximately 250 languages, but only 5 of these have implemented automatic language detection.
|
||||
{{% /note %}}
|
||||
|
||||
hl_Lines
|
||||
: (`string`) A space-delimited list of lines to emphasize within the highlighted code. To emphasize lines 2, 3, 4, and 7, set this value to `2-4 7`. This option is independent of the `lineNoStart` option.
|
||||
|
||||
hl_inline
|
||||
: (`bool`) Whether to render the highlighted code without a wrapping container.Default is `false`.
|
||||
|
||||
lineAnchors
|
||||
: (`string`) When rendering a line number as an HTML anchor element, prepend this value to the `id` attribute of the surrounding `span` element. This provides unique `id` attributes when a page contains two or more code blocks. Irrelevant if `lineNos` or `anchorLineNos` is `false`.
|
||||
|
||||
lineNoStart
|
||||
: (`int`) The number to display at the beginning of the first line. Irrelevant if `lineNos` is `false`. Default is `1`.
|
||||
|
||||
lineNos
|
||||
: (`bool`) Whether to display a number at the beginning of each line. Default is `false`.
|
||||
|
||||
lineNumbersInTable
|
||||
: (`bool`) Whether to render the highlighted code in an HTML table with two cells. The left table cell contains the line numbers, while the right table cell contains the code. Irrelevant if `lineNos` is `false`. Default is `true`.
|
||||
|
||||
noClasses
|
||||
: (`bool`) Whether to use inline CSS styles instead of an external CSS file. To use an external CSS file, set this value to `false` and generate the CSS file using the `hugo gen chromastyles` command. Default is `true`.
|
||||
|
||||
style
|
||||
: (`string`) The CSS styles to apply to the highlighted code. See the [style gallery] for examples. Case-sensitive. Default is `monokai`.
|
||||
|
||||
tabWidth
|
||||
: (`int`) Substitute this number of spaces for each tab character in your highlighted code. Irrelevant if `noClasses` is `false`. Default is `4`.
|
||||
|
||||
wrapperClass
|
||||
{{< new-in 0.140.2 >}}
|
||||
: (`string`) The class or classes to use for the outermost element of the highlighted code. Default is `highlight`.
|
||||
|
||||
{{% note %}}
|
||||
Instead of specifying both `lineNos` and `lineNumbersInTable`, you can use the following shorthand notation:
|
||||
@@ -100,8 +102,6 @@ lineNos=table
|
||||
```
|
||||
|
||||
[Chroma]: https://github.com/alecthomas/chroma
|
||||
[hugo client]: /commands/hugo_gen_chromastyles
|
||||
[options]: #options
|
||||
[site configuration]: /getting-started/configuration-markup#highlight
|
||||
[style gallery]: https://xyproto.github.io/splash/docs/
|
||||
[supported languages]: /content-management/syntax-highlighting#list-of-chroma-highlighting-languages
|
||||
|
||||
@@ -278,6 +278,12 @@ To remain consistent and prevent unexpected behavior, do not mix these strategie
|
||||
|
||||
(`bool`) Will disable generation of alias redirects. Note that even if `disableAliases` is set, the aliases themselves are preserved on the page. The motivation with this is to be able to generate 301 redirects in an `.htaccess`, a Netlify `_redirects` file or similar using a custom output format. Default is `false`.
|
||||
|
||||
###### disableDefaultLanguageRedirect
|
||||
|
||||
{{< new-in 0.140.0 >}}
|
||||
|
||||
(`bool`) Disables generation of redirect to the default language when DefaultContentLanguageInSubdir is `true`. Default is `false`.
|
||||
|
||||
###### disableHugoGeneratorInject
|
||||
|
||||
(`bool`) Hugo will, by default, inject a generator meta tag in the HTML head on the _home page only_. You can turn it off, but we would really appreciate if you don't, as this is a good way to watch Hugo's popularity on the rise. Default is `false`.
|
||||
@@ -439,7 +445,7 @@ See [Content Management](/content-management/urls/#permalinks).
|
||||
|
||||
###### publishDir
|
||||
|
||||
(`string`) The directory to where Hugo will write the final static site (the HTML files etc.). Default is `public`.
|
||||
(`string`) The directory where Hugo will write the final static site (the HTML files etc.). Default is `public`.
|
||||
|
||||
###### refLinksErrorLevel
|
||||
|
||||
|
||||
@@ -207,6 +207,10 @@ See [template](#template).
|
||||
|
||||
A directory that contains an index.md file and zero or more [resources](#resource). Analogous to a physical leaf, a leaf bundle is at the end of a branch. It has no descendants. See [details](/content-management/page-bundles/).
|
||||
|
||||
###### lexer
|
||||
|
||||
A software component that identifies keywords, identifiers, operators, numbers, and other basic building blocks of a programming language within the input text.
|
||||
|
||||
###### list page
|
||||
|
||||
Any [page kind](#page-kind) that receives a page [collection](#collection) in [context](#context). This includes the home page, [section pages](#section-page), [taxonomy pages](#taxonomy-page), and [term pages](#term-page).
|
||||
|
||||
@@ -99,7 +99,7 @@ To view your site while developing layouts or creating content, `cd` into your p
|
||||
hugo server
|
||||
```
|
||||
|
||||
The [`hugo server`] command builds your site into memory, and serves your pages using a minimal HTTP server. When you run `hugo server` it will display the URL of your local site:
|
||||
The [`hugo server`] command builds your site and serves your pages using a minimal HTTP server. When you run `hugo server` it will display the URL of your local site:
|
||||
|
||||
```text
|
||||
Web Server is available at http://localhost:1313/
|
||||
|
||||
@@ -27,16 +27,15 @@ Define your [CI/CD](https://docs.gitlab.com/ee/ci/quick_start/) jobs by creating
|
||||
|
||||
{{< code file=.gitlab-ci.yml copy=true >}}
|
||||
variables:
|
||||
DART_SASS_VERSION: 1.80.6
|
||||
HUGO_VERSION: 0.137.1
|
||||
NODE_VERSION: 20.x
|
||||
DART_SASS_VERSION: 1.81.1
|
||||
GIT_DEPTH: 0
|
||||
GIT_STRATEGY: clone
|
||||
GIT_SUBMODULE_STRATEGY: recursive
|
||||
HUGO_VERSION: 0.140.2
|
||||
NODE_VERSION: 23.x
|
||||
TZ: America/Los_Angeles
|
||||
|
||||
image:
|
||||
name: golang:1.22.1-bookworm
|
||||
name: golang:1.23.4-bookworm
|
||||
|
||||
pages:
|
||||
script:
|
||||
@@ -59,7 +58,7 @@ pages:
|
||||
# Install Node.js dependencies
|
||||
- "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
|
||||
# Build
|
||||
- hugo --gc --minify
|
||||
- hugo --gc --minify --baseURL ${CI_PAGES_URL}
|
||||
# Compress
|
||||
- find public -type f -regex '.*\.\(css\|html\|js\|txt\|xml\)$' -exec gzip -f -k {} \;
|
||||
- find public -type f -regex '.*\.\(css\|html\|js\|txt\|xml\)$' -exec brotli -f -k {} \;
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
---
|
||||
title: Babel
|
||||
description: Hugo Pipes can process JS files with Babel.
|
||||
categories: [asset management]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: hugo-pipes
|
||||
weight: 70
|
||||
weight: 70
|
||||
function:
|
||||
aliases: [babel]
|
||||
returnType: resource.Resource
|
||||
signatures: ['js.Babel [OPTIONS] RESOURCE']
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
Any JavaScript resource file can be transpiled to another JavaScript version using `js.Babel` which takes for argument the resource object and an optional dict of options listed below. Babel uses the [babel cli](https://babeljs.io/docs/en/babel-cli).
|
||||
|
||||
{{% note %}}
|
||||
Hugo Pipe's Babel requires the `@babel/cli` and `@babel/core` JavaScript packages to be installed in the project or globally (`npm install -g @babel/cli @babel/core`) along with any Babel plugin(s) or preset(s) used (e.g., `npm install @babel/preset-env --save-dev`).
|
||||
|
||||
If you are using the Hugo Snap package, Babel and plugin(s) need to be installed locally within your Hugo site directory, e.g., `npm install @babel/cli @babel/core --save-dev` without the `-g` flag.
|
||||
{{% /note %}}
|
||||
|
||||
## Configuration
|
||||
|
||||
We add the main project's `node_modules` to `NODE_PATH` when running Babel and similar tools. There are some known [issues](https://github.com/babel/babel/issues/5618) with Babel in this area, so if you have a `babel.config.js` living in a Hugo Module (and not in the project itself), we recommend using `require` to load the presets/plugins, e.g.:
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
presets: [
|
||||
[
|
||||
require("@babel/preset-env"),
|
||||
{
|
||||
useBuiltIns: "entry",
|
||||
corejs: 3,
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
config
|
||||
: (`string`) Path to the Babel configuration file. Hugo will, by default, look for a `babel.config.js` in your project. More information on these configuration files can be found here: [babel configuration](https://babeljs.io/docs/en/configuration).
|
||||
|
||||
minified
|
||||
: (`bool`) Save as many bytes as possible when printing
|
||||
|
||||
noComments
|
||||
: (`bool`) Write comments to generated output (true by default)
|
||||
|
||||
compact
|
||||
: (`bool`) Do not include superfluous whitespace characters and line terminators. Defaults to `auto` if not set.
|
||||
|
||||
verbose
|
||||
: (`bool`) Log everything
|
||||
|
||||
sourceMap
|
||||
: (`string`) Output `inline` or `external` sourcemap from the babel compile. External sourcemaps will be written to the target with the output file name + ".map". Input sourcemaps can be read from js.Build and node modules and combined into the output sourcemaps.
|
||||
|
||||
## Examples
|
||||
|
||||
```go-html-template
|
||||
{{- $transpiled := resources.Get "scripts/main.js" | babel -}}
|
||||
```
|
||||
|
||||
Or with options:
|
||||
|
||||
```go-html-template
|
||||
{{ $opts := dict "noComments" true }}
|
||||
{{- $transpiled := resources.Get "scripts/main.js" | babel $opts -}}
|
||||
```
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: js.Build
|
||||
title: JavaScript
|
||||
linkTitle: JavaScript building
|
||||
description: Bundle, transpile, tree shake, and minify JavaScript resources.
|
||||
description: Bundle, transpile, tree shake, code split, and minify JavaScript resources.
|
||||
categories: [asset management]
|
||||
keywords: []
|
||||
menu:
|
||||
@@ -9,181 +9,7 @@ menu:
|
||||
parent: hugo-pipes
|
||||
weight: 60
|
||||
weight: 60
|
||||
action:
|
||||
aliases: []
|
||||
returnType: resource.Resource
|
||||
signatures: ['js.Build [OPTIONS] RESOURCE']
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
Any JavaScript resource file can be transpiled and "tree shaken" using `js.Build` which takes for argument either a string for the file path or a dict of options listed below.
|
||||
|
||||
### Options
|
||||
|
||||
targetPath
|
||||
: (`string`) If not set, the source path will be used as the base target path.
|
||||
Note that the target path's extension may change if the target MIME type is different, e.g. when the source is TypeScript.
|
||||
|
||||
params
|
||||
: (`map` or `slice`) Params that can be imported as JSON in your JS files, e.g.:
|
||||
|
||||
```go-html-template
|
||||
{{ $js := resources.Get "js/main.js" | js.Build (dict "params" (dict "api" "https://example.org/api")) }}
|
||||
```
|
||||
And then in your JS file:
|
||||
|
||||
```js
|
||||
import * as params from '@params';
|
||||
```
|
||||
|
||||
Note that this is meant for small data sets, e.g. configuration settings. For larger data, please put/mount the files into `/assets` and import them directly.
|
||||
|
||||
minify
|
||||
: (`bool`) Let `js.Build` handle the minification.
|
||||
|
||||
inject
|
||||
: (`slice`) This option allows you to automatically replace a global variable with an import from another file. The path names must be relative to `assets`. See https://esbuild.github.io/api/#inject
|
||||
|
||||
shims
|
||||
: (`map`) This option allows swapping out a component with another. A common use case is to load dependencies like React from a CDN (with _shims_) when in production, but running with the full bundled `node_modules` dependency during development:
|
||||
|
||||
```go-html-template
|
||||
{{ $shims := dict "react" "js/shims/react.js" "react-dom" "js/shims/react-dom.js" }}
|
||||
{{ $js = $js | js.Build dict "shims" $shims }}
|
||||
```
|
||||
|
||||
The _shim_ files may look like these:
|
||||
|
||||
```js
|
||||
// js/shims/react.js
|
||||
module.exports = window.React;
|
||||
```
|
||||
|
||||
```js
|
||||
// js/shims/react-dom.js
|
||||
module.exports = window.ReactDOM;
|
||||
```
|
||||
|
||||
With the above, these imports should work in both scenarios:
|
||||
|
||||
```js
|
||||
import * as React from 'react'
|
||||
import * as ReactDOM from 'react-dom';
|
||||
```
|
||||
|
||||
target
|
||||
: (`string`) The language target.
|
||||
One of: `es5`, `es2015`, `es2016`, `es2017`, `es2018`, `es2019`, `es2020` or `esnext`.
|
||||
Default is `esnext`.
|
||||
|
||||
externals
|
||||
: (`slice`) External dependencies. Use this to trim dependencies you know will never be executed. See https://esbuild.github.io/api/#external
|
||||
|
||||
defines
|
||||
: (`map`) Allow to define a set of string replacement to be performed when building. Should be a map where each key is to be replaced by its value.
|
||||
|
||||
```go-html-template
|
||||
{{ $defines := dict "process.env.NODE_ENV" `"development"` }}
|
||||
```
|
||||
|
||||
format
|
||||
: (`string`) The output format.
|
||||
One of: `iife`, `cjs`, `esm`.
|
||||
Default is `iife`, a self-executing function, suitable for inclusion as a `<script>` tag.
|
||||
|
||||
sourceMap
|
||||
: (`string`) Whether to generate `inline` or `external` source maps from esbuild. External source maps will be written to the target with the output file name + ".map". Input source maps can be read from js.Build and node modules and combined into the output source maps. By default, source maps are not created.
|
||||
|
||||
JSX {{< new-in 0.124.0 >}}
|
||||
: (`string`) How to handle/transform JSX syntax. One of: `transform`, `preserve`, `automatic`. Default is `transform`. Notably, the `automatic` transform was introduced in React 17+ and will cause the necessary JSX helper functions to be imported automatically. See https://esbuild.github.io/api/#jsx
|
||||
|
||||
JSXImportSource {{< new-in 0.124.0 >}}
|
||||
: (`string`) Which library to use to automatically import its JSX helper functions from. This only works if `JSX` is set to `automatic`. The specified library needs to be installed through NPM and expose certain exports. See https://esbuild.github.io/api/#jsx-import-source
|
||||
|
||||
The combination of `JSX` and `JSXImportSource` is helpful if you want to use a non-React JSX library like Preact, e.g.:
|
||||
|
||||
```go-html-template
|
||||
{{ $js := resources.Get "js/main.jsx" | js.Build (dict "JSX" "automatic" "JSXImportSource" "preact") }}
|
||||
```
|
||||
|
||||
With the above, you can use Preact components and JSX without having to manually import `h` and `Fragment` every time:
|
||||
|
||||
```jsx
|
||||
import { render } from 'preact';
|
||||
|
||||
const App = () => <>Hello world!</>;
|
||||
|
||||
const container = document.getElementById('app');
|
||||
if (container) render(<App />, container);
|
||||
```
|
||||
|
||||
### Import JS code from /assets
|
||||
|
||||
`js.Build` has full support for the virtual union file system in [Hugo Modules](/hugo-modules/). You can see some simple examples in this [test project](https://github.com/gohugoio/hugoTestProjectJSModImports), but in short this means that you can do this:
|
||||
|
||||
```js
|
||||
import { hello } from 'my/module';
|
||||
```
|
||||
|
||||
And it will resolve to the top-most `index.{js,ts,tsx,jsx}` inside `assets/my/module` in the layered file system.
|
||||
|
||||
```js
|
||||
import { hello3 } from 'my/module/hello3';
|
||||
```
|
||||
|
||||
Will resolve to `hello3.{js,ts,tsx,jsx}` inside `assets/my/module`.
|
||||
|
||||
Any imports starting with `.` is resolved relative to the current file:
|
||||
|
||||
```js
|
||||
import { hello4 } from './lib';
|
||||
```
|
||||
|
||||
For other files (e.g. `JSON`, `CSS`) you need to use the relative path including any extension, e.g:
|
||||
|
||||
```js
|
||||
import * as data from 'my/module/data.json';
|
||||
```
|
||||
|
||||
Any imports in a file outside `/assets` or that does not resolve to a component inside `/assets` will be resolved by [ESBuild](https://esbuild.github.io/) with the **project directory** as the resolve directory (used as the starting point when looking for `node_modules` etc.). Also see [hugo mod npm pack](/commands/hugo_mod_npm_pack/). If you have any imported npm dependencies in your project, you need to make sure to run `npm install` before you run `hugo`.
|
||||
|
||||
Also note the new `params` option that can be passed from template to your JS files, e.g.:
|
||||
|
||||
```go-html-template
|
||||
{{ $js := resources.Get "js/main.js" | js.Build (dict "params" (dict "api" "https://example.org/api")) }}
|
||||
```
|
||||
And then in your JS file:
|
||||
|
||||
```js
|
||||
import * as params from '@params';
|
||||
```
|
||||
|
||||
Hugo will, by default, generate a `assets/jsconfig.json` file that maps the imports. This is useful for navigation/intellisense help inside code editors, but if you don't need/want it, you can [turn it off](/getting-started/configuration/#configure-build).
|
||||
|
||||
### Include dependencies In package.json / node_modules
|
||||
|
||||
Any imports in a file outside `/assets` or that does not resolve to a component inside `/assets` will be resolved by [ESBuild](https://esbuild.github.io/) with the **project directory** as the resolve directory (used as the starting point when looking for `node_modules` etc.). Also see [hugo mod npm pack](/commands/hugo_mod_npm_pack/). If you have any imported npm dependencies in your project, you need to make sure to run `npm install` before you run `hugo`.
|
||||
|
||||
The start directory for resolving npm packages (aka. packages that live inside a `node_modules` folder) is always the main project folder.
|
||||
|
||||
{{% note %}}
|
||||
If you're developing a theme/component that is supposed to be imported and depends on dependencies inside `package.json`, we recommend reading about [hugo mod npm pack](/commands/hugo_mod_npm_pack/), a tool to consolidate all the npm dependencies in a project.
|
||||
{{% /note %}}
|
||||
|
||||
### Examples
|
||||
|
||||
```go-html-template
|
||||
{{ $built := resources.Get "js/index.js" | js.Build "main.js" }}
|
||||
```
|
||||
|
||||
Or with options:
|
||||
|
||||
```go-html-template
|
||||
{{ $externals := slice "react" "react-dom" }}
|
||||
{{ $defines := dict "process.env.NODE_ENV" `"development"` }}
|
||||
|
||||
{{ $opts := dict "targetPath" "main.js" "externals" $externals "defines" $defines }}
|
||||
{{ $built := resources.Get "scripts/main.js" | js.Build $opts }}
|
||||
<script src="{{ $built.RelPermalink }}" defer></script>
|
||||
```
|
||||
See [JS functions](/functions/js/).
|
||||
|
||||
@@ -9,9 +9,9 @@ action:
|
||||
signatures: [MENUENTRY.Name]
|
||||
---
|
||||
|
||||
If you define the menu entry [automatically], the `Name` method returns the page’s [`LinkTitle`], falling back to its [`Title`].
|
||||
If you define the menu entry [automatically], the `Name` method returns the page's [`LinkTitle`], falling back to its [`Title`].
|
||||
|
||||
If you define the menu entry [in front matter] or [in site configuration], the `Name` method returns the `name` property, falling back to the page’s `LinkTitle`, then to its `Title`.
|
||||
If you define the menu entry [in front matter] or [in site configuration], the `Name` method returns the `name` property of the given menu entry. If the `name` is not defined, and the menu entry resolves to a page, the `Name` returns the page [`LinkTitle`], falling back to its [`Title`].
|
||||
|
||||
[`LinkTitle`]: /methods/page/linktitle/
|
||||
[`Title`]: /methods/page/title/
|
||||
|
||||
@@ -9,20 +9,14 @@ action:
|
||||
signatures: [MENUENTRY.Title]
|
||||
---
|
||||
|
||||
If you define the menu entry [automatically], the `Title` method returns the page’s [`LinkTitle`], falling back to its [`Title`].
|
||||
The `Title` method returns the `title` property of the given menu entry. If the `title` is not defined, and the menu entry resolves to a page, the `Title` returns the page [`Title`].
|
||||
|
||||
If you define the menu entry [in front matter] or [in site configuration], the `Title` method returns the `title` property, falling back to the page’s `LinkTitle`, then to its `Title`.
|
||||
|
||||
[`LinkTitle`]: /methods/page/linktitle/
|
||||
[`Title`]: /methods/page/title/
|
||||
[automatically]: /content-management/menus/#define-automatically
|
||||
[in front matter]: /content-management/menus/#define-in-front-matter
|
||||
[in site configuration]: /content-management/menus/#define-in-site-configuration
|
||||
|
||||
```go-html-template
|
||||
<ul>
|
||||
{{ range .Site.Menus.main }}
|
||||
<li><a href="{{ .URL }}">{{ .Title }}</a></li>
|
||||
<li><a href="{{ .URL }}" title="{{ .Title }}>{{ .Name }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
|
||||
@@ -28,14 +28,15 @@ Use the `Fragments` method on a `Page` object to create a table of contents with
|
||||
## Methods
|
||||
|
||||
Headings
|
||||
: (`map`) A nested map of all headings on the page. Each map contains the following keys: `ID`, `Level`, `Title` and `Headings`. To inspect the data structure:
|
||||
: (`slice`) A slice of maps of all headings on the page, with first-level keys for each heading. Each map contains the following keys: `ID`, `Level`, `Title` and `Headings`. To inspect the data structure:
|
||||
|
||||
```go-html-template
|
||||
<pre>{{ debug.Dump .Fragments.Headings }}</pre>
|
||||
```
|
||||
|
||||
|
||||
HeadingsMap
|
||||
: (`slice`) A slice of maps of all headings on the page, with first-level keys for each heading. Each map contains the following keys: `ID`, `Level`, `Title` and `Headings`. To inspect the data structure:
|
||||
: (`map`) A nested map of all headings on the page. Each map contains the following keys: `ID`, `Level`, `Title` and `Headings`. To inspect the data structure:
|
||||
|
||||
```go-html-template
|
||||
<pre>{{ debug.Dump .Fragments.HeadingsMap }}</pre>
|
||||
|
||||
@@ -24,8 +24,14 @@ Use this method in shortcode templates to compose a page from multiple content f
|
||||
For example:
|
||||
|
||||
{{< code file=layouts/shortcodes/include.html >}}
|
||||
{{ with site.GetPage (.Get 0) }}
|
||||
{{ .RenderShortcodes }}
|
||||
{{ with .Get 0 }}
|
||||
{{ with $.Page.GetPage . }}
|
||||
{{- .RenderShortcodes }}
|
||||
{{ else }}
|
||||
{{ errorf "The %q shortcode was unable to find %q. See %s" $.Name . $.Position }}
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ errorf "The %q shortcode requires a positional parameter indicating the logical path of the file to include. See %s" .Name .Position }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
|
||||
@@ -69,6 +69,20 @@ When working with global resources instead of page resources, use the [`resource
|
||||
|
||||
When working with global resources instead of page resources, use the [`resources.Match`] function.
|
||||
|
||||
###### Mount
|
||||
|
||||
{{< new-in "0.140.0" >}}
|
||||
|
||||
(`ResourceGetter`) Mounts the given resources from the two arguments base (`string`) to the given target path (`string`) and returns an object that implements [Get](#get). Note that leading slashes in target marks an absolute path. Relative target paths allows you to mount resources relative to another set, e.g. a [Page bundle](/content-management/page-bundles/):
|
||||
|
||||
```go-html-template
|
||||
{{ $common := resources.Match "/js/headlessui/*.*" }}
|
||||
{{ $importContext := (slice $.Page ($common.Mount "/js/headlessui" ".")) }}
|
||||
```
|
||||
|
||||
This method is currently only useful in [js.Batch](/functions/js/batch/#import-context).
|
||||
|
||||
|
||||
## Pattern matching
|
||||
|
||||
With the `GetMatch` and `Match` methods, Hugo determines a match using a case-insensitive [glob pattern].
|
||||
|
||||
@@ -6,7 +6,7 @@ keywords: []
|
||||
action:
|
||||
related:
|
||||
- functions/images/Filter
|
||||
returnType: resources.resourceAdapter
|
||||
returnType: images.ImageResource
|
||||
signatures: [RESOURCE.Filter FILTER...]
|
||||
toc: true
|
||||
---
|
||||
|
||||
@@ -9,8 +9,14 @@ _comment: Do not remove front matter.
|
||||
The primary use case for `PageInner` is to resolve links and [page resources] relative to an included `Page`. For example, create an "include" shortcode to compose a page from multiple content files, while preserving a global context for footnotes and the table of contents:
|
||||
|
||||
{{< code file=layouts/shortcodes/include.html >}}
|
||||
{{ with site.GetPage (.Get 0) }}
|
||||
{{ .RenderShortcodes }}
|
||||
{{ with .Get 0 }}
|
||||
{{ with $.Page.GetPage . }}
|
||||
{{- .RenderShortcodes }}
|
||||
{{ else }}
|
||||
{{ errorf "The %q shortcode was unable to find %q. See %s" $.Name . $.Position }}
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ errorf "The %q shortcode requires a positional parameter indicating the logical path of the file to include. See %s" .Name .Position }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ In its default configuration, Hugo renders Markdown headings according to the [C
|
||||
[CommonMark specification]: https://spec.commonmark.org/current/
|
||||
|
||||
{{< code file=layouts/_default/_markup/render-heading.html copy=true >}}
|
||||
<h{{ .Level }} id="{{ .Anchor }}">
|
||||
<h{{ .Level }} id="{{ .Anchor }}" {{- with .Attributes.class }} class="{{ . }}" {{- end }}>
|
||||
{{- .Text -}}
|
||||
</h{{ .Level }}>
|
||||
{{< /code >}}
|
||||
@@ -72,7 +72,7 @@ In its default configuration, Hugo renders Markdown headings according to the [C
|
||||
To add an anchor link to the right of each heading:
|
||||
|
||||
{{< code file=layouts/_default/_markup/render-heading.html copy=true >}}
|
||||
<h{{ .Level }} id="{{ .Anchor }}">
|
||||
<h{{ .Level }} id="{{ .Anchor }}" {{- with .Attributes.class }} class="{{ . }}" {{- end }}>
|
||||
{{ .Text }}
|
||||
<a href="#{{ .Anchor }}">#</a>
|
||||
</h{{ .Level }}>
|
||||
|
||||
@@ -91,7 +91,7 @@ In its default configuration, Hugo renders Markdown images according to the [Com
|
||||
|
||||
{{< code file=layouts/_default/_markup/render-image.html copy=true >}}
|
||||
<img src="{{ .Destination | safeURL }}"
|
||||
{{- with .Text }} alt="{{ . }}"{{ end -}}
|
||||
{{- with .PlainText }} alt="{{ . }}"{{ end -}}
|
||||
{{- with .Title }} title="{{ . }}"{{ end -}}
|
||||
>
|
||||
{{- /* chomp trailing newline */ -}}
|
||||
@@ -103,13 +103,13 @@ To render standalone images within `figure` elements:
|
||||
{{- if .IsBlock -}}
|
||||
<figure>
|
||||
<img src="{{ .Destination | safeURL }}"
|
||||
{{- with .Text }} alt="{{ . }}"{{ end -}}
|
||||
{{- with .PlainText }} alt="{{ . }}"{{ end -}}
|
||||
>
|
||||
{{- with .Title }}<figcaption>{{ . }}</figcaption>{{ end -}}
|
||||
</figure>
|
||||
{{- else -}}
|
||||
<img src="{{ .Destination | safeURL }}"
|
||||
{{- with .Text }} alt="{{ . }}"{{ end -}}
|
||||
{{- with .PlainText }} alt="{{ . }}"{{ end -}}
|
||||
{{- with .Title }} title="{{ . }}"{{ end -}}
|
||||
>
|
||||
{{- end -}}
|
||||
|
||||
+10
-2
@@ -1005,6 +1005,7 @@ config:
|
||||
targets: null
|
||||
workers: 10
|
||||
disableAliases: false
|
||||
disableDefaultLanguageRedirect: false
|
||||
disableHugoGeneratorInject: false
|
||||
disableKinds: null
|
||||
disableLanguages: null
|
||||
@@ -1148,6 +1149,7 @@ config:
|
||||
noHl: false
|
||||
style: monokai
|
||||
tabWidth: 4
|
||||
wrapperClass: highlight
|
||||
tableOfContents:
|
||||
endLevel: 3
|
||||
ordered: false
|
||||
@@ -2560,8 +2562,9 @@ tpl:
|
||||
- querify
|
||||
Args:
|
||||
- params
|
||||
Description: Querify encodes the given params in URL-encoded form ("bar=baz&foo=quux")
|
||||
sorted by key.
|
||||
Description: |-
|
||||
Querify returns a URL query string composed of the given key-value pairs,
|
||||
encoded and sorted by key.
|
||||
Examples:
|
||||
- - '{{ (querify "foo" 1 "bar" 2 "baz" "with spaces" "qux" "this&that=those")
|
||||
| safeHTML }}'
|
||||
@@ -3289,6 +3292,11 @@ tpl:
|
||||
- args
|
||||
Description: Babel processes the given Resource with Babel.
|
||||
Examples: []
|
||||
Batch:
|
||||
Aliases: null
|
||||
Args: null
|
||||
Description: ""
|
||||
Examples: null
|
||||
Build:
|
||||
Aliases: null
|
||||
Args: null
|
||||
|
||||
@@ -10,18 +10,18 @@
|
||||
'google_analytics' = 'google_analytics.html'
|
||||
'opengraph' = 'opengraph.html'
|
||||
'pagination' = 'pagination.html'
|
||||
'schema' = 'schema.html'
|
||||
'twitter_cards' = 'twitter_cards.html'
|
||||
|
||||
'robots' = '_default/robots.txt'
|
||||
'rss' = '_default/rss.xml'
|
||||
'schema' = 'schema.html'
|
||||
'sitemap' = '_default/sitemap.xml'
|
||||
'sitemapindex' = '_default/sitemapindex.xml'
|
||||
'twitter_cards' = 'twitter_cards.html'
|
||||
|
||||
# Render hooks
|
||||
'render-codeblock-goat' = '_default/_markup/render-codeblock-goat.html'
|
||||
'render-image' = '_default/_markup/render-image.html'
|
||||
'render-link' = '_default/_markup/render-link.html'
|
||||
'render-codeblock-goat' = '_default/_markup/render-codeblock-goat.html'
|
||||
'render-table' = '_default/_markup/render-table.html'
|
||||
|
||||
# Shortcodes
|
||||
'comment' = 'shortcodes/comment.html'
|
||||
@@ -31,6 +31,7 @@
|
||||
'highlight' = 'shortcodes/highlight.html'
|
||||
'instagram' = 'shortcodes/instagram.html'
|
||||
'param' = 'shortcodes/param.html'
|
||||
'qr' = 'shortcodes/qr.html'
|
||||
'ref' = 'shortcodes/ref.html'
|
||||
'relref' = 'shortcodes/relref.html'
|
||||
'twitter' = 'shortcodes/twitter.html'
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user