mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-30 06:48:59 +01:00
Refactor
This commit is contained in:
parent
418284d6de
commit
de57141230
@ -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")
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
17
site/read.go
17
site/read.go
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user