aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib
diff options
context:
space:
mode:
authorNoah Campbell <[email protected]>2013-09-20 17:24:25 -0700
committerNoah Campbell <[email protected]>2013-09-20 17:24:25 -0700
commitbffe4baf4297b0fd3b46cbaac2cb4e99577fadf1 (patch)
tree997dfd9016603fd089e7cd76f3590dcf8925506d /hugolib
parent52e8c7a0ac76f4aa1fff8ff30a6d5074bd459347 (diff)
downloadhugo-bffe4baf4297b0fd3b46cbaac2cb4e99577fadf1.tar.gz
hugo-bffe4baf4297b0fd3b46cbaac2cb4e99577fadf1.zip
Create a TargetPath() method that provides OutFile
Moved the generation of the target path to the page breaking all dependecies on Site.
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/page.go26
-rw-r--r--hugolib/planner.go2
-rw-r--r--hugolib/site.go38
-rw-r--r--hugolib/site_test.go12
4 files changed, 34 insertions, 44 deletions
diff --git a/hugolib/page.go b/hugolib/page.go
index 5c00ef07e..e93984bcf 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -52,7 +52,7 @@ type Page struct {
}
type File struct {
- FileName, OutFile, Extension, Dir string
+ FileName, Extension, Dir string
}
type PageMeta struct {
@@ -432,3 +432,27 @@ func (page *Page) convertRestructuredText(lines io.Reader) {
page.Summary = template.HTML(getRstContent(summary))
}
}
+
+func (p *Page) TargetPath() (outfile string) {
+
+ // Always use Url if it's specified
+ if len(strings.TrimSpace(p.Url)) > 2 {
+ outfile = strings.TrimSpace(p.Url)
+
+ if strings.HasSuffix(outfile, "/") {
+ outfile = outfile + "index.html"
+ }
+ return
+ }
+
+ if len(strings.TrimSpace(p.Slug)) > 0 {
+ outfile = strings.TrimSpace(p.Slug) + "." + p.Extension
+ } else {
+ // Fall back to filename
+ _, t := path.Split(p.FileName)
+ outfile = replaceExtension(strings.TrimSpace(t), p.Extension)
+ }
+
+ return path.Join(p.Dir, strings.TrimSpace(outfile))
+}
+
diff --git a/hugolib/planner.go b/hugolib/planner.go
index e8b03bb5a..637c27b10 100644
--- a/hugolib/planner.go
+++ b/hugolib/planner.go
@@ -27,7 +27,7 @@ func (s *Site) ShowPlan(out io.Writer) (err error) {
continue
}
- trns, err := s.Target.Translate(p.OutFile)
+ trns, err := s.Target.Translate(p.TargetPath())
if err != nil {
return err
}
diff --git a/hugolib/site.go b/hugolib/site.go
index 39744da12..77046c272 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -26,7 +26,6 @@ import (
"html/template"
"io"
"os"
- "path"
"strings"
"time"
)
@@ -265,9 +264,6 @@ func (s *Site) CreatePages() (err error) {
page.Tmpl = s.Tmpl
page.Section = file.Section
page.Dir = file.Dir
- if err = s.setUrlPath(page); err != nil {
- return err
- }
if s.Config.BuildDrafts || !page.Draft {
s.Pages = append(s.Pages, page)
}
@@ -277,34 +273,6 @@ func (s *Site) CreatePages() (err error) {
return
}
-// Set p.Section and p.OutFile relying on p.FileName as the source.
-// Filename is broken apart for a "Section" which basically equates to
-// the folder the file exists in.
-func (s *Site) setUrlPath(p *Page) (err error) {
-
- // Always use Url if it's specified
- if len(strings.TrimSpace(p.Url)) > 2 {
- p.OutFile = strings.TrimSpace(p.Url)
-
- if strings.HasSuffix(p.OutFile, "/") {
- p.OutFile = p.OutFile + "index.html"
- }
- return
- }
-
- var outfile string
- if len(strings.TrimSpace(p.Slug)) > 0 {
- outfile = strings.TrimSpace(p.Slug) + "." + p.Extension
- } else {
- // Fall back to filename
- _, t := path.Split(p.FileName)
- outfile = replaceExtension(strings.TrimSpace(t), p.Extension)
- }
-
- p.OutFile = p.Dir + "/" + strings.TrimSpace(outfile)
- return
-}
-
func (s *Site) BuildSiteMeta() (err error) {
s.Indexes = make(IndexList)
s.Sections = make(Index)
@@ -389,7 +357,7 @@ func (s *Site) RenderPages() (err error) {
var layout string
if !p.IsRenderable() {
- layout = "__" + p.FileName
+ layout = "__" + p.TargetPath()
_, err := s.Tmpl.New(layout).Parse(string(p.Content))
if err != nil {
return err
@@ -402,7 +370,7 @@ func (s *Site) RenderPages() (err error) {
if err != nil {
return err
}
- err = s.WritePublic(p.OutFile, content)
+ err = s.WritePublic(p.TargetPath(), content)
if err != nil {
return err
}
@@ -514,6 +482,8 @@ func (s *Site) RenderLists() error {
}
func (s *Site) RenderHomePage() error {
+ return nil
+
n := s.NewNode()
n.Title = n.Site.Title
n.Url = helpers.Urlize(string(n.Site.BaseUrl))
diff --git a/hugolib/site_test.go b/hugolib/site_test.go
index 9e0936dc2..9c4c44584 100644
--- a/hugolib/site_test.go
+++ b/hugolib/site_test.go
@@ -158,7 +158,7 @@ func TestRenderThingOrDefault(t *testing.T) {
}
}
-func TestSetOutFile(t *testing.T) {
+func TestTargetPath(t *testing.T) {
tests := []struct {
doc string
content string
@@ -175,19 +175,15 @@ func TestSetOutFile(t *testing.T) {
return
}
for _, test := range tests {
- var err error
s := &Site{
Config: Config{ContentDir: "content"},
}
p := pageMust(ReadFrom(strings.NewReader(test.content), s.Config.GetAbsPath(test.doc)))
- if err = s.setUrlPath(p); err != nil {
- t.Fatalf("Unable to set urlpath: %s", err)
- }
expected := test.expectedOutFile
- if p.OutFile != expected {
- t.Errorf("%s => p.OutFile expected: '%s', got: '%s'", test.doc, expected, p.OutFile)
+ if p.TargetPath() != expected {
+ t.Errorf("%s => OutFile expected: '%s', got: '%s'", test.doc, expected, p.TargetPath())
}
if p.Section != test.expectedSection {
@@ -240,7 +236,7 @@ func TestSkipRender(t *testing.T) {
{"sect/doc3.html", "<html><head></head><body><h1>doc3</h1>\n\n<p><em>some</em> content</p>\n</body></html>"},
{"sect/doc4.html", "<html><head></head><body><h1>doc4</h1>\n\n<p><em>some content</em></p>\n</body></html>"},
{"sect/doc5.html", "<!DOCTYPE html><html><head><script src=\"http://auth/bub/script.js\"></script></head><body>body5</body></html>"},
- {"./doc7.html", "<html><head></head><body>doc7 content</body></html>"},
+ {"doc7.html", "<html><head></head><body>doc7 content</body></html>"},
}
for _, test := range tests {