From 15cff8988a9c6b20d0308c5b1feeb3cea1f03a60 Mon Sep 17 00:00:00 2001 From: Oliver Steele Date: Thu, 15 Jun 2017 22:31:36 -0400 Subject: [PATCH] Implement --destination --- build.go | 6 +++--- main.go | 4 ++-- site.go | 21 ++++++++++++--------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/build.go b/build.go index b0baff8..1792b97 100644 --- a/build.go +++ b/build.go @@ -26,10 +26,10 @@ func (s *Site) Clean() error { } return nil } - if err := filepath.Walk(s.Dest, removeFiles); err != nil { + if err := filepath.Walk(s.Destination, removeFiles); err != nil { return err } - return RemoveEmptyDirectories(s.Dest) + return RemoveEmptyDirectories(s.Destination) } // Build cleans the destination and create files in it. @@ -50,7 +50,7 @@ func (s *Site) Build() (count int, err error) { // WritePage writes a page to the destination directory. func (s *Site) WritePage(page Page) error { src := filepath.Join(s.Source, page.Path()) - dst := filepath.Join(s.Dest, page.Path()) + dst := filepath.Join(s.Destination, page.Path()) if !page.Static() && filepath.Ext(dst) == "" { dst = filepath.Join(dst, "/index.html") } diff --git a/main.go b/main.go index 6639eaf..afee651 100644 --- a/main.go +++ b/main.go @@ -56,7 +56,7 @@ func main() { Name: "destination", Value: "", Usage: "Destination directory", - Destination: &source, + Destination: &destination, }, } @@ -133,7 +133,7 @@ func main() { } func buildCommand(c *cli.Context) error { - printPathSetting("Destination:", site.Dest) + printPathSetting("Destination:", site.Destination) printSetting("Generating...", "") count, err := site.Build() if err != nil { diff --git a/site.go b/site.go index 46c78bd..54d20b4 100644 --- a/site.go +++ b/site.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "strings" + "time" "github.com/acstech/liquid" @@ -14,9 +15,9 @@ import ( // Site is a Jekyll site. type Site struct { - ConfigFile *string - Source string - Dest string + ConfigFile *string + Source string + Destination string Collections []*Collection Variables VariableMap @@ -45,6 +46,7 @@ type SiteConfig struct { Permalink string } +// From https://jekyllrb.com/docs/configuration/#default-configuration const siteConfigDefaults = ` # Where things are source: . @@ -70,9 +72,7 @@ paginate_path: /page:num timezone: null ` -//TODO permalink: "/:categories/:year/:month/:day/:title.html", - -// NewSite creates a new site. +// NewSite creates a new site record, initialized with the site defaults. func NewSite() *Site { s := new(Site) if err := s.readConfigBytes([]byte(siteConfigDefaults)); err != nil { @@ -91,10 +91,10 @@ func (s *Site) ReadConfiguration(source, dest string) error { return err } s.Source = filepath.Join(source, s.config.Source) - s.Dest = filepath.Join(s.Source, s.config.Destination) + s.Destination = filepath.Join(s.Source, s.config.Destination) s.ConfigFile = &configPath if dest != "" { - site.Dest = dest + site.Destination = dest } return nil case os.IsNotExist(err): @@ -247,7 +247,10 @@ func (s *Site) readCollections() error { } func (s *Site) initTemplateAttributes() { - // TODO site: {time, pages, posts, related_posts, static_files, html_pages, html_files, collections, data, documents, categories.CATEGORY, tags.TAG} + // TODO site: {pages, posts, related_posts, static_files, html_pages, html_files, collections, data, documents, categories.CATEGORY, tags.TAG} + s.Variables = mergeVariableMaps(s.Variables, VariableMap{ + "time": time.Now(), + }) for _, c := range s.Collections { s.Variables[c.Name] = c.PageTemplateObjects() }