mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-15 20:44:01 +02:00
Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code. Also, * Lower case the default output format names; this is in line with the custom ones (map keys) and how it's treated all the places. This avoids doing `stringds.EqualFold` everywhere. Closes #10896 Closes #10620
This commit is contained in:
@@ -52,20 +52,6 @@ func IsNotExist(err error) bool {
|
||||
return errors.Is(err, os.ErrNotExist)
|
||||
}
|
||||
|
||||
// CreateProjectModule creates modules from the given config.
|
||||
// This is used in tests only.
|
||||
func CreateProjectModule(cfg config.Provider) (Module, error) {
|
||||
workingDir := cfg.GetString("workingDir")
|
||||
var modConfig Config
|
||||
|
||||
mod := createProjectModule(nil, workingDir, modConfig)
|
||||
if err := ApplyProjectConfigDefaults(cfg, mod); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mod, nil
|
||||
}
|
||||
|
||||
func (h *Client) Collect() (ModulesConfig, error) {
|
||||
mc, coll := h.collect(true)
|
||||
if coll.err != nil {
|
||||
@@ -90,6 +76,9 @@ func (h *Client) Collect() (ModulesConfig, error) {
|
||||
}
|
||||
|
||||
func (h *Client) collect(tidy bool) (ModulesConfig, *collector) {
|
||||
if h == nil {
|
||||
panic("nil client")
|
||||
}
|
||||
c := &collector{
|
||||
Client: h,
|
||||
}
|
||||
@@ -133,6 +122,16 @@ type ModulesConfig struct {
|
||||
GoWorkspaceFilename string
|
||||
}
|
||||
|
||||
func (m ModulesConfig) HasConfigFile() bool {
|
||||
for _, mod := range m.ActiveModules {
|
||||
if len(mod.ConfigFilenames()) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *ModulesConfig) setActiveMods(logger loggers.Logger) error {
|
||||
var activeMods Modules
|
||||
for _, mod := range m.AllModules {
|
||||
@@ -230,6 +229,7 @@ func (c *collector) getVendoredDir(path string) (vendoredModule, bool) {
|
||||
}
|
||||
|
||||
func (c *collector) add(owner *moduleAdapter, moduleImport Import, disabled bool) (*moduleAdapter, error) {
|
||||
|
||||
var (
|
||||
mod *goModule
|
||||
moduleDir string
|
||||
@@ -299,7 +299,7 @@ func (c *collector) add(owner *moduleAdapter, moduleImport Import, disabled bool
|
||||
return nil, nil
|
||||
}
|
||||
if found, _ := afero.Exists(c.fs, moduleDir); !found {
|
||||
c.err = c.wrapModuleNotFound(fmt.Errorf(`module %q not found; either add it as a Hugo Module or store it in %q.`, modulePath, c.ccfg.ThemesDir))
|
||||
c.err = c.wrapModuleNotFound(fmt.Errorf(`module %q not found in % q; either add it as a Hugo Module or store it in %q.`, modulePath, moduleDir, c.ccfg.ThemesDir))
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
@@ -347,7 +347,7 @@ func (c *collector) addAndRecurse(owner *moduleAdapter, disabled bool) error {
|
||||
moduleConfig := owner.Config()
|
||||
if owner.projectMod {
|
||||
if err := c.applyMounts(Import{}, owner); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to apply mounts for project module: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,7 +618,7 @@ func (c *collector) mountCommonJSConfig(owner *moduleAdapter, mounts []Mount) ([
|
||||
// Mount the common JS config files.
|
||||
fis, err := afero.ReadDir(c.fs, owner.Dir())
|
||||
if err != nil {
|
||||
return mounts, err
|
||||
return mounts, fmt.Errorf("failed to read dir %q: %q", owner.Dir(), err)
|
||||
}
|
||||
|
||||
for _, fi := range fis {
|
||||
|
Reference in New Issue
Block a user