mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-26 23:34:47 +01:00
Name changes
This commit is contained in:
parent
c6423be20f
commit
ad5c5ffddf
@ -13,7 +13,7 @@ import (
|
||||
func (s *Site) Clean() error {
|
||||
// TODO PERF when called as part of build, keep files that will be re-generated
|
||||
removeFiles := func(filename string, info os.FileInfo, err error) error {
|
||||
if s.config.Verbose {
|
||||
if s.cfg.Verbose {
|
||||
fmt.Println("rm", filename)
|
||||
}
|
||||
switch {
|
||||
@ -25,7 +25,7 @@ func (s *Site) Clean() error {
|
||||
return nil
|
||||
case s.KeepFile(utils.MustRel(s.DestDir(), filename)):
|
||||
return nil
|
||||
case s.config.DryRun:
|
||||
case s.cfg.DryRun:
|
||||
return nil
|
||||
default:
|
||||
// empirically, moving the os.Remove into a goroutine has no performance benefit
|
||||
@ -39,7 +39,7 @@ func (s *Site) Clean() error {
|
||||
}
|
||||
|
||||
func (s *Site) setTimeZone() error {
|
||||
if tz := s.config.Timezone; tz != "" {
|
||||
if tz := s.cfg.Timezone; tz != "" {
|
||||
if _, err := time.LoadLocation(tz); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s; using local time zone\n", err)
|
||||
} else if err := os.Setenv("TZ", tz); err != nil {
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
|
||||
func (s *Site) readDataFiles() error {
|
||||
s.data = map[string]interface{}{}
|
||||
dataDir := filepath.Join(s.SourceDir(), s.config.DataDir)
|
||||
dataDir := filepath.Join(s.SourceDir(), s.cfg.DataDir)
|
||||
files, err := ioutil.ReadDir(dataDir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
|
@ -17,9 +17,9 @@ func (s *Site) Exclude(siteRel string) bool {
|
||||
for siteRel != "." {
|
||||
dir, base := filepath.Dir(siteRel), filepath.Base(siteRel)
|
||||
switch {
|
||||
case utils.MatchList(s.config.Include, siteRel):
|
||||
case utils.MatchList(s.cfg.Include, siteRel):
|
||||
return false
|
||||
case utils.MatchList(s.config.Exclude, siteRel):
|
||||
case utils.MatchList(s.cfg.Exclude, siteRel):
|
||||
return true
|
||||
case dir != "." && base[0] == '_':
|
||||
return true
|
||||
@ -44,19 +44,19 @@ func (s *Site) Exclude(siteRel string) bool {
|
||||
func (s *Site) RequiresFullReload(paths []string) bool {
|
||||
for _, path := range paths {
|
||||
switch {
|
||||
case s.config.IsConfigPath(path):
|
||||
case s.cfg.IsConfigPath(path):
|
||||
return true
|
||||
case s.Exclude(path):
|
||||
continue
|
||||
case !s.config.Incremental:
|
||||
case !s.cfg.Incremental:
|
||||
return true
|
||||
case strings.HasPrefix(path, s.config.DataDir):
|
||||
case strings.HasPrefix(path, s.cfg.DataDir):
|
||||
return true
|
||||
case strings.HasPrefix(path, s.config.IncludesDir):
|
||||
case strings.HasPrefix(path, s.cfg.IncludesDir):
|
||||
return true
|
||||
case strings.HasPrefix(path, s.config.LayoutsDir):
|
||||
case strings.HasPrefix(path, s.cfg.LayoutsDir):
|
||||
return true
|
||||
case strings.HasPrefix(path, s.config.SassDir()):
|
||||
case strings.HasPrefix(path, s.cfg.SassDir()):
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -74,7 +74,7 @@ func (s *Site) affectsBuildFilter(paths []string) []string {
|
||||
loop:
|
||||
for _, path := range paths {
|
||||
switch {
|
||||
case s.config.IsConfigPath(path):
|
||||
case s.cfg.IsConfigPath(path):
|
||||
// break
|
||||
case !s.fileAffectsBuild(path):
|
||||
continue loop
|
||||
@ -94,9 +94,9 @@ func (s *Site) fileAffectsBuild(rel string) bool {
|
||||
switch {
|
||||
case rel == ".":
|
||||
return true
|
||||
case utils.MatchList(s.config.Include, rel):
|
||||
case utils.MatchList(s.cfg.Include, rel):
|
||||
return true
|
||||
case utils.MatchList(s.config.Exclude, rel):
|
||||
case utils.MatchList(s.cfg.Exclude, rel):
|
||||
return false
|
||||
case strings.HasPrefix(rel, "."):
|
||||
return false
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
|
||||
func TestSite_Reloaded(t *testing.T) {
|
||||
s0 := New(config.Flags{})
|
||||
s0.config.Incremental = true
|
||||
s0.cfg.Incremental = true
|
||||
s1, _ := s0.Reloaded([]string{})
|
||||
require.Equal(t, s0, s1)
|
||||
|
||||
@ -30,7 +30,7 @@ func TestSite_RequiresFullReload(t *testing.T) {
|
||||
// require.False(t, s.RequiresFullReload([]string{"_site"}))
|
||||
// require.False(t, s.RequiresFullReload([]string{"_site/index.html"}))
|
||||
|
||||
s.config.Incremental = true
|
||||
s.cfg.Incremental = true
|
||||
require.False(t, s.RequiresFullReload([]string{}))
|
||||
require.False(t, s.RequiresFullReload([]string{"file.md"}))
|
||||
require.True(t, s.RequiresFullReload([]string{"_config.yml"}))
|
||||
|
@ -25,7 +25,7 @@ func (s *Site) initializeDrop() error {
|
||||
for _, c := range s.Collections {
|
||||
docs = append(docs, c.Pages()...)
|
||||
}
|
||||
drop := templates.MergeVariableMaps(s.config.Variables(), map[string]interface{}{
|
||||
drop := templates.MergeVariableMaps(s.cfg.Variables(), map[string]interface{}{
|
||||
"collections": s.collectionDrops(),
|
||||
"data": s.data,
|
||||
"documents": docs,
|
||||
|
12
site/read.go
12
site/read.go
@ -16,17 +16,17 @@ import (
|
||||
// FromDirectory reads the configuration file, if it exists.
|
||||
func FromDirectory(dir string, flags config.Flags) (*Site, error) {
|
||||
s := New(flags)
|
||||
if err := s.config.FromDirectory(dir); err != nil {
|
||||
if err := s.cfg.FromDirectory(dir); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.config.ApplyFlags(s.flags)
|
||||
s.cfg.ApplyFlags(s.flags)
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Read loads the site data and files.
|
||||
func (s *Site) Read() error {
|
||||
s.Routes = make(map[string]pages.Document)
|
||||
plugins.Install(s.config.Plugins, s)
|
||||
plugins.Install(s.cfg.Plugins, s)
|
||||
if err := s.findTheme(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -65,7 +65,7 @@ func (s *Site) readFiles(dir, base string) error {
|
||||
case strings.HasPrefix(rel, "_"):
|
||||
return nil
|
||||
}
|
||||
defaultFrontmatter := s.config.GetFrontMatterDefaults("", rel)
|
||||
defaultFrontmatter := s.cfg.GetFrontMatterDefaults("", rel)
|
||||
d, err := pages.NewFile(s, filename, filepath.ToSlash(rel), defaultFrontmatter)
|
||||
if err != nil {
|
||||
return utils.WrapPathError(err, filename)
|
||||
@ -81,7 +81,7 @@ func (s *Site) readFiles(dir, base string) error {
|
||||
// AddDocument adds a document to the site's fields.
|
||||
// It ignores unpublished documents unless config.Unpublished is true.
|
||||
func (s *Site) AddDocument(d pages.Document, output bool) {
|
||||
if d.Published() || s.config.Unpublished {
|
||||
if d.Published() || s.cfg.Unpublished {
|
||||
s.docs = append(s.docs, d)
|
||||
if output {
|
||||
s.Routes[d.Permalink()] = d
|
||||
@ -93,7 +93,7 @@ func (s *Site) AddDocument(d pages.Document, output bool) {
|
||||
// It adds each collection's pages to the site map, and creates a template site variable for each collection.
|
||||
func (s *Site) ReadCollections() (err error) {
|
||||
var cols []*collection.Collection
|
||||
for name, data := range s.config.Collections {
|
||||
for name, data := range s.cfg.Collections {
|
||||
c := collection.New(s, name, data)
|
||||
cols = append(cols, c)
|
||||
err = c.ReadPages()
|
||||
|
36
site/site.go
36
site/site.go
@ -17,12 +17,12 @@ import (
|
||||
// Site is a Jekyll site.
|
||||
type Site struct {
|
||||
Collections []*collection.Collection
|
||||
Routes map[string]pages.Document // URL path -> Document, only for output pages
|
||||
Routes map[string]pages.Document // URL path -> Document; only for output pages
|
||||
|
||||
config config.Config
|
||||
data map[string]interface{}
|
||||
flags config.Flags
|
||||
themeDir string
|
||||
cfg config.Config
|
||||
data map[string]interface{} // from _data files
|
||||
flags config.Flags // command-line flags, override config files
|
||||
themeDir string // absolute path to theme directory
|
||||
|
||||
docs []pages.Document // all documents, whether or not they are output
|
||||
nonCollectionPages []pages.Page
|
||||
@ -35,14 +35,14 @@ type Site struct {
|
||||
}
|
||||
|
||||
// SourceDir returns the site source directory.
|
||||
func (s *Site) SourceDir() string { return s.config.Source }
|
||||
func (s *Site) SourceDir() string { return s.cfg.Source }
|
||||
|
||||
// DestDir returns the site destination directory.
|
||||
func (s *Site) DestDir() string {
|
||||
if filepath.IsAbs(s.config.Destination) {
|
||||
return s.config.Destination
|
||||
if filepath.IsAbs(s.cfg.Destination) {
|
||||
return s.cfg.Destination
|
||||
}
|
||||
return filepath.Join(s.config.Source, s.config.Destination)
|
||||
return filepath.Join(s.cfg.Source, s.cfg.Destination)
|
||||
}
|
||||
|
||||
// OutputDocs returns a list of output pages.
|
||||
@ -75,11 +75,11 @@ func (s *Site) AbsDir() string {
|
||||
|
||||
// Config is in the collection.Site interface.
|
||||
func (s *Site) Config() *config.Config {
|
||||
return &s.config
|
||||
return &s.cfg
|
||||
}
|
||||
|
||||
func (s *Site) runHooks(h func(plugins.Plugin) error) error {
|
||||
for _, name := range s.config.Plugins {
|
||||
for _, name := range s.cfg.Plugins {
|
||||
p, ok := plugins.Lookup(name)
|
||||
if ok {
|
||||
if err := h(p); err != nil {
|
||||
@ -100,16 +100,16 @@ func (s *Site) PathPrefix() string { return "" }
|
||||
|
||||
// New creates a new site record, initialized with the site defaults.
|
||||
func New(flags config.Flags) *Site {
|
||||
s := &Site{config: config.Default(), flags: flags}
|
||||
s.config.ApplyFlags(flags)
|
||||
s := &Site{cfg: config.Default(), flags: flags}
|
||||
s.cfg.ApplyFlags(flags)
|
||||
return s
|
||||
}
|
||||
|
||||
// SetAbsoluteURL overrides the loaded configuration.
|
||||
// The server uses this.
|
||||
func (s *Site) SetAbsoluteURL(url string) {
|
||||
s.config.AbsoluteURL = url
|
||||
s.config.Set("url", url)
|
||||
s.cfg.AbsoluteURL = url
|
||||
s.cfg.Set("url", url)
|
||||
if s.drop != nil {
|
||||
s.drop["url"] = url
|
||||
}
|
||||
@ -126,7 +126,7 @@ func (s *Site) FilenameURLs() map[string]string {
|
||||
|
||||
// KeepFile returns a boolean indicating that clean should leave the file in the destination directory.
|
||||
func (s *Site) KeepFile(filename string) bool {
|
||||
return utils.SearchStrings(s.config.KeepFiles, filename)
|
||||
return utils.SearchStrings(s.cfg.KeepFiles, filename)
|
||||
}
|
||||
|
||||
// FilePathPage returns a Page, give a file path relative to site source directory.
|
||||
@ -171,7 +171,7 @@ func (s *Site) initializeRenderers() (err error) {
|
||||
RelativeFilenameToURL: s.FilenameURLPath,
|
||||
ThemeDir: s.themeDir,
|
||||
}
|
||||
s.renderer, err = renderers.New(s.config, options)
|
||||
s.renderer, err = renderers.New(s.cfg, options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -188,7 +188,7 @@ func (s *Site) RelativePath(path string) string {
|
||||
return rel
|
||||
}
|
||||
}
|
||||
return utils.MustRel(s.config.Source, path)
|
||||
return utils.MustRel(s.cfg.Source, path)
|
||||
}
|
||||
|
||||
// URLPage returns the page that will be served at URL
|
||||
|
@ -17,8 +17,8 @@ func TestKeepFile(t *testing.T) {
|
||||
|
||||
func TestExclude(t *testing.T) {
|
||||
s := New(config.Flags{})
|
||||
s.config.Exclude = append(s.config.Exclude, "exclude/")
|
||||
s.config.Include = append(s.config.Include, ".include/")
|
||||
s.cfg.Exclude = append(s.cfg.Exclude, "exclude/")
|
||||
s.cfg.Include = append(s.cfg.Include, ".include/")
|
||||
require.False(t, s.Exclude("."))
|
||||
require.True(t, s.Exclude(".git"))
|
||||
require.True(t, s.Exclude(".dir"))
|
||||
|
@ -10,19 +10,19 @@ import (
|
||||
)
|
||||
|
||||
func (s *Site) findTheme() error {
|
||||
if s.config.Theme == "" {
|
||||
if s.cfg.Theme == "" {
|
||||
return nil
|
||||
}
|
||||
exe, err := exec.LookPath("bundle")
|
||||
if err != nil {
|
||||
log.Fatal("bundle is not in your PATH", err)
|
||||
}
|
||||
cmd := exec.Command(exe, "show", s.config.Theme) // nolint: gas
|
||||
cmd := exec.Command(exe, "show", s.cfg.Theme) // nolint: gas
|
||||
cmd.Dir = s.AbsDir()
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return fmt.Errorf("the %s theme could not be found", s.config.Theme)
|
||||
return fmt.Errorf("the %s theme could not be found", s.cfg.Theme)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func (s *Site) WatchFiles() (<-chan FilesEvent, error) {
|
||||
|
||||
func (s *Site) makeFileWatcher() (<-chan string, error) {
|
||||
switch {
|
||||
case s.config.ForcePolling:
|
||||
case s.cfg.ForcePolling:
|
||||
return s.makePollingWatcher()
|
||||
default:
|
||||
return s.makeEventWatcher()
|
||||
@ -88,7 +88,7 @@ func (s *Site) makePollingWatcher() (<-chan string, error) {
|
||||
if err := w.AddRecursive(sourceDir); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, path := range s.config.Exclude {
|
||||
for _, path := range s.cfg.Exclude {
|
||||
if err := w.Ignore(filepath.Join(sourceDir, path)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -60,10 +60,10 @@ func (s *Site) WriteDoc(d pages.Document) error {
|
||||
rel = filepath.Join(rel, "index.html")
|
||||
}
|
||||
to := filepath.Join(s.DestDir(), rel)
|
||||
if s.config.Verbose {
|
||||
if s.cfg.Verbose {
|
||||
fmt.Println("create", to, "from", d.SourcePath())
|
||||
}
|
||||
if s.config.DryRun {
|
||||
if s.cfg.DryRun {
|
||||
// FIXME render the page, just don't write it
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user