1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-30 08:39:01 +01:00

Implement --destination

This commit is contained in:
Oliver Steele 2017-06-15 22:31:36 -04:00
parent 1e12903487
commit 15cff8988a
3 changed files with 17 additions and 14 deletions

View File

@ -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")
}

View File

@ -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 {

17
site.go
View File

@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
"github.com/acstech/liquid"
@ -16,7 +17,7 @@ import (
type Site struct {
ConfigFile *string
Source string
Dest 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()
}