hugo: github.com/gohugoio/hugo/modules Index | Files

package modules

import "github.com/gohugoio/hugo/modules"

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

Package Files

client.go collect.go config.go module.go

Variables

var DefaultModuleConfig = Config{

    Proxy: "direct",

    NoProxy: "none",

    Private: "*.*",
}
var ErrNotExist = errors.New("module does not exist")

func ApplyProjectConfigDefaults Uses

func ApplyProjectConfigDefaults(cfg config.Provider, mod Module) error

ApplyProjectConfigDefaults applies default/missing module configuration for the main project.

func IsNotExist Uses

func IsNotExist(err error) bool

IsNotExist returns whether an error means that a module could not be found.

type Client Uses

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 Uses

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) Clean Uses

func (c *Client) Clean(pattern string) error

func (*Client) Collect Uses

func (h *Client) Collect() (ModulesConfig, error)

func (*Client) Get Uses

func (c *Client) Get(args ...string) error

Get runs "go get" with the supplied arguments.

func (*Client) Graph Uses

func (c *Client) Graph(w io.Writer) error

Graph writes a module dependenchy graph to the given writer.

func (*Client) Init Uses

func (c *Client) Init(path string) error

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) Tidy Uses

func (c *Client) Tidy() error

Tidy can be used to remove unused dependencies from go.mod and go.sum.

func (*Client) Vendor Uses

func (c *Client) Vendor() error

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.

func (*Client) Verify Uses

func (c *Client) Verify(clean bool) error

Verify checks that the dependencies of the current module, which are stored in a local downloaded source cache, have not been modified since being downloaded.

type ClientConfig Uses

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.
    IgnoreVendor bool

    // 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 Uses

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

    // Configures GOPROXY.
    Proxy string
    // Configures GONOPROXY.
    NoProxy string
    // Configures GOPRIVATE.
    Private string
}

Config holds a module config.

func DecodeConfig Uses

func DecodeConfig(cfg config.Provider) (Config, error)

DecodeConfig creates a modules Config from a given Hugo configuration.

type HugoVersion Uses

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 Uses

func (v HugoVersion) IsValid() bool

IsValid reports whether this version is valid compared to the running Hugo binary.

func (HugoVersion) String Uses

func (v HugoVersion) String() string

type Import Uses

type Import struct {
    Path         string // Module path
    IgnoreConfig bool   // Ignore any config.toml found.
    Disable      bool   // Turn off this module.
    Mounts       []Mount
}

type Module Uses

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
}

func CreateProjectModule Uses

func CreateProjectModule(cfg config.Provider) (Module, error)

CreateProjectModule creates modules from the given config. This is used in tests only.

type Modules Uses

type Modules []Module

type ModulesConfig Uses

type ModulesConfig struct {
    // All modules, including any disabled.
    AllModules Modules

    // All active modules.
    ActiveModules Modules

    // Set if this is a Go modules enabled project.
    GoModulesFilename string
}

type Mount Uses

type Mount struct {
    Source string // relative path in source repo, e.g. "scss"
    Target string // relative target path, e.g. "assets/bootstrap/scss"

    Lang string // any language code associated with this mount.
}

func (Mount) Component Uses

func (m Mount) Component() string

Package modules imports 30 packages (graph) and is imported by 29 packages. Updated 2020-04-08. Refresh now. Tools for package owners.