2017-06-22 21:21:47 +02:00
|
|
|
package config
|
2017-06-17 03:53:14 +02:00
|
|
|
|
2017-06-22 16:42:57 +02:00
|
|
|
import (
|
2017-06-22 21:21:47 +02:00
|
|
|
"strings"
|
|
|
|
|
2017-06-22 16:42:57 +02:00
|
|
|
"github.com/osteele/gojekyll/templates"
|
|
|
|
yaml "gopkg.in/yaml.v2"
|
|
|
|
)
|
2017-06-17 03:53:14 +02:00
|
|
|
|
2017-06-22 21:21:47 +02:00
|
|
|
// Config is the Jekyll site configuration, typically read from _config.yml.
|
2017-06-17 03:53:14 +02:00
|
|
|
// See https://jekyllrb.com/docs/configuration/#default-configuration
|
2017-06-22 21:21:47 +02:00
|
|
|
type Config struct {
|
2017-06-17 03:53:14 +02:00
|
|
|
// Where things are:
|
|
|
|
Source string
|
|
|
|
Destination string
|
|
|
|
LayoutsDir string `yaml:"layouts_dir"`
|
2017-06-22 16:42:57 +02:00
|
|
|
DataDir string `yaml:"data_dir"`
|
2017-06-17 05:36:27 +02:00
|
|
|
IncludesDir string `yaml:"includes_dir"`
|
2017-07-01 05:56:29 +02:00
|
|
|
Collections map[string]map[string]interface{}
|
2017-06-17 03:53:14 +02:00
|
|
|
|
|
|
|
// Handling Reading
|
|
|
|
Include []string
|
|
|
|
Exclude []string
|
2017-07-02 01:42:48 +02:00
|
|
|
KeepFiles []string `yaml:"keep_files"`
|
|
|
|
MarkdownExt string `yaml:"markdown_ext"`
|
|
|
|
|
|
|
|
// Filtering Content
|
|
|
|
Drafts bool `yaml:"show_drafts"`
|
|
|
|
Future bool
|
|
|
|
Unpublished bool
|
2017-06-17 03:53:14 +02:00
|
|
|
|
2017-06-30 18:53:34 +02:00
|
|
|
// Plugins
|
2017-07-02 01:42:48 +02:00
|
|
|
Plugins []string
|
|
|
|
Gems []string // bwcompat
|
2017-06-30 18:53:34 +02:00
|
|
|
|
2017-06-28 22:55:15 +02:00
|
|
|
// Serving
|
|
|
|
AbsoluteURL string `yaml:"url"`
|
|
|
|
BaseURL string
|
|
|
|
|
2017-06-17 03:53:14 +02:00
|
|
|
// Outputting
|
2017-07-02 01:42:48 +02:00
|
|
|
Permalink string
|
2017-06-17 05:30:10 +02:00
|
|
|
|
|
|
|
Defaults []struct {
|
|
|
|
Scope struct {
|
|
|
|
Path string
|
|
|
|
Type string
|
|
|
|
}
|
2017-07-01 05:56:29 +02:00
|
|
|
Values map[string]interface{}
|
2017-06-17 05:30:10 +02:00
|
|
|
}
|
2017-06-22 21:21:47 +02:00
|
|
|
|
2017-07-01 05:56:29 +02:00
|
|
|
Variables map[string]interface{} `yaml:"-"`
|
2017-06-22 21:21:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Default returns a default site configuration.
|
|
|
|
// This is a function instead of a global variable, and returns a new value each time,
|
|
|
|
// since the caller may overwrite it.
|
|
|
|
func Default() Config {
|
|
|
|
var c Config
|
|
|
|
err := Unmarshal([]byte(defaultSiteConfig), &c)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return c
|
2017-06-17 03:53:14 +02:00
|
|
|
}
|
|
|
|
|
2017-06-22 21:21:47 +02:00
|
|
|
// Unmarshal reads a YAML configuration.
|
|
|
|
func Unmarshal(bytes []byte, c *Config) error {
|
|
|
|
if err := yaml.Unmarshal(bytes, &c); err != nil {
|
2017-06-17 03:53:14 +02:00
|
|
|
return err
|
|
|
|
}
|
2017-06-22 21:21:47 +02:00
|
|
|
if err := yaml.Unmarshal(bytes, &c.Variables); err != nil {
|
2017-06-17 03:53:14 +02:00
|
|
|
return err
|
|
|
|
}
|
2017-07-02 01:42:48 +02:00
|
|
|
if len(c.Gems) > 0 {
|
|
|
|
c.Plugins = c.Gems
|
|
|
|
}
|
2017-06-17 03:53:14 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-06-22 21:21:47 +02:00
|
|
|
// GetFrontMatterDefaults implements https://jekyllrb.com/docs/configuration/#front-matter-defaults
|
2017-07-01 05:56:29 +02:00
|
|
|
func (c *Config) GetFrontMatterDefaults(relpath, typename string) (m map[string]interface{}) {
|
2017-06-22 21:21:47 +02:00
|
|
|
for _, entry := range c.Defaults {
|
|
|
|
scope := &entry.Scope
|
|
|
|
hasPrefix := strings.HasPrefix(relpath, scope.Path)
|
|
|
|
hasType := scope.Type == "" || scope.Type == typename
|
|
|
|
if hasPrefix && hasType {
|
|
|
|
m = templates.MergeVariableMaps(m, entry.Values)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-06-17 03:53:14 +02:00
|
|
|
// From https://jekyllrb.com/docs/configuration/#default-configuration
|
2017-06-30 18:53:34 +02:00
|
|
|
// The following includes only those keys that are currently implemented.
|
2017-06-17 03:53:14 +02:00
|
|
|
const defaultSiteConfig = `
|
|
|
|
# Where things are
|
|
|
|
source: .
|
|
|
|
destination: ./_site
|
|
|
|
layouts_dir: _layouts
|
|
|
|
data_dir: _data
|
|
|
|
includes_dir: _includes
|
|
|
|
collections:
|
|
|
|
posts:
|
|
|
|
output: true
|
|
|
|
|
|
|
|
# Handling Reading
|
|
|
|
include: [".htaccess"]
|
|
|
|
exclude: ["Gemfile", "Gemfile.lock", "node_modules", "vendor/bundle/", "vendor/cache/", "vendor/gems/", "vendor/ruby/"]
|
|
|
|
keep_files: [".git", ".svn"]
|
|
|
|
encoding: "utf-8"
|
|
|
|
markdown_ext: "markdown,mkdown,mkdn,mkd,md"
|
|
|
|
strict_front_matter: false
|
|
|
|
|
2017-06-30 18:53:34 +02:00
|
|
|
# Plugins
|
|
|
|
plugins: []
|
|
|
|
|
2017-06-17 03:53:14 +02:00
|
|
|
# Outputting
|
|
|
|
permalink: date
|
|
|
|
paginate_path: /page:num
|
|
|
|
timezone: null
|
2017-06-28 22:55:15 +02:00
|
|
|
`
|