mirror of
https://github.com/danog/gojekyll.git
synced 2024-12-02 14:57:50 +01:00
Implement --destination
This commit is contained in:
parent
1e12903487
commit
15cff8988a
6
build.go
6
build.go
@ -26,10 +26,10 @@ func (s *Site) Clean() error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := filepath.Walk(s.Dest, removeFiles); err != nil {
|
if err := filepath.Walk(s.Destination, removeFiles); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return RemoveEmptyDirectories(s.Dest)
|
return RemoveEmptyDirectories(s.Destination)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build cleans the destination and create files in it.
|
// 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.
|
// WritePage writes a page to the destination directory.
|
||||||
func (s *Site) WritePage(page Page) error {
|
func (s *Site) WritePage(page Page) error {
|
||||||
src := filepath.Join(s.Source, page.Path())
|
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) == "" {
|
if !page.Static() && filepath.Ext(dst) == "" {
|
||||||
dst = filepath.Join(dst, "/index.html")
|
dst = filepath.Join(dst, "/index.html")
|
||||||
}
|
}
|
||||||
|
4
main.go
4
main.go
@ -56,7 +56,7 @@ func main() {
|
|||||||
Name: "destination",
|
Name: "destination",
|
||||||
Value: "",
|
Value: "",
|
||||||
Usage: "Destination directory",
|
Usage: "Destination directory",
|
||||||
Destination: &source,
|
Destination: &destination,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func buildCommand(c *cli.Context) error {
|
func buildCommand(c *cli.Context) error {
|
||||||
printPathSetting("Destination:", site.Dest)
|
printPathSetting("Destination:", site.Destination)
|
||||||
printSetting("Generating...", "")
|
printSetting("Generating...", "")
|
||||||
count, err := site.Build()
|
count, err := site.Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
17
site.go
17
site.go
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/acstech/liquid"
|
"github.com/acstech/liquid"
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ import (
|
|||||||
type Site struct {
|
type Site struct {
|
||||||
ConfigFile *string
|
ConfigFile *string
|
||||||
Source string
|
Source string
|
||||||
Dest string
|
Destination string
|
||||||
|
|
||||||
Collections []*Collection
|
Collections []*Collection
|
||||||
Variables VariableMap
|
Variables VariableMap
|
||||||
@ -45,6 +46,7 @@ type SiteConfig struct {
|
|||||||
Permalink string
|
Permalink string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// From https://jekyllrb.com/docs/configuration/#default-configuration
|
||||||
const siteConfigDefaults = `
|
const siteConfigDefaults = `
|
||||||
# Where things are
|
# Where things are
|
||||||
source: .
|
source: .
|
||||||
@ -70,9 +72,7 @@ paginate_path: /page:num
|
|||||||
timezone: null
|
timezone: null
|
||||||
`
|
`
|
||||||
|
|
||||||
//TODO permalink: "/:categories/:year/:month/:day/:title.html",
|
// NewSite creates a new site record, initialized with the site defaults.
|
||||||
|
|
||||||
// NewSite creates a new site.
|
|
||||||
func NewSite() *Site {
|
func NewSite() *Site {
|
||||||
s := new(Site)
|
s := new(Site)
|
||||||
if err := s.readConfigBytes([]byte(siteConfigDefaults)); err != nil {
|
if err := s.readConfigBytes([]byte(siteConfigDefaults)); err != nil {
|
||||||
@ -91,10 +91,10 @@ func (s *Site) ReadConfiguration(source, dest string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.Source = filepath.Join(source, s.config.Source)
|
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
|
s.ConfigFile = &configPath
|
||||||
if dest != "" {
|
if dest != "" {
|
||||||
site.Dest = dest
|
site.Destination = dest
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
case os.IsNotExist(err):
|
case os.IsNotExist(err):
|
||||||
@ -247,7 +247,10 @@ func (s *Site) readCollections() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) initTemplateAttributes() {
|
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 {
|
for _, c := range s.Collections {
|
||||||
s.Variables[c.Name] = c.PageTemplateObjects()
|
s.Variables[c.Name] = c.PageTemplateObjects()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user