1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-30 06:48:59 +01:00
This commit is contained in:
Oliver Steele 2017-07-25 09:48:49 -04:00
parent 418284d6de
commit de57141230
4 changed files with 29 additions and 20 deletions

View File

@ -80,8 +80,8 @@ func loadSite(source string, flags config.Flags) (*site.Site, error) {
return nil, err
}
const configurationFileLabel = "Configuration file:"
if site.ConfigFile != nil {
logger.path(configurationFileLabel, *site.ConfigFile)
if cf := site.Config().ConfigFile; cf != "" {
logger.path(configurationFileLabel, cf)
} else {
logger.label(configurationFileLabel, "none")
}

View File

@ -1,6 +1,8 @@
package config
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -64,14 +66,35 @@ type Config struct {
ForcePolling bool `yaml:"-"`
Watch bool `yaml:"-"`
// Unstructured data for templates
Variables map[string]interface{} `yaml:"-"`
// Meta
ConfigFile string `yaml:"-"`
Variables map[string]interface{} `yaml:"-"`
// Plugins
RequireFrontMatter bool `yaml:"-"`
RequireFrontMatterExclude map[string]bool `yaml:"-"`
}
// FromDirectory updates the config from the config file in
// the directory, if such a file exists.
func (c *Config) FromDirectory(dir string) error {
path := filepath.Join(dir, "_config.yml")
bytes, err := ioutil.ReadFile(path)
switch {
case os.IsNotExist(err):
// break
case err != nil:
return err
default:
if err = Unmarshal(bytes, c); err != nil {
return utils.WrapPathError(err, path)
}
c.ConfigFile = path
}
c.Source = dir
return nil
}
type configCompat struct {
Gems []string
}

View File

@ -1,7 +1,6 @@
package site
import (
"io/ioutil"
"os"
"path/filepath"
@ -13,23 +12,11 @@ import (
)
// FromDirectory reads the configuration file, if it exists.
func FromDirectory(source string, flags config.Flags) (*Site, error) {
func FromDirectory(dir string, flags config.Flags) (*Site, error) {
s := New(flags)
configPath := filepath.Join(source, "_config.yml")
bytes, err := ioutil.ReadFile(configPath)
switch {
case err != nil && os.IsNotExist(err):
// ok
case err != nil:
if err := s.config.FromDirectory(dir); err != nil {
return nil, err
default:
err = config.Unmarshal(bytes, &s.config)
if err != nil {
return nil, utils.WrapPathError(err, configPath)
}
s.ConfigFile = &configPath
}
s.config.Source = source
s.config.ApplyFlags(s.flags)
return s, nil
}

View File

@ -17,7 +17,6 @@ import (
// Site is a Jekyll site.
type Site struct {
ConfigFile *string
Collections []*collection.Collection
Routes map[string]pages.Document // URL path -> Document, only for output pages