2018-11-08 04:24:13 -05:00
|
|
|
// Copyright 2018 The Hugo Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package filecache
|
|
|
|
|
|
|
|
import (
|
2019-10-21 03:37:46 -04:00
|
|
|
"errors"
|
2018-11-08 04:24:13 -05:00
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
2018-12-04 04:52:04 -05:00
|
|
|
"os"
|
2018-11-08 04:24:13 -05:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-09-09 15:10:28 -04:00
|
|
|
"github.com/gobwas/glob"
|
|
|
|
|
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
2019-05-03 03:16:58 -04:00
|
|
|
"github.com/gohugoio/hugo/langs"
|
|
|
|
"github.com/gohugoio/hugo/modules"
|
|
|
|
|
2018-11-08 04:24:13 -05:00
|
|
|
"github.com/gohugoio/hugo/common/hugio"
|
|
|
|
"github.com/gohugoio/hugo/config"
|
2018-11-23 03:16:42 -05:00
|
|
|
"github.com/gohugoio/hugo/helpers"
|
|
|
|
|
2018-11-08 04:24:13 -05:00
|
|
|
"github.com/gohugoio/hugo/hugofs"
|
|
|
|
"github.com/spf13/afero"
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
qt "github.com/frankban/quicktest"
|
2018-11-08 04:24:13 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestFileCache(t *testing.T) {
|
|
|
|
t.Parallel()
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
2018-11-08 04:24:13 -05:00
|
|
|
|
2018-12-04 04:52:04 -05:00
|
|
|
tempWorkingDir, err := ioutil.TempDir("", "hugo_filecache_test_work")
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
2018-12-04 04:52:04 -05:00
|
|
|
defer os.Remove(tempWorkingDir)
|
|
|
|
|
|
|
|
tempCacheDir, err := ioutil.TempDir("", "hugo_filecache_test_cache")
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
2018-12-04 04:52:04 -05:00
|
|
|
defer os.Remove(tempCacheDir)
|
|
|
|
|
|
|
|
osfs := afero.NewOsFs()
|
|
|
|
|
|
|
|
for _, test := range []struct {
|
|
|
|
cacheDir string
|
|
|
|
workingDir string
|
|
|
|
}{
|
2018-12-04 12:19:37 -05:00
|
|
|
// Run with same dirs twice to make sure that works.
|
|
|
|
{tempCacheDir, tempWorkingDir},
|
2018-12-04 04:52:04 -05:00
|
|
|
{tempCacheDir, tempWorkingDir},
|
|
|
|
} {
|
2018-11-08 04:24:13 -05:00
|
|
|
|
|
|
|
configStr := `
|
2018-12-04 04:52:04 -05:00
|
|
|
workingDir = "WORKING_DIR"
|
2018-11-14 05:53:45 -05:00
|
|
|
resourceDir = "resources"
|
2018-11-08 04:24:13 -05:00
|
|
|
cacheDir = "CACHEDIR"
|
2018-11-23 03:16:42 -05:00
|
|
|
contentDir = "content"
|
|
|
|
dataDir = "data"
|
|
|
|
i18nDir = "i18n"
|
|
|
|
layoutDir = "layouts"
|
|
|
|
assetDir = "assets"
|
|
|
|
archeTypedir = "archetypes"
|
|
|
|
|
2018-11-08 04:24:13 -05:00
|
|
|
[caches]
|
|
|
|
[caches.getJSON]
|
2018-11-14 04:51:41 -05:00
|
|
|
maxAge = "10h"
|
2018-11-08 04:24:13 -05:00
|
|
|
dir = ":cacheDir/c"
|
|
|
|
|
|
|
|
`
|
2018-12-04 04:52:04 -05:00
|
|
|
|
|
|
|
winPathSep := "\\\\"
|
|
|
|
|
|
|
|
replacer := strings.NewReplacer("CACHEDIR", test.cacheDir, "WORKING_DIR", test.workingDir)
|
|
|
|
|
|
|
|
configStr = replacer.Replace(configStr)
|
|
|
|
configStr = strings.Replace(configStr, "\\", winPathSep, -1)
|
2018-11-08 04:24:13 -05:00
|
|
|
|
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
2019-05-03 03:16:58 -04:00
|
|
|
p := newPathsSpec(t, osfs, configStr)
|
2018-11-08 04:24:13 -05:00
|
|
|
|
2018-11-23 03:16:42 -05:00
|
|
|
caches, err := NewCaches(p)
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
2018-11-08 04:24:13 -05:00
|
|
|
|
2018-12-04 04:52:04 -05:00
|
|
|
cache := caches.Get("GetJSON")
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(cache, qt.Not(qt.IsNil))
|
|
|
|
c.Assert(cache.maxAge.String(), qt.Equals, "10h0m0s")
|
2018-11-08 04:24:13 -05:00
|
|
|
|
2018-12-04 04:52:04 -05:00
|
|
|
bfs, ok := cache.Fs.(*afero.BasePathFs)
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(ok, qt.Equals, true)
|
2018-11-08 04:24:13 -05:00
|
|
|
filename, err := bfs.RealPath("key")
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
2018-12-04 04:52:04 -05:00
|
|
|
if test.cacheDir != "" {
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(filename, qt.Equals, filepath.Join(test.cacheDir, "c/"+filecacheRootDirname+"/getjson/key"))
|
2018-11-08 04:24:13 -05:00
|
|
|
} else {
|
|
|
|
// Temp dir.
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(filename, qt.Matches, ".*hugo_cache.*"+filecacheRootDirname+".*key")
|
2018-11-08 04:24:13 -05:00
|
|
|
}
|
|
|
|
|
2018-12-04 04:52:04 -05:00
|
|
|
cache = caches.Get("Images")
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(cache, qt.Not(qt.IsNil))
|
|
|
|
c.Assert(cache.maxAge, qt.Equals, time.Duration(-1))
|
2018-12-04 04:52:04 -05:00
|
|
|
bfs, ok = cache.Fs.(*afero.BasePathFs)
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(ok, qt.Equals, true)
|
2018-11-14 05:53:45 -05:00
|
|
|
filename, _ = bfs.RealPath("key")
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(filename, qt.Equals, filepath.FromSlash("_gen/images/key"))
|
2018-11-14 05:53:45 -05:00
|
|
|
|
2018-11-08 04:24:13 -05:00
|
|
|
rf := func(s string) func() (io.ReadCloser, error) {
|
|
|
|
return func() (io.ReadCloser, error) {
|
|
|
|
return struct {
|
|
|
|
io.ReadSeeker
|
|
|
|
io.Closer
|
|
|
|
}{
|
|
|
|
strings.NewReader(s),
|
|
|
|
ioutil.NopCloser(nil),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bf := func() ([]byte, error) {
|
|
|
|
return []byte("bcd"), nil
|
|
|
|
}
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
for _, ca := range []*Cache{caches.ImageCache(), caches.AssetsCache(), caches.GetJSONCache(), caches.GetCSVCache()} {
|
2018-12-04 04:52:04 -05:00
|
|
|
for i := 0; i < 2; i++ {
|
2019-08-10 15:05:17 -04:00
|
|
|
info, r, err := ca.GetOrCreate("a", rf("abc"))
|
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(r, qt.Not(qt.IsNil))
|
|
|
|
c.Assert(info.Name, qt.Equals, "a")
|
2018-12-04 04:52:04 -05:00
|
|
|
b, _ := ioutil.ReadAll(r)
|
|
|
|
r.Close()
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(string(b), qt.Equals, "abc")
|
2018-12-04 04:52:04 -05:00
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
info, b, err = ca.GetOrCreateBytes("b", bf)
|
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(r, qt.Not(qt.IsNil))
|
|
|
|
c.Assert(info.Name, qt.Equals, "b")
|
|
|
|
c.Assert(string(b), qt.Equals, "bcd")
|
2018-12-04 04:52:04 -05:00
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
_, b, err = ca.GetOrCreateBytes("a", bf)
|
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(string(b), qt.Equals, "abc")
|
2018-12-04 04:52:04 -05:00
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
_, r, err = ca.GetOrCreate("a", rf("bcd"))
|
|
|
|
c.Assert(err, qt.IsNil)
|
2018-12-04 04:52:04 -05:00
|
|
|
b, _ = ioutil.ReadAll(r)
|
|
|
|
r.Close()
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(string(b), qt.Equals, "abc")
|
2018-12-04 04:52:04 -05:00
|
|
|
}
|
2018-11-08 04:24:13 -05:00
|
|
|
}
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(caches.Get("getJSON"), qt.Not(qt.IsNil))
|
2018-11-08 04:24:13 -05:00
|
|
|
|
|
|
|
info, w, err := caches.ImageCache().WriteCloser("mykey")
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(info.Name, qt.Equals, "mykey")
|
2018-11-08 04:24:13 -05:00
|
|
|
io.WriteString(w, "Hugo is great!")
|
|
|
|
w.Close()
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(caches.ImageCache().getString("mykey"), qt.Equals, "Hugo is great!")
|
2018-11-08 04:24:13 -05:00
|
|
|
|
|
|
|
info, r, err := caches.ImageCache().Get("mykey")
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(r, qt.Not(qt.IsNil))
|
|
|
|
c.Assert(info.Name, qt.Equals, "mykey")
|
2018-11-08 04:24:13 -05:00
|
|
|
b, _ := ioutil.ReadAll(r)
|
|
|
|
r.Close()
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(string(b), qt.Equals, "Hugo is great!")
|
2018-11-08 04:24:13 -05:00
|
|
|
|
|
|
|
info, b, err = caches.ImageCache().GetBytes("mykey")
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(info.Name, qt.Equals, "mykey")
|
|
|
|
c.Assert(string(b), qt.Equals, "Hugo is great!")
|
2018-11-08 04:24:13 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFileCacheConcurrent(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
2018-11-08 04:24:13 -05:00
|
|
|
|
|
|
|
configStr := `
|
2018-11-14 05:53:45 -05:00
|
|
|
resourceDir = "myresources"
|
2018-11-23 03:16:42 -05:00
|
|
|
contentDir = "content"
|
|
|
|
dataDir = "data"
|
|
|
|
i18nDir = "i18n"
|
|
|
|
layoutDir = "layouts"
|
|
|
|
assetDir = "assets"
|
|
|
|
archeTypedir = "archetypes"
|
|
|
|
|
2018-11-08 04:24:13 -05:00
|
|
|
[caches]
|
|
|
|
[caches.getjson]
|
2018-11-14 04:51:41 -05:00
|
|
|
maxAge = "1s"
|
2018-11-08 04:24:13 -05:00
|
|
|
dir = "/cache/c"
|
|
|
|
|
|
|
|
`
|
|
|
|
|
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
2019-05-03 03:16:58 -04:00
|
|
|
p := newPathsSpec(t, afero.NewMemMapFs(), configStr)
|
2018-11-08 04:24:13 -05:00
|
|
|
|
2018-11-23 03:16:42 -05:00
|
|
|
caches, err := NewCaches(p)
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
2018-11-08 04:24:13 -05:00
|
|
|
|
|
|
|
const cacheName = "getjson"
|
|
|
|
|
|
|
|
filenameData := func(i int) (string, string) {
|
|
|
|
data := fmt.Sprintf("data: %d", i)
|
|
|
|
filename := fmt.Sprintf("file%d", i)
|
|
|
|
return filename, data
|
|
|
|
}
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
for i := 0; i < 50; i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func(i int) {
|
|
|
|
defer wg.Done()
|
|
|
|
for j := 0; j < 20; j++ {
|
2019-08-10 15:05:17 -04:00
|
|
|
ca := caches.Get(cacheName)
|
|
|
|
c.Assert(ca, qt.Not(qt.IsNil))
|
2018-11-08 04:24:13 -05:00
|
|
|
filename, data := filenameData(i)
|
2019-08-10 15:05:17 -04:00
|
|
|
_, r, err := ca.GetOrCreate(filename, func() (io.ReadCloser, error) {
|
2018-11-08 04:24:13 -05:00
|
|
|
return hugio.ToReadCloser(strings.NewReader(data)), nil
|
|
|
|
})
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
2018-11-08 04:24:13 -05:00
|
|
|
b, _ := ioutil.ReadAll(r)
|
|
|
|
r.Close()
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(string(b), qt.Equals, data)
|
2018-11-08 04:24:13 -05:00
|
|
|
// Trigger some expiration.
|
|
|
|
time.Sleep(50 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}(i)
|
|
|
|
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
}
|
2018-11-14 06:06:46 -05:00
|
|
|
|
2019-10-21 03:37:46 -04:00
|
|
|
func TestFileCacheReadOrCreateErrorInRead(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
c := qt.New(t)
|
|
|
|
|
|
|
|
var result string
|
|
|
|
|
2019-11-25 06:49:04 -05:00
|
|
|
rf := func(failLevel int) func(info ItemInfo, r io.ReadSeeker) error {
|
2019-10-21 03:37:46 -04:00
|
|
|
|
2019-11-25 06:49:04 -05:00
|
|
|
return func(info ItemInfo, r io.ReadSeeker) error {
|
2019-10-21 03:37:46 -04:00
|
|
|
if failLevel > 0 {
|
|
|
|
if failLevel > 1 {
|
|
|
|
return ErrFatal
|
|
|
|
}
|
|
|
|
return errors.New("fail")
|
|
|
|
}
|
|
|
|
|
|
|
|
b, _ := ioutil.ReadAll(r)
|
|
|
|
result = string(b)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bf := func(s string) func(info ItemInfo, w io.WriteCloser) error {
|
|
|
|
return func(info ItemInfo, w io.WriteCloser) error {
|
|
|
|
defer w.Close()
|
|
|
|
result = s
|
|
|
|
_, err := w.Write([]byte(s))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cache := NewCache(afero.NewMemMapFs(), 100*time.Hour, "")
|
|
|
|
|
|
|
|
const id = "a32"
|
|
|
|
|
|
|
|
_, err := cache.ReadOrCreate(id, rf(0), bf("v1"))
|
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(result, qt.Equals, "v1")
|
|
|
|
_, err = cache.ReadOrCreate(id, rf(0), bf("v2"))
|
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(result, qt.Equals, "v1")
|
|
|
|
_, err = cache.ReadOrCreate(id, rf(1), bf("v3"))
|
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(result, qt.Equals, "v3")
|
|
|
|
_, err = cache.ReadOrCreate(id, rf(2), bf("v3"))
|
|
|
|
c.Assert(err, qt.Equals, ErrFatal)
|
|
|
|
}
|
|
|
|
|
2018-11-14 06:06:46 -05:00
|
|
|
func TestCleanID(t *testing.T) {
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
|
|
|
c.Assert(cleanID(filepath.FromSlash("/a/b//c.txt")), qt.Equals, filepath.FromSlash("a/b/c.txt"))
|
|
|
|
c.Assert(cleanID(filepath.FromSlash("a/b//c.txt")), qt.Equals, filepath.FromSlash("a/b/c.txt"))
|
2018-11-14 06:06:46 -05:00
|
|
|
}
|
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
2019-05-03 03:16:58 -04:00
|
|
|
|
|
|
|
func initConfig(fs afero.Fs, cfg config.Provider) error {
|
|
|
|
if _, err := langs.LoadLanguageSettings(cfg, nil); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
modConfig, err := modules.DecodeConfig(cfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
workingDir := cfg.GetString("workingDir")
|
|
|
|
themesDir := cfg.GetString("themesDir")
|
|
|
|
if !filepath.IsAbs(themesDir) {
|
|
|
|
themesDir = filepath.Join(workingDir, themesDir)
|
|
|
|
}
|
2020-09-09 15:10:28 -04:00
|
|
|
globAll := glob.MustCompile("**", '/')
|
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
2019-05-03 03:16:58 -04:00
|
|
|
modulesClient := modules.NewClient(modules.ClientConfig{
|
|
|
|
Fs: fs,
|
|
|
|
WorkingDir: workingDir,
|
|
|
|
ThemesDir: themesDir,
|
|
|
|
ModuleConfig: modConfig,
|
2020-09-09 15:10:28 -04:00
|
|
|
IgnoreVendor: globAll,
|
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
2019-05-03 03:16:58 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
moduleConfig, err := modulesClient.Collect()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := modules.ApplyProjectConfigDefaults(cfg, moduleConfig.ActiveModules[len(moduleConfig.ActiveModules)-1]); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.Set("allModules", moduleConfig.ActiveModules)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func newPathsSpec(t *testing.T, fs afero.Fs, configStr string) *helpers.PathSpec {
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
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
2019-05-03 03:16:58 -04:00
|
|
|
cfg, err := config.FromConfigString(configStr, "toml")
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
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
2019-05-03 03:16:58 -04:00
|
|
|
initConfig(fs, cfg)
|
2019-07-24 18:12:40 -04:00
|
|
|
p, err := helpers.NewPathSpec(hugofs.NewFrom(fs, cfg), cfg, nil)
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
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
2019-05-03 03:16:58 -04:00
|
|
|
return p
|
|
|
|
|
|
|
|
}
|