mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-30 10:19:03 +01:00
config.collections can be a list
This commit is contained in:
parent
3fb43c65ab
commit
16422716c3
@ -14,10 +14,10 @@ type Config struct {
|
||||
// Where things are:
|
||||
Source string
|
||||
Destination string
|
||||
LayoutsDir string `yaml:"layouts_dir"`
|
||||
DataDir string `yaml:"data_dir"`
|
||||
IncludesDir string `yaml:"includes_dir"`
|
||||
Collections map[string]map[string]interface{}
|
||||
LayoutsDir string `yaml:"layouts_dir"`
|
||||
DataDir string `yaml:"data_dir"`
|
||||
IncludesDir string `yaml:"includes_dir"`
|
||||
Collections map[string]map[string]interface{} `yaml:"-"`
|
||||
|
||||
// Handling Reading
|
||||
Include []string
|
||||
@ -58,6 +58,14 @@ type configCompat struct {
|
||||
Gems []string
|
||||
}
|
||||
|
||||
type collectionsList struct {
|
||||
Collections []string
|
||||
}
|
||||
|
||||
type collectionsMap struct {
|
||||
Collections map[string]map[string]interface{}
|
||||
}
|
||||
|
||||
// SourceDir returns the source directory as an absolute path.
|
||||
func (c *Config) SourceDir() string {
|
||||
return helpers.MustAbs(c.Source)
|
||||
@ -78,13 +86,29 @@ func (c *Config) GetFrontMatterDefaults(typename, relpath string) (m map[string]
|
||||
|
||||
// Unmarshal updates site from a YAML configuration file.
|
||||
func Unmarshal(bytes []byte, c *Config) error {
|
||||
compat := configCompat{}
|
||||
var (
|
||||
compat configCompat
|
||||
cList collectionsList
|
||||
// cMap collectionsMap
|
||||
)
|
||||
if err := yaml.Unmarshal(bytes, &c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := yaml.Unmarshal(bytes, &c.Variables); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := yaml.Unmarshal(bytes, &cList); err == nil {
|
||||
if len(c.Collections) == 0 {
|
||||
c.Collections = make(map[string]map[string]interface{})
|
||||
}
|
||||
for _, name := range cList.Collections {
|
||||
c.Collections[name] = map[string]interface{}{}
|
||||
}
|
||||
}
|
||||
cMap := collectionsMap{c.Collections}
|
||||
if err := yaml.Unmarshal(bytes, &cMap); err == nil {
|
||||
c.Collections = cMap.Collections
|
||||
}
|
||||
if err := yaml.Unmarshal(bytes, &compat); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSourceDir(t *testing.T) {
|
||||
func TestConfig_SourceDir(t *testing.T) {
|
||||
c := Default()
|
||||
require.True(t, strings.HasPrefix(c.SourceDir(), "/"))
|
||||
}
|
||||
@ -18,7 +19,7 @@ func TestDefaultConfig(t *testing.T) {
|
||||
require.Equal(t, "_layouts", c.LayoutsDir)
|
||||
}
|
||||
|
||||
func TestPlugins(t *testing.T) {
|
||||
func TestConfig_Plugins(t *testing.T) {
|
||||
c := Default()
|
||||
require.NoError(t, Unmarshal([]byte(`plugins: ['a']`), &c))
|
||||
require.Equal(t, []string{"a"}, c.Plugins)
|
||||
@ -30,13 +31,16 @@ func TestPlugins(t *testing.T) {
|
||||
|
||||
func TestUnmarshal(t *testing.T) {
|
||||
c := Default()
|
||||
err := Unmarshal([]byte(`source: x`), &c)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, Unmarshal([]byte(`source: x`), &c))
|
||||
require.Equal(t, "x", c.Source)
|
||||
require.Equal(t, "./_site", c.Destination)
|
||||
|
||||
c = Default()
|
||||
require.NoError(t, Unmarshal([]byte(`collections: \n- x\n-y`), &c))
|
||||
fmt.Println(c.Collections)
|
||||
}
|
||||
|
||||
func TestIsMarkdown(t *testing.T) {
|
||||
func TestConfig_IsMarkdown(t *testing.T) {
|
||||
c := Default()
|
||||
require.True(t, c.IsMarkdown("name.md"))
|
||||
require.True(t, c.IsMarkdown("name.markdown"))
|
||||
|
Loading…
Reference in New Issue
Block a user