aboutsummaryrefslogtreecommitdiff
path: root/context.go
diff options
context:
space:
mode:
Diffstat (limited to 'context.go')
-rw-r--r--context.go25
1 files changed, 11 insertions, 14 deletions
diff --git a/context.go b/context.go
index aff6a5d..a099da4 100644
--- a/context.go
+++ b/context.go
@@ -27,40 +27,36 @@ import (
27 27
28type page struct { 28type page struct {
29 Title string 29 Title string
30 URL string 30 Path string
31} 31}
32 32
33type context struct { 33type context struct {
34 path string 34 filePath string
35 Path string
35 IsCurrent func(params []string, data string) string 36 IsCurrent func(params []string, data string) string
36 IsParent func(params []string, data string) string 37 IsParent func(params []string, data string) string
37} 38}
38 39
39// Methods accessible in templates 40// Methods accessible in templates
40 41
41func (c context) URL() string {
42 p := strings.TrimPrefix(c.path, *settings.sourceDir)
43 return path.Clean("/" + p)
44}
45
46func (c context) Title() string { 42func (c context) Title() string {
47 _, t := path.Split(strings.TrimRight(c.URL(), "/")) 43 _, t := path.Split(strings.TrimRight(c.Path, "/"))
48 return t 44 return t
49} 45}
50 46
51func (c context) SubPages() (subPages []page) { 47func (c context) SubPages() (subPages []page) {
52 dirs, _ := fcmd.Ls(c.path) 48 dirs, _ := fcmd.Ls(c.filePath)
53 for _, dir := range dirs { 49 for _, dir := range dirs {
54 var page page 50 var page page
55 page.Title = dir 51 page.Title = dir
56 page.URL = path.Join(c.URL(), dir) 52 page.Path = path.Join(c.Path, dir)
57 subPages = append(subPages, page) 53 subPages = append(subPages, page)
58 } 54 }
59 return 55 return
60} 56}
61 57
62func (c context) IsRoot() bool { 58func (c context) IsRoot() bool {
63 if c.URL() == "/" { 59 if c.Path == "/" {
64 return true 60 return true
65 } 61 }
66 return false 62 return false
@@ -74,7 +70,7 @@ func (c context) isCurrent(pageTitle string) bool {
74} 70}
75 71
76func (c context) isParent(pageTitle string) bool { 72func (c context) isParent(pageTitle string) bool {
77 for _, parent := range strings.Split(c.URL(), "/") { 73 for _, parent := range strings.Split(c.Path, "/") {
78 if parent == pageTitle { 74 if parent == pageTitle {
79 return true 75 return true
80 } 76 }
@@ -82,8 +78,9 @@ func (c context) isParent(pageTitle string) bool {
82 return false 78 return false
83} 79}
84 80
85func makeContext(pagePath, sourceDir, outputDir string, exts []string) (c context) { 81func makeContext(pagePath, sourceDir string, exts []string) (c context) {
86 c.path = pagePath 82 c.Path = path.Clean("/" + pagePath)
83 c.filePath = path.Join(sourceDir, c.Path)
87 c.IsCurrent = func(params []string, data string) string { 84 c.IsCurrent = func(params []string, data string) string {
88 if c.isCurrent(strings.Join(params, " ")) { 85 if c.isCurrent(strings.Join(params, " ")) {
89 return data 86 return data