Documentation ¶
Overview ¶
Package modules provides a client that can be used to manage Hugo Components, what's referred to as Hugo Modules. Hugo Modules is built on top of Go Modules, but also supports vendoring and components stored directly in the themes dir.
Index ¶
- Variables
- func ApplyProjectConfigDefaults(cfg config.Provider, mod Module) error
- func IsNotExist(err error) bool
- type Client
- func (c *Client) Clean(pattern string) error
- func (h *Client) Collect() (ModulesConfig, error)
- func (c *Client) Get(args ...string) error
- func (c *Client) Graph(w io.Writer) error
- func (c *Client) Init(path string) error
- func (c *Client) Tidy() error
- func (c *Client) Vendor() error
- func (c *Client) Verify(clean bool) error
- type ClientConfig
- type Config
- type HugoVersion
- type Import
- type Module
- type Modules
- type ModulesConfig
- type Mount
Constants ¶
This section is empty.
Variables ¶
var DefaultModuleConfig = Config{ Proxy: "direct", NoProxy: "none", Private: "*.*", Replacements: nil, }
var ErrNotExist = errors.New("module does not exist")
Functions ¶
func ApplyProjectConfigDefaults ¶
ApplyProjectConfigDefaults applies default/missing module configuration for the main project.
func IsNotExist ¶
IsNotExist returns whether an error means that a module could not be found.
Types ¶
type Client ¶
type Client struct { // Set when Go modules are initialized in the current repo, that is: // a go.mod file exists. GoModulesFilename string // contains filtered or unexported fields }
Client contains most of the API provided by this package.
func NewClient ¶
func NewClient(cfg ClientConfig) *Client
NewClient creates a new Client that can be used to manage the Hugo Components in a given workingDir. The Client will resolve the dependencies recursively, but needs the top level imports to start out.
func (*Client) Collect ¶
func (h *Client) Collect() (ModulesConfig, error)
func (*Client) Init ¶
Init initializes this as a Go Module with the given path. If path is empty, Go will try to guess. If this succeeds, this project will be marked as Go Module.
func (*Client) Vendor ¶
Vendor writes all the module dependencies to a _vendor folder.
Unlike Go, we support it for any level.
We, by default, use the /_vendor folder first, if found. To disable, run with
hugo --ignoreVendor
Given a module tree, Hugo will pick the first module for a given path, meaning that if the top-level module is vendored, that will be the full set of dependencies.
type ClientConfig ¶
type ClientConfig struct { Fs afero.Fs Logger loggers.Logger // If set, it will be run before we do any duplicate checks for modules // etc. HookBeforeFinalize func(m *ModulesConfig) error // Ignore any _vendor directory for module paths matching the given pattern. // This can be nil. IgnoreVendor glob.Glob // Absolute path to the project dir. WorkingDir string // Absolute path to the project's themes dir. ThemesDir string CacheDir string // Module cache ModuleConfig Config }
ClientConfig configures the module Client.
type Config ¶
type Config struct { Mounts []Mount Imports []Import // Meta info about this module (license information etc.). Params map[string]interface{} // Will be validated against the running Hugo version. HugoVersion HugoVersion // A optional Glob pattern matching module paths to skip when vendoring, e.g. // "github.com/**". NoVendor string Replacements []string // Configures GOPROXY. Proxy string // Configures GONOPROXY. NoProxy string // Configures GOPRIVATE. Private string // contains filtered or unexported fields }
Config holds a module config.
type HugoVersion ¶
type HugoVersion struct { // The minimum Hugo version that this module works with. Min hugo.VersionString // The maxium Hugo version that this module works with. Max hugo.VersionString // Set if the extended version is needed. Extended bool }
HugoVersion holds Hugo binary version requirements for a module.
func (HugoVersion) IsValid ¶
func (v HugoVersion) IsValid() bool
IsValid reports whether this version is valid compared to the running Hugo binary.
func (HugoVersion) String ¶
func (v HugoVersion) String() string
type Import ¶
type Import struct { Path string // Module path IgnoreConfig bool // Ignore any config in config.toml (will still folow imports). IgnoreImports bool // Do not follow any configured imports. NoVendor bool // Never vendor this import (only allowed in main project). Disable bool // Turn off this module. Mounts []Mount }
type Module ¶
type Module interface { // Optional config read from the configFilename above. Cfg() config.Provider // The decoded module config and mounts. Config() Config // Optional configuration filename (e.g. "/themes/mytheme/config.json"). // This will be added to the special configuration watch list when in // server mode. ConfigFilename() string // Directory holding files for this module. Dir() string // This module is disabled. Disabled() bool // Returns whether this is a Go Module. IsGoMod() bool // Any directory remappings. Mounts() []Mount // In the dependency tree, this is the first module that defines this module // as a dependency. Owner() Module // Returns the path to this module. // This will either be the module path, e.g. "github.com/gohugoio/myshortcodes", // or the path below your /theme folder, e.g. "mytheme". Path() string // Replaced by this module. Replace() Module // Returns whether Dir points below the _vendor dir. Vendor() bool // The module version. Version() string // Whether this module's dir is a watch candidate. Watch() bool }