summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorspf13 <steve.francia@gmail.com>2014-10-16 20:20:09 -0400
committerspf13 <steve.francia@gmail.com>2014-10-16 20:20:09 -0400
commit5dfc1dedb8ac53b7a2d3823d06808ae86f90b3d9 (patch)
treee90f9cfbcc920685dd9bceecd1925abec81ae0c0 /hugolib
parent24bbfe7d32fe151487ff87394433622e3f69eee4 (diff)
Big refactor of how source files are used. Also added default destination extension option.
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/page.go308
-rw-r--r--hugolib/pageGroup.go13
-rw-r--r--hugolib/page_permalink_test.go5
-rw-r--r--hugolib/page_test.go10
-rw-r--r--hugolib/path_seperators_test.go9
-rw-r--r--hugolib/permalinks.go9
-rw-r--r--hugolib/planner.go2
-rw-r--r--hugolib/shortcode.go3
-rw-r--r--hugolib/site.go14
-rw-r--r--hugolib/site_show_plan_test.go4
-rw-r--r--hugolib/site_test.go57
-rw-r--r--hugolib/site_url_test.go4
-rw-r--r--hugolib/summary.go75
13 files changed, 155 insertions, 358 deletions
diff --git a/hugolib/page.go b/hugolib/page.go
index 7cd400504..f5b5a2cdb 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -15,56 +15,63 @@ package hugolib
import (
"bytes"
- "crypto/md5"
- "encoding/hex"
"errors"
"fmt"
"html/template"
"io"
"net/url"
"path"
- "path/filepath"
"strings"
"time"
- "github.com/russross/blackfriday"
"github.com/spf13/cast"
"github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/parser"
+ "github.com/spf13/hugo/source"
jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
)
type Page struct {
- Status string
- Images []string
- rawContent []byte
- Content template.HTML
- Summary template.HTML
- TableOfContents template.HTML
- Truncated bool
- plain string // TODO should be []byte
- Params map[string]interface{}
- contentType string
- Draft bool
- PublishDate time.Time
- Aliases []string
- Tmpl Template
- Markup string
- renderable bool
- layout string
- linkTitle string
- frontmatter []byte
- sourceFrontmatter []byte
- sourceContent []byte
+ Params map[string]interface{}
+ Content template.HTML
+ Summary template.HTML
+ Aliases []string
+ Status string
+ Images []string
+ TableOfContents template.HTML
+ Truncated bool
+ Draft bool
+ PublishDate time.Time
+ Tmpl Template
+ Markup string
+
+ extension string
+ contentType string
+ renderable bool
+ layout string
+ linkTitle string
+ frontmatter []byte
+ rawContent []byte
+ plain string // TODO should be []byte
+ //sourceFrontmatter []byte
+ //sourceContent []byte
PageMeta
- File
+ //SourceFile source.File
+ Source
Position
Node
+ //Destination source.File
}
-type File struct {
- Name, FileName, Extension, Dir, UniqueId string
+//type File struct {
+//Name, FileName, Extension, Dir, UniqueId string
+//}
+
+type Source struct {
+ Frontmatter []byte
+ Content []byte
+ source.File
}
type PageMeta struct {
@@ -97,75 +104,40 @@ func (p *Page) IsPage() bool {
}
func (p *Page) UniqueId() string {
- return p.File.UniqueId
+ return p.Source.UniqueId()
}
func (p *Page) setSummary() {
- if bytes.Contains(p.rawContent, summaryDivider) {
+ if bytes.Contains(p.rawContent, helpers.SummaryDivider) {
// If user defines split:
// Split then render
p.Truncated = true // by definition
- header := bytes.Split(p.rawContent, summaryDivider)[0]
- p.Summary = bytesToHTML(p.renderBytes(header))
+ header := bytes.Split(p.rawContent, helpers.SummaryDivider)[0]
+ p.Summary = helpers.BytesToHTML(p.renderBytes(header))
} else {
// If hugo defines split:
// render, strip html, then split
plain := strings.TrimSpace(p.Plain())
- p.Summary = bytesToHTML([]byte(TruncateWordsToWholeSentence(plain, summaryLength)))
+ p.Summary = helpers.BytesToHTML([]byte(helpers.TruncateWordsToWholeSentence(plain, helpers.SummaryLength)))
p.Truncated = len(p.Summary) != len(plain)
}
}
-func stripEmptyNav(in []byte) []byte {
- return bytes.Replace(in, []byte("<nav>\n</nav>\n\n"), []byte(``), -1)
-}
-
-func bytesToHTML(b []byte) template.HTML {
- return template.HTML(string(b))
-}
-
func (p *Page) renderBytes(content []byte) []byte {
- return renderBytes(content, p.guessMarkupType(), p.UniqueId())
+ return helpers.RenderBytes(content, p.guessMarkupType(), p.UniqueId())
}
func (p *Page) renderContent(content []byte) []byte {
- return renderBytesWithTOC(content, p.guessMarkupType(), p.UniqueId())
-}
-
-func renderBytesWithTOC(content []byte, pagefmt string, footnoteref string) []byte {
- switch pagefmt {
- default:
- return markdownRenderWithTOC(content, footnoteref)
- case "markdown":
- return markdownRenderWithTOC(content, footnoteref)
- case "rst":
- return []byte(getRstContent(content))
- }
-}
-
-func renderBytes(content []byte, pagefmt string, footnoteref string) []byte {
- switch pagefmt {
- default:
- return markdownRender(content, footnoteref)
- case "markdown":
- return markdownRender(content, footnoteref)
- case "rst":
- return []byte(getRstContent(content))
- }
+ return helpers.RenderBytesWithTOC(content, p.guessMarkupType(), p.UniqueId())
}
func newPage(filename string) *Page {
- name := filepath.Base(filename)
- // strip off the extension
- name = name[:len(name)-len(filepath.Ext(name))]
-
page := Page{contentType: "",
- File: File{Name: name, FileName: filename, Extension: "html", UniqueId: md5ForFilename(filename)},
+ Source: Source{File: *source.NewFile(filename)},
Node: Node{Keywords: []string{}, Sitemap: Sitemap{Priority: -1}},
Params: make(map[string]interface{})}
- jww.DEBUG.Println("Reading from", page.File.FileName)
- page.guessSection()
+ jww.DEBUG.Println("Reading from", page.File.Path())
return &page
}
@@ -173,24 +145,22 @@ func (p *Page) IsRenderable() bool {
return p.renderable
}
-func (p *Page) guessSection() {
- if p.Section == "" {
- p.Section = helpers.GuessSection(p.FileName)
- }
-}
-
func (page *Page) Type() string {
if page.contentType != "" {
return page.contentType
}
- page.guessSection()
- if x := page.Section; x != "" {
+
+ if x := page.Section(); x != "" {
return x
}
return "page"
}
+func (page *Page) Section() string {
+ return page.Source.Section()
+}
+
func (page *Page) Layout(l ...string) []string {
if page.layout != "" {
return layouts(page.Type(), page.layout)
@@ -261,14 +231,14 @@ func (p *Page) ReadFrom(buf io.Reader) (err error) {
}
func (p *Page) analyzePage() {
- p.WordCount = TotalWords(p.Plain())
+ p.WordCount = helpers.TotalWords(p.Plain())
p.FuzzyWordCount = int((p.WordCount+100)/100) * 100
p.ReadingTime = int((p.WordCount + 212) / 213)
}
func (p *Page) permalink() (*url.URL, error) {
baseUrl := string(p.Site.BaseUrl)
- dir := strings.TrimSpace(p.Dir)
+ dir := strings.TrimSpace(p.Source.Dir())
pSlug := strings.TrimSpace(p.Slug)
pUrl := strings.TrimSpace(p.Url)
var permalink string
@@ -278,7 +248,7 @@ func (p *Page) permalink() (*url.URL, error) {
return helpers.MakePermalink(baseUrl, pUrl), nil
}
- if override, ok := p.Site.Permalinks[p.Section]; ok {
+ if override, ok := p.Site.Permalinks[p.Section()]; ok {
permalink, err = override.Expand(p)
if err != nil {
@@ -287,16 +257,24 @@ 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)
} else {
if len(pSlug) > 0 {
- permalink = helpers.UrlPrep(viper.GetBool("UglyUrls"), path.Join(dir, p.Slug+"."+p.Extension))
+ permalink = helpers.UrlPrep(viper.GetBool("UglyUrls"), path.Join(dir, p.Slug+"."+p.Extension()))
} else {
- _, t := path.Split(p.FileName)
- permalink = helpers.UrlPrep(viper.GetBool("UglyUrls"), path.Join(dir, helpers.ReplaceExtension(strings.TrimSpace(t), p.Extension)))
+ _, t := path.Split(p.Source.LogicalName())
+ permalink = helpers.UrlPrep(viper.GetBool("UglyUrls"), path.Join(dir, helpers.ReplaceExtension(strings.TrimSpace(t), p.Extension())))
}
}
return helpers.MakePermalink(baseUrl, permalink), nil
}
+func (p *Page) Extension() string {
+ if p.extension != "" {
+ return p.extension
+ } else {
+ return viper.GetString("DefaultExtension")
+ }
+}
+
func (p *Page) LinkTitle() string {
if len(p.linkTitle) > 0 {
return p.linkTitle
@@ -370,6 +348,8 @@ func (page *Page) update(f interface{}) error {
page.Url = helpers.Urlize(cast.ToString(v))
case "type":
page.contentType = cast.ToString(v)
+ case "extension", "ext":
+ page.extension = cast.ToString(v)
case "keywords":
page.Keywords = cast.ToStringSlice(v)
case "date":
@@ -445,7 +425,7 @@ func (page *Page) GetParam(key string) interface{} {
case time.Time:
return cast.ToTime(v)
case []string:
- return sliceToLower(v.([]string))
+ return helpers.SliceToLower(v.([]string))
}
return nil
}
@@ -543,31 +523,13 @@ func (p *Page) Render(layout ...string) template.HTML {
func (page *Page) guessMarkupType() string {
// First try the explicitly set markup from the frontmatter
if page.Markup != "" {
- format := guessType(page.Markup)
+ format := helpers.GuessType(page.Markup)
if format != "unknown" {
return format
}
}
- // Then try to guess from the extension
- ext := strings.ToLower(path.Ext(page.FileName))
- if strings.HasPrefix(ext, ".") {
- return guessType(ext[1:])
- }
-
- return "unknown"
-}
-
-func guessType(in string) string {
- switch strings.ToLower(in) {
- case "md", "markdown", "mdown":
- return "markdown"
- case "rst":
- return "rst"
- case "html", "htm":
- return "html"
- }
- return "unknown"
+ return helpers.GuessType(page.Source.Ext())
}
func (page *Page) detectFrontMatter() (f *parser.FrontmatterType) {
@@ -585,7 +547,7 @@ func (page *Page) parse(reader io.Reader) error {
meta, err := psr.Metadata()
if meta != nil {
if err != nil {
- jww.ERROR.Printf("Error parsing page meta data for %s", page.FileName)
+ jww.ERROR.Printf("Error parsing page meta data for %s", page.File.Path())
jww.ERROR.Println(err)
return err
}
@@ -601,7 +563,7 @@ func (page *Page) parse(reader io.Reader) error {
}
func (page *Page) SetSourceContent(content []byte) {
- page.sourceContent = content
+ page.Source.Content = content
}
func (page *Page) SetSourceMetaData(in interface{}, mark rune) (err error) {
@@ -611,7 +573,7 @@ func (page *Page) SetSourceMetaData(in interface{}, mark rune) (err error) {
}
by = append(by, '\n')
- page.sourceFrontmatter = by
+ page.Source.Frontmatter = by
return nil
}
@@ -626,8 +588,8 @@ func (page *Page) SaveSourceAs(path string) error {
func (page *Page) saveSourceAs(path string, safe bool) error {
b := new(bytes.Buffer)
- b.Write(page.sourceFrontmatter)
- b.Write(page.sourceContent)
+ b.Write(page.Source.Frontmatter)
+ b.Write(page.Source.Content)
err := page.saveSource(b.Bytes(), path, safe)
if err != nil {
@@ -666,100 +628,19 @@ func (page *Page) Convert() error {
markupType := page.guessMarkupType()
switch markupType {
case "markdown", "rst":
- tmpContent, tmpTableOfContents := extractTOC(page.renderContent(RemoveSummaryDivider(page.rawContent)))
- page.Content = bytesToHTML(tmpContent)
- page.TableOfContents = bytesToHTML(tmpTableOfContents)
+ tmpContent, tmpTableOfContents := helpers.ExtractTOC(page.renderContent(helpers.RemoveSummaryDivider(page.rawContent)))
+ page.Content = helpers.BytesToHTML(tmpContent)
+ page.TableOfContents = helpers.BytesToHTML(tmpTableOfContents)
case "html":
- page.Content = bytesToHTML(page.rawContent)
+ page.Content = helpers.BytesToHTML(page.rawContent)
default:
- return fmt.Errorf("Error converting unsupported file type '%s' for page '%s'", markupType, page.FileName)
+ return fmt.Errorf("Error converting unsupported file type '%s' for page '%s'", markupType, page.Source.Path())
}
return nil
}
-func getHtmlRenderer(defaultFlags int, footnoteref string) blackfriday.Renderer {
- renderParameters := blackfriday.HtmlRendererParameters{
- FootnoteAnchorPrefix: viper.GetString("FootnoteAnchorPrefix"),
- FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"),
- }
-
- if len(footnoteref) != 0 {
- renderParameters.FootnoteAnchorPrefix = footnoteref + ":" +
- renderParameters.FootnoteAnchorPrefix
- }
-
- htmlFlags := defaultFlags
- htmlFlags |= blackfriday.HTML_USE_XHTML
- htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
- htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
- htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
- htmlFlags |= blackfriday.HTML_FOOTNOTE_RETURN_LINKS
-
- return blackfriday.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters)
-}
-
-func getMarkdownExtensions() int {
- return 0 | blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
- blackfriday.EXTENSION_TABLES | blackfriday.EXTENSION_FENCED_CODE |
- blackfriday.EXTENSION_AUTOLINK | blackfriday.EXTENSION_STRIKETHROUGH |
- blackfriday.EXTENSION_SPACE_HEADERS | blackfriday.EXTENSION_FOOTNOTES |
- blackfriday.EXTENSION_HEADER_IDS
-}
-
-func markdownRender(content []byte, footnoteref string) []byte {
- return blackfriday.Markdown(content, getHtmlRenderer(0, footnoteref),
- getMarkdownExtensions())
-}
-
-func markdownRenderWithTOC(content []byte, footnoteref string) []byte {
- return blackfriday.Markdown(content,
- getHtmlRenderer(blackfriday.HTML_TOC, footnoteref),
- getMarkdownExtensions())
-}
-
-func extractTOC(content []byte) (newcontent []byte, toc []byte) {
- origContent := make([]byte, len(content))
- copy(origContent, content)
- first := []byte(`<nav>
-<ul>`)
-
- last := []byte(`</ul>
-</nav>`)
-
- replacement := []byte(`<nav id="TableOfContents">
-<ul>`)
-
- startOfTOC := bytes.Index(content, first)
-
- peekEnd := len(content)
- if peekEnd > 70+startOfTOC {
- peekEnd = 70 + startOfTOC
- }
-
- if startOfTOC < 0 {
- return stripEmptyNav(content), toc
- }
- // Need to peek ahead to see if this nav element is actually the right one.
- correctNav := bytes.Index(content[startOfTOC:peekEnd], []byte(`#toc_0`))
- if correctNav < 0 { // no match found
- return content, toc
- }
- lengthOfTOC := bytes.Index(content[startOfTOC:], last) + len(last)
- endOfTOC := startOfTOC + lengthOfTOC
-
- newcontent = append(content[:startOfTOC], content[endOfTOC:]...)
- toc = append(replacement, origContent[startOfTOC+len(first):endOfTOC]...)
- return
-}
-
-func ReaderToBytes(lines io.Reader) []byte {
- b := new(bytes.Buffer)
- b.ReadFrom(lines)
- return b.Bytes()
-}
-
func (p *Page) FullFilePath() string {
- return path.Join(p.Dir, p.FileName)
+ return path.Join(p.Source.Dir(), p.Source.Path())
}
func (p *Page) TargetPath() (outfile string) {
@@ -775,7 +656,7 @@ func (p *Page) TargetPath() (outfile string) {
}
// If there's a Permalink specification, we use that
- if override, ok := p.Site.Permalinks[p.Section]; ok {
+ if override, ok := p.Site.Permalinks[p.Section()]; ok {
var err error
outfile, err = override.Expand(p)
if err == nil {
@@ -787,32 +668,11 @@ func (p *Page) TargetPath() (outfile string) {
}
if len(strings.TrimSpace(p.Slug)) > 0 {
- outfile = strings.TrimSpace(p.Slug) + "." + p.Extension
+ outfile = strings.TrimSpace(p.Slug) + "." + p.Extension()
} else {
// Fall back to filename
- _, t := path.Split(p.FileName)
- outfile = helpers.ReplaceExtension(strings.TrimSpace(t), p.Extension)
- }
-
- return path.Join(p.Dir, strings.TrimSpace(outfile))
-}
-
-// sliceToLower goes through the source slice and lowers all values.
-func sliceToLower(s []string) []string {
- if s == nil {
- return nil
+ outfile = helpers.ReplaceExtension(p.Source.LogicalName(), p.Extension())
}
- l := make([]string, len(s))
- for i, v := range s {
- l[i] = strings.ToLower(v)
- }
-
- return l
-}
-
-func md5ForFilename(f string) string {
- h := md5.New()
- h.Write([]byte(f))
- return hex.EncodeToString(h.Sum([]byte{}))
+ return path.Join(p.Source.Dir(), strings.TrimSpace(outfile))
}
diff --git a/hugolib/pageGroup.go b/hugolib/pageGroup.go
index 9d8d9d62c..f859c2e50 100644
--- a/hugolib/pageGroup.go
+++ b/hugolib/pageGroup.go
@@ -83,20 +83,25 @@ func (p Pages) GroupBy(key string, order ...string) (PagesGroup, error) {
direction = "desc"
}
- ppt := reflect.TypeOf(&Page{})
+ ppt := reflect.TypeOf(&Page{}) // *hugolib.Page
+
ft, ok := ppt.Elem().FieldByName(key)
+
if !ok {
return nil, errors.New("No such field in Page struct")
}
+
tmp := reflect.MakeMap(reflect.MapOf(ft.Type, reflect.SliceOf(ppt)))
for _, e := range p {
ppv := reflect.ValueOf(e)
fv := ppv.Elem().FieldByName(key)
- if !tmp.MapIndex(fv).IsValid() {
- tmp.SetMapIndex(fv, reflect.MakeSlice(reflect.SliceOf(ppt), 0, 0))
+ if !fv.IsNil() {
+ if !tmp.MapIndex(fv).IsValid() {
+ tmp.SetMapIndex(fv, reflect.MakeSlice(reflect.SliceOf(ppt), 0, 0))
+ }
+ tmp.SetMapIndex(fv, reflect.Append(tmp.MapIndex(fv), ppv))
}
- tmp.SetMapIndex(fv, reflect.Append(tmp.MapIndex(fv), ppv))
}
var r []PageGroup
diff --git a/hugolib/page_permalink_test.go b/hugolib/page_permalink_test.go
index b20362d5e..f420b19c6 100644
--- a/hugolib/page_permalink_test.go
+++ b/hugolib/page_permalink_test.go
@@ -4,6 +4,7 @@ import (
"html/template"
"testing"
+ "github.com/spf13/hugo/source"
"github.com/spf13/viper"
)
@@ -33,6 +34,8 @@ func TestPermalink(t *testing.T) {
{"x/y/z/boofar.md", "x/y/z", "", "", "/z/y/q/", false, "/z/y/q/", "/z/y/q/"},
}
+ viper.Set("DefaultExtension", "html")
+
for i, test := range tests {
viper.Set("uglyurls", test.uglyurls)
p := &Page{
@@ -45,7 +48,7 @@ func TestPermalink(t *testing.T) {
BaseUrl: test.base,
},
},
- File: File{FileName: test.file, Dir: test.dir, Extension: "html"},
+ Source: Source{File: *source.NewFile(test.file)},
}
if test.slug != "" {
diff --git a/hugolib/page_test.go b/hugolib/page_test.go
index 67c1270f3..6bb554bdf 100644
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -6,6 +6,8 @@ import (
"strings"
"testing"
"time"
+
+ "github.com/spf13/hugo/helpers"
)
var EMPTY_PAGE = ""
@@ -507,7 +509,7 @@ func TestDegenerateInvalidFrontMatterLeadingWhitespace(t *testing.T) {
func TestSectionEvaluation(t *testing.T) {
page, _ := NewPage("blue/file1.md")
page.ReadFrom(strings.NewReader(SIMPLE_PAGE))
- if page.Section != "blue" {
+ if page.Section() != "blue" {
t.Errorf("Section should be %s, got: %s", "blue", page.Section)
}
}
@@ -529,12 +531,12 @@ func TestLayoutOverride(t *testing.T) {
path string
expectedLayout []string
}{
- {SIMPLE_PAGE_NOLAYOUT, path_content_two_dir, L("dub/sub/single.html", "dub/single.html", "_default/single.html")},
+ {SIMPLE_PAGE_NOLAYOUT, path_content_two_dir, L("dub/single.html", "_default/single.html")},
{SIMPLE_PAGE_NOLAYOUT, path_content_one_dir, L("gub/single.html", "_default/single.html")},
{SIMPLE_PAGE_NOLAYOUT, path_content_no_dir, L("page/single.html", "_default/single.html")},
{SIMPLE_PAGE_NOLAYOUT, path_one_directory, L("fub/single.html", "_default/single.html")},
{SIMPLE_PAGE_NOLAYOUT, path_no_directory, L("page/single.html", "_default/single.html")},
- {SIMPLE_PAGE_LAYOUT_FOOBAR, path_content_two_dir, L("dub/sub/foobar.html", "dub/foobar.html", "_default/foobar.html")},
+ {SIMPLE_PAGE_LAYOUT_FOOBAR, path_content_two_dir, L("dub/foobar.html", "_default/foobar.html")},
{SIMPLE_PAGE_LAYOUT_FOOBAR, path_content_one_dir, L("gub/foobar.html", "_default/foobar.html")},
{SIMPLE_PAGE_LAYOUT_FOOBAR, path_one_directory, L("fub/foobar.html", "_default/foobar.html")},
{SIMPLE_PAGE_LAYOUT_FOOBAR, path_no_directory, L("page/foobar.html", "_default/foobar.html")},
@@ -576,7 +578,7 @@ func TestSliceToLower(t *testing.T) {
}
for _, test := range tests {
- res := sliceToLower(test.value)
+ res := helpers.SliceToLower(test.value)
for i, val := range res {
if val != test.expected[i] {
t.Errorf("Case mismatch. Expected %s, got %s", test.expected[i], res[i])
diff --git a/hugolib/path_seperators_test.go b/hugolib/path_seperators_test.go
index 187c155b5..589619d8c 100644
--- a/hugolib/path_seperators_test.go
+++ b/hugolib/path_seperators_test.go
@@ -17,7 +17,7 @@ func TestDegenerateMissingFolderInPageFilename(t *testing.T) {
if err != nil {
t.Fatalf("Error in NewPageFrom")
}
- if p.Section != "" {
+ if p.Section() != "" {
t.Fatalf("No section should be set for a file path: foobar")
}
}
@@ -31,17 +31,16 @@ func TestNewPageWithFilePath(t *testing.T) {
{path.Join("sub", "foobar.html"), "sub", L("sub/single.html", "_default/single.html")},
{path.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")},
- {path.Join("content", "dub", "sub", "foobar.html"), "dub/sub", L("dub/sub/single.html", "dub/single.html", "_default/single.html")},
+ {path.Join("content", "dub", "sub", "foobar.html"), "dub", L("dub/single.html", "_default/single.html")},
}
for _, el := range toCheck {
p, err := NewPageFrom(strings.NewReader(SIMPLE_PAGE_YAML), el.input)
- p.guessSection()
if err != nil {
t.Errorf("Reading from SIMPLE_PAGE_YAML resulted in an error: %s", err)
}
- if p.Section != el.section {
- t.Errorf("Section not set to %s for page %s. Got: %s", el.section, el.input, p.Section)
+ if p.Section() != el.section {
+ t.Errorf("Section not set to %s for page %s. Got: %s", el.section, el.input, p.Section())
}
for _, y := range el.layout {
diff --git a/hugolib/permalinks.go b/hugolib/permalinks.go
index 24e3334bb..323128041 100644
--- a/hugolib/permalinks.go
+++ b/hugolib/permalinks.go
@@ -3,7 +3,6 @@ package hugolib
import (
"errors"
"fmt"
- "path/filepath"
"strconv"
"strings"
@@ -120,9 +119,9 @@ func pageToPermalinkTitle(p *Page, _ string) (string, error) {
// pageToPermalinkFilename returns the URL-safe form of the filename
func pageToPermalinkFilename(p *Page, _ string) (string, error) {
- var extension = filepath.Ext(p.FileName)
- var name = p.FileName[0 : len(p.FileName)-len(extension)]
- return helpers.Urlize(name), nil
+ //var extension = p.Source.Ext
+ //var name = p.Source.Path()[0 : len(p.Source.Path())-len(extension)]
+ return helpers.Urlize(p.Source.BaseFileName()), nil
}
// if the page has a slug, return the slug, else return the title
@@ -143,7 +142,7 @@ func pageToPermalinkSlugElseTitle(p *Page, a string) (string, error) {
func pageToPermalinkSection(p *Page, _ string) (string, error) {
// Page contains Node contains UrlPath which has Section
- return p.Section, nil
+ return p.Section(), nil
}
func init() {
diff --git a/hugolib/planner.go b/hugolib/planner.go
index 246312746..ae32f9a38 100644
--- a/hugolib/planner.go
+++ b/hugolib/planner.go
@@ -11,7 +11,7 @@ func (s *Site) ShowPlan(out io.Writer) (err error) {
}
for _, p := range s.Pages {
- fmt.Fprintf(out, "%s", p.FileName)
+ fmt.Fprintf(out, "%s", p.Source.Path())
if p.IsRenderable() {
fmt.Fprintf(out, " (renderer: markdown)")
} else {
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go
index 1635ece99..ef413bfb3 100644
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -20,6 +20,7 @@ import (
"strings"
"unicode"
+ "github.com/spf13/hugo/helpers"
jww "github.com/spf13/jwalterweatherman"
)
@@ -93,7 +94,7 @@ func ShortcodesHandle(stringToParse string, p *Page, t Template) string {
var data = &ShortcodeWithPage{Params: params, Page: p}
if endStart > 0 {
s := stringToParse[leadEnd+3 : leadEnd+endStart]
- data.Inner = template.HTML(renderBytes([]byte(CleanP(ShortcodesHandle(s, p, t))), p.guessMarkupType(), p.UniqueId()))
+ data.Inner = template.HTML(helpers.RenderBytes([]byte(CleanP(ShortcodesHandle(s, p, t))), p.guessMarkupType(), p.UniqueId()))
remainder := CleanP(stringToParse[leadEnd+endEnd:])
return CleanP(stringToParse[:leadStart]) +
diff --git a/hugolib/site.go b/hugolib/site.go
index ad7afd725..d24036eb3 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -236,7 +236,7 @@ func (s *Site) Render() (err error) {
func (s *Site) checkDescriptions() {
for _, p := range s.Pages {
if len(p.Description) < 60 {
- jww.FEEDBACK.Println(p.FileName + " ")
+ jww.FEEDBACK.Println(p.Source.Path() + " ")
}
}
}
@@ -340,7 +340,7 @@ func (s *Site) CreatePages() error {
for i := 0; i < procs*4; i++ {
wg.Add(1)
- go pageReader(s, filechan, results, wg)
+ go sourceReader(s, filechan, results, wg)
}
errs := make(chan error)
@@ -397,18 +397,16 @@ func (s *Site) CreatePages() error {
return fmt.Errorf("%s\n%s", readErrs, renderErrs)
}
-func pageReader(s *Site, files <-chan *source.File, results chan<- pageResult, wg *sync.WaitGroup) {
+func sourceReader(s *Site, files <-chan *source.File, results chan<- pageResult, wg *sync.WaitGroup) {
defer wg.Done()
for file := range files {
- page, err := NewPage(file.LogicalName)
+ page, err := NewPage(file.Path())
if err != nil {
results <- pageResult{nil, err}
continue
}
page.Site = &s.Info
page.Tmpl = s.Tmpl
- page.Section = file.Section
- page.Dir = file.Dir
if err := page.ReadFrom(file.Contents); err != nil {
results <- pageResult{nil, err}
continue
@@ -604,7 +602,7 @@ func (s *Site) assembleTaxonomies() {
x := WeightedPage{weight.(int), p}
s.Taxonomies[plural].Add(v, x)
} else {
- jww.ERROR.Printf("Invalid %s in %s\n", plural, p.File.FileName)
+ jww.ERROR.Printf("Invalid %s in %s\n", plural, p.File.Path())
}
}
}
@@ -620,7 +618,7 @@ func (s *Site) assembleTaxonomies() {
func (s *Site) assembleSections() {
for i, p := range s.Pages {
- s.Sections.Add(p.Section, WeightedPage{s.Pages[i].Weight, s.Pages[i]})
+ s.Sections.Add(p.Section(), WeightedPage{s.Pages[i].Weight, s.Pages[i]})
}
for k := range s.Sections {
diff --git a/hugolib/site_show_plan_test.go b/hugolib/site_show_plan_test.go
index d43821848..801738ca3 100644
--- a/hugol