mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-30 08:28:58 +01:00
Include theme assets
This commit is contained in:
parent
e8a71af452
commit
a72426bb1b
@ -18,6 +18,7 @@ type Config struct {
|
||||
DataDir string `yaml:"data_dir"`
|
||||
IncludesDir string `yaml:"includes_dir"`
|
||||
Collections map[string]map[string]interface{} `yaml:"-"`
|
||||
Theme string
|
||||
|
||||
// Handling Reading
|
||||
Include []string
|
||||
|
35
site/read.go
35
site/read.go
@ -37,11 +37,21 @@ func FromDirectory(source string, flags config.Flags) (*Site, error) {
|
||||
|
||||
// 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)
|
||||
if err := s.findTheme(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.readDataFiles(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.readFiles(); err != nil {
|
||||
if err := s.readThemeAssets(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.readFiles(s.SourceDir(), s.SourceDir()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.ReadCollections(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.initializeRenderingPipeline(); err != nil {
|
||||
@ -77,31 +87,26 @@ func (s *Site) requiresFullReload(paths []string) bool {
|
||||
}
|
||||
|
||||
// readFiles scans the source directory and creates pages and collection.
|
||||
func (s *Site) readFiles() error {
|
||||
s.Routes = make(map[string]pages.Document)
|
||||
walkFn := func(filename string, info os.FileInfo, err error) error {
|
||||
func (s *Site) readFiles(dir, base string) error {
|
||||
return filepath.Walk(dir, func(filename string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
relname := utils.MustRel(s.SourceDir(), filename)
|
||||
rel := utils.MustRel(base, filename)
|
||||
switch {
|
||||
case info.IsDir() && s.Exclude(relname):
|
||||
case info.IsDir() && s.Exclude(rel):
|
||||
return filepath.SkipDir
|
||||
case info.IsDir(), s.Exclude(relname):
|
||||
case info.IsDir(), s.Exclude(rel):
|
||||
return nil
|
||||
}
|
||||
defaultFrontmatter := s.config.GetFrontMatterDefaults("", relname)
|
||||
p, err := pages.NewFile(s, filename, filepath.ToSlash(relname), defaultFrontmatter)
|
||||
defaultFrontmatter := s.config.GetFrontMatterDefaults("", rel)
|
||||
d, err := pages.NewFile(s, filename, filepath.ToSlash(rel), defaultFrontmatter)
|
||||
if err != nil {
|
||||
return utils.WrapPathError(err, filename)
|
||||
}
|
||||
s.AddDocument(p, true)
|
||||
s.AddDocument(d, true)
|
||||
return nil
|
||||
}
|
||||
if err := filepath.Walk(s.SourceDir(), walkFn); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.ReadCollections()
|
||||
})
|
||||
}
|
||||
|
||||
// AddDocument adds a document to the site structures.
|
||||
|
@ -25,6 +25,7 @@ type Site struct {
|
||||
data map[string]interface{}
|
||||
flags config.Flags
|
||||
pipeline *pipelines.Pipeline
|
||||
themeDir string
|
||||
docs []pages.Document // all documents, whether or not they are output
|
||||
preparedToRender bool
|
||||
drop map[string]interface{} // cached drop value
|
||||
|
39
site/theme.go
Normal file
39
site/theme.go
Normal file
@ -0,0 +1,39 @@
|
||||
package site
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func (s *Site) findTheme() error {
|
||||
if s.config.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.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 err
|
||||
}
|
||||
s.themeDir = string(bytes.TrimSpace(out))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Site) readThemeAssets() error {
|
||||
err := s.readFiles(filepath.Join(s.themeDir, "assets"), s.themeDir)
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue
Block a user