mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-30 23:50:04 +03:00
parent
eb038cfa0a
commit
7930d2132a
7 changed files with 35 additions and 85 deletions
|
@ -98,17 +98,16 @@ func TestSiteBuildErrors(t *testing.T) {
|
||||||
a.assertLineNumber(2, err)
|
a.assertLineNumber(2, err)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// TODO(bep) 2errors
|
{
|
||||||
/* {
|
name: "Shortode execute failed",
|
||||||
name: "Shortode execute failed",
|
fileType: shortcode,
|
||||||
fileType: shortcode,
|
fileFixer: func(content string) string {
|
||||||
fileFixer: func(content string) string {
|
return strings.Replace(content, ".Title", ".Titles", 1)
|
||||||
return strings.Replace(content, ".Title", ".Titles", 1)
|
},
|
||||||
},
|
assertBuildError: func(a testSiteBuildErrorAsserter, err error) {
|
||||||
assertBuildError: func(a testSiteBuildErrorAsserter, err error) {
|
a.assertLineNumber(25, err)
|
||||||
a.assertLineNumber(2, err)
|
},
|
||||||
},
|
},
|
||||||
},*/
|
|
||||||
|
|
||||||
{
|
{
|
||||||
name: "Panic in template Execute",
|
name: "Panic in template Execute",
|
||||||
|
|
|
@ -49,7 +49,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
bp "github.com/gohugoio/hugo/bufferpool"
|
|
||||||
"github.com/gohugoio/hugo/compare"
|
"github.com/gohugoio/hugo/compare"
|
||||||
"github.com/gohugoio/hugo/source"
|
"github.com/gohugoio/hugo/source"
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
|
@ -185,7 +184,7 @@ type Page struct {
|
||||||
// menus
|
// menus
|
||||||
pageMenus PageMenus
|
pageMenus PageMenus
|
||||||
|
|
||||||
Source
|
source.File
|
||||||
|
|
||||||
Position `json:"-"`
|
Position `json:"-"`
|
||||||
|
|
||||||
|
@ -467,7 +466,7 @@ func (p *Page) BundleType() string {
|
||||||
return "branch"
|
return "branch"
|
||||||
}
|
}
|
||||||
|
|
||||||
var source interface{} = p.Source.File
|
var source interface{} = p.File
|
||||||
if fi, ok := source.(*fileInfo); ok {
|
if fi, ok := source.(*fileInfo); ok {
|
||||||
switch fi.bundleTp {
|
switch fi.bundleTp {
|
||||||
case bundleBranch:
|
case bundleBranch:
|
||||||
|
@ -484,12 +483,6 @@ func (p *Page) MediaType() media.Type {
|
||||||
return media.OctetType
|
return media.OctetType
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(bep) 2errors remove
|
|
||||||
type Source struct {
|
|
||||||
Frontmatter []byte
|
|
||||||
Content []byte
|
|
||||||
source.File
|
|
||||||
}
|
|
||||||
type PageMeta struct {
|
type PageMeta struct {
|
||||||
wordCount int
|
wordCount int
|
||||||
fuzzyWordCount int
|
fuzzyWordCount int
|
||||||
|
@ -512,7 +505,7 @@ func (ps Pages) String() string {
|
||||||
|
|
||||||
func (ps Pages) findPagePosByFilename(filename string) int {
|
func (ps Pages) findPagePosByFilename(filename string) int {
|
||||||
for i, x := range ps {
|
for i, x := range ps {
|
||||||
if x.Source.Filename() == filename {
|
if x.Filename() == filename {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -545,8 +538,8 @@ func (ps Pages) findPagePosByFilnamePrefix(prefix string) int {
|
||||||
|
|
||||||
// Find the closest match
|
// Find the closest match
|
||||||
for i, x := range ps {
|
for i, x := range ps {
|
||||||
if strings.HasPrefix(x.Source.Filename(), prefix) {
|
if strings.HasPrefix(x.Filename(), prefix) {
|
||||||
diff := len(x.Source.Filename()) - prefixLen
|
diff := len(x.Filename()) - prefixLen
|
||||||
if lenDiff == -1 || diff < lenDiff {
|
if lenDiff == -1 || diff < lenDiff {
|
||||||
lenDiff = diff
|
lenDiff = diff
|
||||||
currPos = i
|
currPos = i
|
||||||
|
@ -560,7 +553,7 @@ func (ps Pages) findPagePosByFilnamePrefix(prefix string) int {
|
||||||
// will return -1 if not found
|
// will return -1 if not found
|
||||||
func (ps Pages) findPagePos(page *Page) int {
|
func (ps Pages) findPagePos(page *Page) int {
|
||||||
for i, x := range ps {
|
for i, x := range ps {
|
||||||
if x.Source.Filename() == page.Source.Filename() {
|
if x.Filename() == page.Filename() {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -701,7 +694,7 @@ func (p *Page) Authors() AuthorList {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) UniqueID() string {
|
func (p *Page) UniqueID() string {
|
||||||
return p.Source.UniqueID()
|
return p.File.UniqueID()
|
||||||
}
|
}
|
||||||
|
|
||||||
// for logging
|
// for logging
|
||||||
|
@ -881,7 +874,7 @@ func (s *Site) newPageFromFile(fi *fileInfo) *Page {
|
||||||
pageContentInit: &pageContentInit{},
|
pageContentInit: &pageContentInit{},
|
||||||
Kind: kindFromFileInfo(fi),
|
Kind: kindFromFileInfo(fi),
|
||||||
contentType: "",
|
contentType: "",
|
||||||
Source: Source{File: fi},
|
File: fi,
|
||||||
Keywords: []string{}, Sitemap: Sitemap{Priority: -1},
|
Keywords: []string{}, Sitemap: Sitemap{Priority: -1},
|
||||||
params: make(map[string]interface{}),
|
params: make(map[string]interface{}),
|
||||||
translations: make(Pages, 0),
|
translations: make(Pages, 0),
|
||||||
|
@ -914,7 +907,7 @@ func (p *Page) Section() string {
|
||||||
if p.Kind == KindSection || p.Kind == KindTaxonomy || p.Kind == KindTaxonomyTerm {
|
if p.Kind == KindSection || p.Kind == KindTaxonomy || p.Kind == KindTaxonomyTerm {
|
||||||
return p.sections[0]
|
return p.sections[0]
|
||||||
}
|
}
|
||||||
return p.Source.Section()
|
return p.File.Section()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) newPageFrom(buf io.Reader, name string) (*Page, error) {
|
func (s *Site) newPageFrom(buf io.Reader, name string) (*Page, error) {
|
||||||
|
@ -1273,8 +1266,8 @@ func (p *Page) updateMetaData(frontmatter map[string]interface{}) error {
|
||||||
maps.ToLower(frontmatter)
|
maps.ToLower(frontmatter)
|
||||||
|
|
||||||
var mtime time.Time
|
var mtime time.Time
|
||||||
if p.Source.FileInfo() != nil {
|
if p.FileInfo() != nil {
|
||||||
mtime = p.Source.FileInfo().ModTime()
|
mtime = p.FileInfo().ModTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
var gitAuthorDate time.Time
|
var gitAuthorDate time.Time
|
||||||
|
@ -1476,7 +1469,7 @@ func (p *Page) updateMetaData(frontmatter map[string]interface{}) error {
|
||||||
p.Markup = helpers.GuessType(p.Markup)
|
p.Markup = helpers.GuessType(p.Markup)
|
||||||
if p.Markup == "unknown" {
|
if p.Markup == "unknown" {
|
||||||
// Fall back to file extension (might also return "unknown")
|
// Fall back to file extension (might also return "unknown")
|
||||||
p.Markup = helpers.GuessType(p.Source.Ext())
|
p.Markup = helpers.GuessType(p.Ext())
|
||||||
}
|
}
|
||||||
|
|
||||||
if draft != nil && published != nil {
|
if draft != nil && published != nil {
|
||||||
|
@ -1721,51 +1714,6 @@ func (p *Page) RawContent() string {
|
||||||
return string(p.rawContent)
|
return string(p.rawContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) SetSourceContent(content []byte) {
|
|
||||||
p.Source.Content = content
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Page) SafeSaveSourceAs(path string) error {
|
|
||||||
return p.saveSourceAs(path, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Page) SaveSourceAs(path string) error {
|
|
||||||
return p.saveSourceAs(path, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Page) saveSourceAs(path string, safe bool) error {
|
|
||||||
b := bp.GetBuffer()
|
|
||||||
defer bp.PutBuffer(b)
|
|
||||||
|
|
||||||
b.Write(p.Source.Frontmatter)
|
|
||||||
b.Write(p.Source.Content)
|
|
||||||
|
|
||||||
bc := make([]byte, b.Len(), b.Len())
|
|
||||||
copy(bc, b.Bytes())
|
|
||||||
|
|
||||||
return p.saveSource(bc, path, safe)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Page) saveSource(by []byte, inpath string, safe bool) (err error) {
|
|
||||||
if !filepath.IsAbs(inpath) {
|
|
||||||
inpath = p.s.PathSpec.AbsPathify(inpath)
|
|
||||||
}
|
|
||||||
p.s.Log.INFO.Println("creating", inpath)
|
|
||||||
if safe {
|
|
||||||
err = helpers.SafeWriteToDisk(inpath, bytes.NewReader(by), p.s.Fs.Source)
|
|
||||||
} else {
|
|
||||||
err = helpers.WriteToDisk(inpath, bytes.NewReader(by), p.s.Fs.Source)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Page) SaveSource() error {
|
|
||||||
return p.SaveSourceAs(p.FullFilePath())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Page) FullFilePath() string {
|
func (p *Page) FullFilePath() string {
|
||||||
return filepath.Join(p.Dir(), p.LogicalName())
|
return filepath.Join(p.Dir(), p.LogicalName())
|
||||||
}
|
}
|
||||||
|
@ -1779,8 +1727,8 @@ func (p *Page) FullFilePath() string {
|
||||||
// For pages that do not (sections witout content page etc.), it returns the
|
// For pages that do not (sections witout content page etc.), it returns the
|
||||||
// virtual path, consistent with where you would add a source file.
|
// virtual path, consistent with where you would add a source file.
|
||||||
func (p *Page) absoluteSourceRef() string {
|
func (p *Page) absoluteSourceRef() string {
|
||||||
if p.Source.File != nil {
|
if p.File != nil {
|
||||||
sourcePath := p.Source.Path()
|
sourcePath := p.Path()
|
||||||
if sourcePath != "" {
|
if sourcePath != "" {
|
||||||
return "/" + filepath.ToSlash(sourcePath)
|
return "/" + filepath.ToSlash(sourcePath)
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,9 +101,9 @@ func (c *PageCollections) refreshPageCaches() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ref/Relref supports this potentially ambiguous lookup.
|
// Ref/Relref supports this potentially ambiguous lookup.
|
||||||
add(p.Source.LogicalName(), p)
|
add(p.LogicalName(), p)
|
||||||
|
|
||||||
translationBaseName := p.Source.TranslationBaseName()
|
translationBaseName := p.TranslationBaseName()
|
||||||
|
|
||||||
dir, _ := path.Split(sourceRef)
|
dir, _ := path.Split(sourceRef)
|
||||||
dir = strings.TrimSuffix(dir, "/")
|
dir = strings.TrimSuffix(dir, "/")
|
||||||
|
|
|
@ -167,7 +167,7 @@ func (p *Page) parse(reader io.Reader) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(bep) 2errors
|
// TODO(bep) 2errors
|
||||||
p.lang = p.Source.File.Lang()
|
p.lang = p.File.Lang()
|
||||||
|
|
||||||
if p.s != nil && p.s.owner != nil {
|
if p.s != nil && p.s.owner != nil {
|
||||||
gi, enabled := p.s.owner.gitInfo.forPage(p)
|
gi, enabled := p.s.owner.gitInfo.forPage(p)
|
||||||
|
|
|
@ -87,7 +87,7 @@ func (p *Page) initTargetPathDescriptor() error {
|
||||||
Kind: p.Kind,
|
Kind: p.Kind,
|
||||||
Sections: p.sections,
|
Sections: p.sections,
|
||||||
UglyURLs: p.s.Info.uglyURLs(p),
|
UglyURLs: p.s.Info.uglyURLs(p),
|
||||||
Dir: filepath.ToSlash(p.Source.Dir()),
|
Dir: filepath.ToSlash(p.Dir()),
|
||||||
URL: p.frontMatterURL,
|
URL: p.frontMatterURL,
|
||||||
IsMultihost: p.s.owner.IsMultihost(),
|
IsMultihost: p.s.owner.IsMultihost(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1467,7 +1467,7 @@ func (s *Site) assembleTaxonomies() {
|
||||||
w := p.getParamToLower(plural + "_weight")
|
w := p.getParamToLower(plural + "_weight")
|
||||||
weight, err := cast.ToIntE(w)
|
weight, err := cast.ToIntE(w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Log.ERROR.Printf("Unable to convert taxonomy weight %#v to int for %s", w, p.Source.File.Path())
|
s.Log.ERROR.Printf("Unable to convert taxonomy weight %#v to int for %s", w, p.File.Path())
|
||||||
// weight will equal zero, so let the flow continue
|
// weight will equal zero, so let the flow continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1799,7 +1799,7 @@ func (s *Site) newNodePage(typ string, sections ...string) *Page {
|
||||||
pageInit: &pageInit{},
|
pageInit: &pageInit{},
|
||||||
pageContentInit: &pageContentInit{},
|
pageContentInit: &pageContentInit{},
|
||||||
Kind: typ,
|
Kind: typ,
|
||||||
Source: Source{File: &source.FileInfo{}},
|
File: &source.FileInfo{},
|
||||||
data: make(map[string]interface{}),
|
data: make(map[string]interface{}),
|
||||||
Site: &s.Info,
|
Site: &s.Info,
|
||||||
sections: sections,
|
sections: sections,
|
||||||
|
|
|
@ -59,7 +59,7 @@ func unmarshal(data []byte, f Format, v interface{}) error {
|
||||||
case ORG:
|
case ORG:
|
||||||
vv, err := goorgeous.OrgHeaders(data)
|
vv, err := goorgeous.OrgHeaders(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrap(err, "failed to unmarshal ORG headers")
|
||||||
}
|
}
|
||||||
switch v.(type) {
|
switch v.(type) {
|
||||||
case *map[string]interface{}:
|
case *map[string]interface{}:
|
||||||
|
@ -73,6 +73,9 @@ func unmarshal(data []byte, f Format, v interface{}) error {
|
||||||
err = toml.Unmarshal(data, v)
|
err = toml.Unmarshal(data, v)
|
||||||
case YAML:
|
case YAML:
|
||||||
err = yaml.Unmarshal(data, v)
|
err = yaml.Unmarshal(data, v)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to unmarshal YAML")
|
||||||
|
}
|
||||||
|
|
||||||
// To support boolean keys, the YAML package unmarshals maps to
|
// To support boolean keys, the YAML package unmarshals maps to
|
||||||
// map[interface{}]interface{}. Here we recurse through the result
|
// map[interface{}]interface{}. Here we recurse through the result
|
||||||
|
@ -100,7 +103,7 @@ func unmarshal(data []byte, f Format, v interface{}) error {
|
||||||
return errors.Errorf("unmarshal of format %q is not supported", f)
|
return errors.Errorf("unmarshal of format %q is not supported", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return errors.Wrap(err, "unmarshal failed")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue