diff --git a/asset.go b/asset.go index 616bf55..1f5f210 100644 --- a/asset.go +++ b/asset.go @@ -1,8 +1,12 @@ package baja +import ( + "github.com/yeo/baja/utils" +) + func compileAsset(config *Config) { // This should go into a site/path helper - CopyDir("themes/"+config.Theme+"/static/css", "public/css") - CopyDir("themes/"+config.Theme+"/static/js", "public/js") - CopyDir("static", "public") + utils.CopyDir("themes/"+config.Theme+"/static/css", "public/css") + utils.CopyDir("themes/"+config.Theme+"/static/js", "public/js") + utils.CopyDir("static", "public") } diff --git a/baja.go b/baja.go index 7053020..4888566 100644 --- a/baja.go +++ b/baja.go @@ -1 +1,41 @@ package baja + +type Site struct { + Name string + Author string + BaseUrl string +} + +type NodeParams struct{} + +type TreeNode struct { + Name string + Leafs []TreeNode + Type string +} + +type NodeMeta struct { + Title string + Draft bool + Date time.Time + DateFormatted string + Tags []string + Category string + Type string +} + +type Node struct { + Meta *NodeMeta + Body template.HTML + Name string + + Params *NodeParams + + Raw string + Path string + BaseDirectory string + templatePaths []string +} + +var NodeDB map[string][]*Node +var Nodes []*Node diff --git a/node.go b/node.go index faa88ae..c20b404 100644 --- a/node.go +++ b/node.go @@ -16,37 +16,6 @@ import ( "strings" ) -type NodeParams struct{} - -type TreeNode struct { - Name string - Leafs []TreeNode - Type string -} - -type NodeMeta struct { - Title string - Draft bool - Date time.Time - DateFormatted string - Tags []string - Category string - Hidden bool -} - -type Node struct { - Meta *NodeMeta - Body template.HTML - - Params *NodeParams - - Raw string - Path string - BaseDirectory string - Name string - templatePaths []string -} - func NewNode(path string) *Node { n := Node{Path: path} n.BaseDirectory = strings.Join(strings.Split(filepath.Dir(path), "/")[1:], "/") @@ -57,6 +26,10 @@ func NewNode(path string) *Node { return &n } +func (n *Node) IsPage() bool { + return n.Meta.Type == "page" +} + func (n *Node) Permalink() string { return n.BaseDirectory + "/" + filepath.Base(n.Name) } @@ -142,8 +115,6 @@ func (n *Node) Compile() { type visitor func(path string, f os.FileInfo, err error) error -var NodeDB map[string][]*Node - func visit(node *TreeNode) filepath.WalkFunc { NodeDB = make(map[string][]*Node) @@ -163,9 +134,8 @@ func visit(node *TreeNode) filepath.WalkFunc { n.Parse() n.FindTheme(DefaultConfig()) n.Compile() - if n.Meta.Hidden == false { - NodeDB[n.BaseDirectory] = append(NodeDB[n.BaseDirectory], n) - } + + NodeDB[n.BaseDirectory] = append(NodeDB[n.BaseDirectory], n) return nil } diff --git a/site.go b/site.go deleted file mode 100644 index 72fe831..0000000 --- a/site.go +++ /dev/null @@ -1,7 +0,0 @@ -package baja - -type Site struct { - Name string - Author string - BaseUrl string -} diff --git a/utils.go b/utils/utils.go similarity index 93% rename from utils.go rename to utils/utils.go index efe8578..b9675ab 100644 --- a/utils.go +++ b/utils/utils.go @@ -1,10 +1,11 @@ -package baja - -// https://gist.github.com/jaybill/2876519 -import "os" -import "io" -import "io/ioutil" -import "log" +package utils + +import ( + "io" + "io/ioutil" + "log" + "os" +) // Copies file source to destination dest. func CopyFile(source string, dest string) (err error) {