converted path 2 filepath

This commit is contained in:
Joel Scoble 2014-11-06 10:52:01 -06:00 committed by spf13
parent 7fd348cf79
commit 2c51bba0c3
3 changed files with 20 additions and 20 deletions

View file

@ -20,7 +20,7 @@ import (
"html/template" "html/template"
"io" "io"
"net/url" "net/url"
"path" "path/filepath"
"strings" "strings"
"time" "time"
@ -175,7 +175,7 @@ func layouts(types string, layout string) (layouts []string) {
// Add type/layout.html // Add type/layout.html
for i := range t { for i := range t {
search := t[:len(t)-i] search := t[:len(t)-i]
layouts = append(layouts, fmt.Sprintf("%s/%s.html", strings.ToLower(path.Join(search...)), layout)) layouts = append(layouts, fmt.Sprintf("%s/%s.html", strings.ToLower(filepath.Join(search...)), layout))
} }
// Add _default/layout.html // Add _default/layout.html
@ -250,10 +250,10 @@ func (p *Page) permalink() (*url.URL, error) {
// fmt.Printf("have a section override for %q in section %s → %s\n", p.Title, p.Section, permalink) // fmt.Printf("have a section override for %q in section %s → %s\n", p.Title, p.Section, permalink)
} else { } else {
if len(pSlug) > 0 { if len(pSlug) > 0 {
permalink = helpers.UrlPrep(viper.GetBool("UglyUrls"), path.Join(dir, p.Slug+"."+p.Extension())) permalink = helpers.UrlPrep(viper.GetBool("UglyUrls"), filepath.Join(dir, p.Slug+"."+p.Extension()))
} else { } else {
_, t := path.Split(p.Source.LogicalName()) _, t := filepath.Split(p.Source.LogicalName())
permalink = helpers.UrlPrep(viper.GetBool("UglyUrls"), path.Join(dir, helpers.ReplaceExtension(strings.TrimSpace(t), p.Extension()))) permalink = helpers.UrlPrep(viper.GetBool("UglyUrls"), filepath.Join(dir, helpers.ReplaceExtension(strings.TrimSpace(t), p.Extension())))
} }
} }
@ -592,7 +592,7 @@ func (page *Page) saveSourceAs(path string, safe bool) error {
} }
func (page *Page) saveSource(by []byte, inpath string, safe bool) (err error) { func (page *Page) saveSource(by []byte, inpath string, safe bool) (err error) {
if !path.IsAbs(inpath) { if !filepath.IsAbs(inpath) {
inpath = helpers.AbsPathify(inpath) inpath = helpers.AbsPathify(inpath)
} }
jww.INFO.Println("creating", inpath) jww.INFO.Println("creating", inpath)
@ -633,7 +633,7 @@ func (page *Page) Convert() error {
} }
func (p *Page) FullFilePath() string { func (p *Page) FullFilePath() string {
return path.Join(p.Source.Dir(), p.Source.Path()) return filepath.Join(p.Source.Dir(), p.Source.Path())
} }
func (p *Page) TargetPath() (outfile string) { func (p *Page) TargetPath() (outfile string) {
@ -667,5 +667,5 @@ func (p *Page) TargetPath() (outfile string) {
outfile = helpers.ReplaceExtension(p.Source.LogicalName(), p.Extension()) outfile = helpers.ReplaceExtension(p.Source.LogicalName(), p.Extension())
} }
return path.Join(p.Source.Dir(), strings.TrimSpace(outfile)) return filepath.Join(p.Source.Dir(), strings.TrimSpace(outfile))
} }

View file

@ -2,7 +2,7 @@ package hugolib
import ( import (
"html/template" "html/template"
"path" "path/filepath"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -520,11 +520,11 @@ func L(s ...string) []string {
func TestLayoutOverride(t *testing.T) { func TestLayoutOverride(t *testing.T) {
var ( var (
path_content_two_dir = path.Join("content", "dub", "sub", "file1.md") path_content_two_dir = filepath.Join("content", "dub", "sub", "file1.md")
path_content_one_dir = path.Join("content", "gub", "file1.md") path_content_one_dir = filepath.Join("content", "gub", "file1.md")
path_content_no_dir = path.Join("content", "file1") path_content_no_dir = filepath.Join("content", "file1")
path_one_directory = path.Join("fub", "file1.md") path_one_directory = filepath.Join("fub", "file1.md")
path_no_directory = path.Join("file1.md") path_no_directory = filepath.Join("file1.md")
) )
tests := []struct { tests := []struct {
content string content string

View file

@ -1,7 +1,7 @@
package hugolib package hugolib
import ( import (
"path" "path/filepath"
"strings" "strings"
"testing" "testing"
) )
@ -13,7 +13,7 @@ Sample Text
` `
func TestDegenerateMissingFolderInPageFilename(t *testing.T) { func TestDegenerateMissingFolderInPageFilename(t *testing.T) {
p, err := NewPageFrom(strings.NewReader(SIMPLE_PAGE_YAML), path.Join("foobar")) p, err := NewPageFrom(strings.NewReader(SIMPLE_PAGE_YAML), filepath.Join("foobar"))
if err != nil { if err != nil {
t.Fatalf("Error in NewPageFrom") t.Fatalf("Error in NewPageFrom")
} }
@ -28,10 +28,10 @@ func TestNewPageWithFilePath(t *testing.T) {
section string section string
layout []string layout []string
}{ }{
{path.Join("sub", "foobar.html"), "sub", L("sub/single.html", "_default/single.html")}, {filepath.Join("sub", "foobar.html"), "sub", L("sub/single.html", "_default/single.html")},
{path.Join("content", "foobar.html"), "", L("page/single.html", "_default/single.html")}, {filepath.Join("content", "foobar.html"), "", L("page/single.html", "_default/single.html")},
{path.Join("content", "sub", "foobar.html"), "sub", L("sub/single.html", "_default/single.html")}, {filepath.Join("content", "sub", "foobar.html"), "sub", L("sub/single.html", "_default/single.html")},
{path.Join("content", "dub", "sub", "foobar.html"), "dub", L("dub/single.html", "_default/single.html")}, {filepath.Join("content", "dub", "sub", "foobar.html"), "dub", L("dub/single.html", "_default/single.html")},
} }
for _, el := range toCheck { for _, el := range toCheck {