Adding support for destination dir, split out static

This commit is contained in:
spf13 2013-07-26 18:06:13 -04:00
parent 92c31bbe10
commit 7ab28c564f
3 changed files with 31 additions and 26 deletions

View file

@ -27,13 +27,13 @@ import (
// config file items // config file items
type Config struct { type Config struct {
SourceDir, PublishDir, BaseUrl, StaticDir string ContentDir, PublishDir, BaseUrl, StaticDir string
Path, CacheDir, LayoutDir, DefaultLayout string Path, CacheDir, LayoutDir, DefaultLayout string
ConfigFile string ConfigFile string
Title string Title string
Indexes map[string]string // singular, plural Indexes map[string]string // singular, plural
ProcessFilters map[string][]string ProcessFilters map[string][]string
BuildDrafts, UglyUrls, Verbose bool BuildDrafts, UglyUrls, Verbose bool
} }
var c Config var c Config
@ -51,7 +51,7 @@ func SetupConfig(cfgfile *string, path *string) *Config {
} }
// set defaults // set defaults
c.SourceDir = "content" c.ContentDir = "content"
c.LayoutDir = "layouts" c.LayoutDir = "layouts"
c.PublishDir = "public" c.PublishDir = "public"
c.StaticDir = "static" c.StaticDir = "static"

View file

@ -165,7 +165,7 @@ func (s *Site) initialize() {
return nil return nil
} }
filepath.Walk(s.c.GetAbsPath(s.c.SourceDir), walker) filepath.Walk(s.c.GetAbsPath(s.c.ContentDir), walker)
s.Info = SiteInfo{BaseUrl: template.URL(s.c.BaseUrl), Title: s.c.Title, Config: &s.c} s.Info = SiteInfo{BaseUrl: template.URL(s.c.BaseUrl), Title: s.c.Title, Config: &s.c}
@ -176,8 +176,8 @@ func (s *Site) checkDirectories() {
if b, _ := dirExists(s.c.GetAbsPath(s.c.LayoutDir)); !b { if b, _ := dirExists(s.c.GetAbsPath(s.c.LayoutDir)); !b {
FatalErr("No layout directory found, expecting to find it at " + s.c.GetAbsPath(s.c.LayoutDir)) FatalErr("No layout directory found, expecting to find it at " + s.c.GetAbsPath(s.c.LayoutDir))
} }
if b, _ := dirExists(s.c.GetAbsPath(s.c.SourceDir)); !b { if b, _ := dirExists(s.c.GetAbsPath(s.c.ContentDir)); !b {
FatalErr("No source directory found, expecting to find it at " + s.c.GetAbsPath(s.c.SourceDir)) FatalErr("No source directory found, expecting to find it at " + s.c.GetAbsPath(s.c.ContentDir))
} }
mkdirIf(s.c.GetAbsPath(s.c.PublishDir)) mkdirIf(s.c.GetAbsPath(s.c.PublishDir))
} }

35
main.go
View file

@ -27,19 +27,20 @@ import (
) )
var ( var (
baseUrl = flag.StringP("base-url", "b", "", "hostname (and path) to the root eg. http://spf13.com/") baseUrl = flag.StringP("base-url", "b", "", "hostname (and path) to the root eg. http://spf13.com/")
cfgfile = flag.String("config", "", "config file (default is path/config.yaml|json|toml)") cfgfile = flag.String("config", "", "config file (default is path/config.yaml|json|toml)")
checkMode = flag.Bool("check", false, "analyze content and provide feedback") checkMode = flag.Bool("check", false, "analyze content and provide feedback")
draft = flag.BoolP("build-drafts", "d", false, "include content marked as draft") draft = flag.BoolP("build-drafts", "D", false, "include content marked as draft")
help = flag.BoolP("help", "h", false, "show this help") help = flag.BoolP("help", "h", false, "show this help")
path = flag.StringP("source", "s", "", "filesystem path to read files relative from") source = flag.StringP("source", "s", "", "filesystem path to read files relative from")
verbose = flag.BoolP("verbose", "v", false, "verbose output") destination = flag.StringP("destination", "d", "", "filesystem path to write files to")
version = flag.Bool("version", false, "which version of hugo") verbose = flag.BoolP("verbose", "v", false, "verbose output")
cpuprofile = flag.Int("profile", 0, "Number of times to create the site and profile it") version = flag.Bool("version", false, "which version of hugo")
watchMode = flag.BoolP("watch", "w", false, "watch filesystem for changes and recreate as needed") cpuprofile = flag.Int("profile", 0, "Number of times to create the site and profile it")
server = flag.BoolP("server", "S", false, "run a (very) simple web server") watchMode = flag.BoolP("watch", "w", false, "watch filesystem for changes and recreate as needed")
port = flag.String("port", "1313", "port to run web server on, default :1313") server = flag.BoolP("server", "S", false, "run a (very) simple web server")
uglyUrls = flag.Bool("uglyurls", false, "use /filename.html instead of /filename/ ") port = flag.String("port", "1313", "port to run web server on, default :1313")
uglyUrls = flag.Bool("uglyurls", false, "use /filename.html instead of /filename/ ")
) )
func usage() { func usage() {
@ -57,11 +58,15 @@ func main() {
usage() usage()
} }
config := hugolib.SetupConfig(cfgfile, path) config := hugolib.SetupConfig(cfgfile, source)
config.BuildDrafts = *draft config.BuildDrafts = *draft
config.UglyUrls = *uglyUrls config.UglyUrls = *uglyUrls
config.Verbose = *verbose config.Verbose = *verbose
if *destination != "" {
config.PublishDir = *destination
}
if *baseUrl != "" { if *baseUrl != "" {
config.BaseUrl = *baseUrl config.BaseUrl = *baseUrl
} else if *server { } else if *server {
@ -194,7 +199,7 @@ func getDirList(c *hugolib.Config) []string {
return nil return nil
} }
filepath.Walk(c.GetAbsPath(c.SourceDir), walker) filepath.Walk(c.GetAbsPath(c.ContentDir), walker)
filepath.Walk(c.GetAbsPath(c.LayoutDir), walker) filepath.Walk(c.GetAbsPath(c.LayoutDir), walker)
return a return a