summaryrefslogtreecommitdiffstats
path: root/hugolib/paths/paths.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-05-03 09:16:58 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-07-24 09:35:53 +0200
commit9f5a92078a3f388b52d597b5a59af5c933a112d2 (patch)
tree0b2b07e5b3a3f21877bc5585a4bdd76306a09dde /hugolib/paths/paths.go
parent47953148b6121441d0147c960a99829c53b5a5ba (diff)
Add Hugo Modules
This commit implements Hugo Modules. This is a broad subject, but some keywords include: * A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project. * A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects. * Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running. * Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions. * A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`. All of the above is backed by Go Modules. Fixes #5973 Fixes #5996 Fixes #6010 Fixes #5911 Fixes #5940 Fixes #6074 Fixes #6082 Fixes #6092
Diffstat (limited to 'hugolib/paths/paths.go')
-rw-r--r--hugolib/paths/paths.go66
1 files changed, 34 insertions, 32 deletions
diff --git a/hugolib/paths/paths.go b/hugolib/paths/paths.go
index df66e2a46..97d4f17ba 100644
--- a/hugolib/paths/paths.go
+++ b/hugolib/paths/paths.go
@@ -20,6 +20,7 @@ import (
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/langs"
+ "github.com/gohugoio/hugo/modules"
"github.com/pkg/errors"
"github.com/gohugoio/hugo/hugofs"
@@ -39,7 +40,6 @@ type Paths struct {
// Directories
// TODO(bep) when we have trimmed down mos of the dirs usage outside of this package, make
// these into an interface.
- ContentDir string
ThemesDir string
WorkingDir string
@@ -62,8 +62,9 @@ type Paths struct {
UglyURLs bool
CanonifyURLs bool
- Language *langs.Language
- Languages langs.Languages
+ Language *langs.Language
+ Languages langs.Languages
+ LanguagesDefaultFirst langs.Languages
// The PathSpec looks up its config settings in both the current language
// and then in the global Viper config.
@@ -74,8 +75,8 @@ type Paths struct {
DefaultContentLanguage string
multilingual bool
- themes []string
- AllThemes []ThemeConfig
+ AllModules modules.Modules
+ ModulesClient *modules.Client
}
func New(fs *hugofs.Fs, cfg config.Provider) (*Paths, error) {
@@ -91,12 +92,6 @@ func New(fs *hugofs.Fs, cfg config.Provider) (*Paths, error) {
resourceDir := filepath.Clean(cfg.GetString("resourceDir"))
publishDir := filepath.Clean(cfg.GetString("publishDir"))
- if contentDir == "" {
- return nil, fmt.Errorf("contentDir not set")
- }
- if resourceDir == "" {
- return nil, fmt.Errorf("resourceDir not set")
- }
if publishDir == "" {
return nil, fmt.Errorf("publishDir not set")
}
@@ -104,8 +99,9 @@ func New(fs *hugofs.Fs, cfg config.Provider) (*Paths, error) {
defaultContentLanguage := cfg.GetString("defaultContentLanguage")
var (
- language *langs.Language
- languages langs.Languages
+ language *langs.Language
+ languages langs.Languages
+ languagesDefaultFirst langs.Languages
)
if l, ok := cfg.(*langs.Language); ok {
@@ -117,6 +113,12 @@ func New(fs *hugofs.Fs, cfg config.Provider) (*Paths, error) {
languages = l
}
+ if l, ok := cfg.Get("languagesSortedDefaultFirst").(langs.Languages); ok {
+ languagesDefaultFirst = l
+ }
+
+ //
+
if len(languages) == 0 {
// We have some old tests that does not test the entire chain, hence
// they have no languages. So create one so we get the proper filesystem.
@@ -156,33 +158,30 @@ func New(fs *hugofs.Fs, cfg config.Provider) (*Paths, error) {
UglyURLs: cfg.GetBool("uglyURLs"),
CanonifyURLs: cfg.GetBool("canonifyURLs"),
- ContentDir: contentDir,
ThemesDir: cfg.GetString("themesDir"),
WorkingDir: workingDir,
AbsResourcesDir: absResourcesDir,
AbsPublishDir: absPublishDir,
- themes: config.GetStringSlicePreserveString(cfg, "theme"),
-
multilingual: cfg.GetBool("multilingual"),
defaultContentLanguageInSubdir: cfg.GetBool("defaultContentLanguageInSubdir"),
DefaultContentLanguage: defaultContentLanguage,
Language: language,
Languages: languages,
+ LanguagesDefaultFirst: languagesDefaultFirst,
MultihostTargetBasePaths: multihostTargetBasePaths,
PaginatePath: cfg.GetString("paginatePath"),
}
- if !cfg.IsSet("theme") && cfg.IsSet("allThemes") {
- p.AllThemes = cfg.Get("allThemes").([]ThemeConfig)
- } else {
- p.AllThemes, err = collectThemeNames(p)
- if err != nil {
- return nil, err
- }
+ if cfg.IsSet("allModules") {
+ p.AllModules = cfg.Get("allModules").(modules.Modules)
+ }
+
+ if cfg.IsSet("modulesClient") {
+ p.ModulesClient = cfg.Get("modulesClient").(*modules.Client)
}
// TODO(bep) remove this, eventually
@@ -207,15 +206,6 @@ func (p *Paths) Lang() string {
return p.Language.Lang
}
-// ThemeSet checks whether a theme is in use or not.
-func (p *Paths) ThemeSet() bool {
- return len(p.themes) > 0
-}
-
-func (p *Paths) Themes() []string {
- return p.themes
-}
-
func (p *Paths) GetTargetLanguageBasePath() string {
if p.Languages.IsMultihost() {
// In a multihost configuration all assets will be published below the language code.
@@ -269,6 +259,18 @@ func (p *Paths) AbsPathify(inPath string) string {
return AbsPathify(p.WorkingDir, inPath)
}
+// RelPathify trims any WorkingDir prefix from the given filename. If
+// the filename is not considered to be absolute, the path is just cleaned.
+func (p *Paths) RelPathify(filename string) string {
+ filename = filepath.Clean(filename)
+ if !filepath.IsAbs(filename) {
+ return filename
+ }
+
+ return strings.TrimPrefix(strings.TrimPrefix(filename, p.WorkingDir), FilePathSeparator)
+
+}
+
// AbsPathify creates an absolute path if given a working dir and arelative path.
// If already absolute, the path is just cleaned.
func AbsPathify(workingDir, inPath string) string {