diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-10-23 14:37:09 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-10-23 19:41:22 +0200 |
commit | 6636cf1bea77d20ef2a72a45fae59ac402fb133b (patch) | |
tree | 91c9435acd1a2139f8816abcd9b0d978ff2fa300 /hugolib | |
parent | f669ef6bec25155d015b6ab231c53caef4fa5cdc (diff) |
Resolve error handling/parser related TODOs
See #5324
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/hugo_sites_build_errors_test.go | 2 | ||||
-rw-r--r-- | hugolib/hugo_sites_build_test.go | 8 | ||||
-rw-r--r-- | hugolib/page.go | 8 | ||||
-rw-r--r-- | hugolib/page_content.go | 21 | ||||
-rw-r--r-- | hugolib/page_test.go | 12 | ||||
-rw-r--r-- | hugolib/site_render.go | 5 | ||||
-rw-r--r-- | hugolib/site_test.go | 3 |
7 files changed, 30 insertions, 29 deletions
diff --git a/hugolib/hugo_sites_build_errors_test.go b/hugolib/hugo_sites_build_errors_test.go index 1e53eb3c4..8e913f061 100644 --- a/hugolib/hugo_sites_build_errors_test.go +++ b/hugolib/hugo_sites_build_errors_test.go @@ -191,7 +191,7 @@ func TestSiteBuildErrors(t *testing.T) { }, assertBuildError: func(a testSiteBuildErrorAsserter, err error) { assert.Error(err) - assert.Contains(err.Error(), `"content/mytoml.md": render of "page" failed: execute of template failed: panic in Execute`) + assert.Contains(err.Error(), `execute of template failed: panic in Execute`) }, }, } diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go index 727cc6ed9..f1e317f59 100644 --- a/hugolib/hugo_sites_build_test.go +++ b/hugolib/hugo_sites_build_test.go @@ -631,12 +631,10 @@ func assertShouldNotBuild(t *testing.T, sites *HugoSites) { for _, p := range s.rawAllPages { // No HTML when not processed require.Equal(t, p.shouldBuild(), bytes.Contains(p.workContent, []byte("</")), p.BaseFileName()+": "+string(p.workContent)) - // TODO(bep) 2errors - /* - require.Equal(t, p.shouldBuild(), p.content() != "", fmt.Sprintf("%v:%v", p.content(), p.shouldBuild())) - require.Equal(t, p.shouldBuild(), p.content() != "", p.BaseFileName()) - */ + require.Equal(t, p.shouldBuild(), p.content() != "", fmt.Sprintf("%v:%v", p.content(), p.shouldBuild())) + + require.Equal(t, p.shouldBuild(), p.content() != "", p.BaseFileName()) } } diff --git a/hugolib/page.go b/hugolib/page.go index df6f88b01..f7149ad74 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -1685,9 +1685,13 @@ func (p *Page) shouldRenderTo(f output.Format) bool { return found } +// RawContent returns the un-rendered source content without +// any leading front matter. func (p *Page) RawContent() string { - // TODO(bep) 2errors - return string(p.source.parsed.Input()) + if p.source.posMainContent == -1 { + return "" + } + return string(p.source.parsed.Input()[p.source.posMainContent:]) } func (p *Page) FullFilePath() string { diff --git a/hugolib/page_content.go b/hugolib/page_content.go index be015253b..dab46411e 100644 --- a/hugolib/page_content.go +++ b/hugolib/page_content.go @@ -46,11 +46,11 @@ type rawPageContent struct { hasSummaryDivider bool // The AST of the parsed page. Contains information about: - // shortcBackup3odes, front matter, summary indicators. - // TODO(bep) 2errors add this to a new rawPagecContent struct - // with frontMatterItem (pos) etc. - // * RawContent, RawContentWithoutFrontMatter + // shortcodes, front matter, summary indicators. parsed pageparser.Result + + // Returns the position in bytes after any front matter. + posMainContent int } // TODO(bep) lazy consolidate @@ -58,6 +58,7 @@ func (p *Page) mapContent() error { p.shortcodeState = newShortcodeHandler(p) s := p.shortcodeState p.renderable = true + p.source.posMainContent = -1 result := bp.GetBuffer() defer bp.PutBuffer(result) @@ -81,8 +82,8 @@ Loop: case it.Type == pageparser.TypeIgnore: case it.Type == pageparser.TypeHTMLComment: // Ignore. This is only a leading Front matter comment. - case it.Type == pageparser.TypeHTMLDocument: - // This is HTML only. No shortcode, front matter etc. + case it.Type == pageparser.TypeHTMLStart: + // This is HTML without front matter. It can still have shortcodes. p.renderable = false result.Write(it.Val) case it.IsFrontMatter(): @@ -99,12 +100,17 @@ Loop: return err } + next := iter.Peek() + if !next.IsDone() { + p.source.posMainContent = next.Pos + } + if !p.shouldBuild() { // Nothing more to do. return nil } - case it.Type == pageparser.TypeLeadSummaryDivider, it.Type == pageparser.TypeSummaryDividerOrg: + case it.Type == pageparser.TypeLeadSummaryDivider: result.Write(internalSummaryDivider) p.source.hasSummaryDivider = true // Need to determine if the page is truncated. @@ -172,7 +178,6 @@ func (p *Page) parse(reader io.Reader) error { parsed: parseResult, } - // TODO(bep) 2errors p.lang = p.File.Lang() if p.s != nil && p.s.owner != nil { diff --git a/hugolib/page_test.go b/hugolib/page_test.go index ced7e78d8..4499a97e0 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -767,8 +767,7 @@ Simple Page With Some Date` } // Issue #2601 -// TODO(bep) 2errors -func _TestPageRawContent(t *testing.T) { +func TestPageRawContent(t *testing.T) { t.Parallel() cfg, fs := newTestCfg() @@ -784,7 +783,7 @@ title: Raw require.Len(t, s.RegularPages, 1) p := s.RegularPages[0] - require.Contains(t, p.RawContent(), "**Raw**") + require.Equal(t, p.RawContent(), "**Raw**") } @@ -1042,8 +1041,7 @@ func TestWordCountWithAllCJKRunesWithoutHasCJKLanguage(t *testing.T) { testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithAllCJKRunes) } -// TODO(bep) 2errors -func _TestWordCountWithAllCJKRunesHasCJKLanguage(t *testing.T) { +func TestWordCountWithAllCJKRunesHasCJKLanguage(t *testing.T) { t.Parallel() settings := map[string]interface{}{"hasCJKLanguage": true} @@ -1056,8 +1054,7 @@ func _TestWordCountWithAllCJKRunesHasCJKLanguage(t *testing.T) { testAllMarkdownEnginesForPages(t, assertFunc, settings, simplePageWithAllCJKRunes) } -// TODO(bep) 2errors -func _TestWordCountWithMainEnglishWithCJKRunes(t *testing.T) { +func TestWordCountWithMainEnglishWithCJKRunes(t *testing.T) { t.Parallel() settings := map[string]interface{}{"hasCJKLanguage": true} @@ -1164,7 +1161,6 @@ func TestShouldRenderContent(t *testing.T) { render bool }{ {contentNoFrontmatter, true}, - // TODO(bep) 2errors {invalidFrontmatterShortDelim, true}, {renderNoFrontmatter, false}, {contentWithCommentedFrontmatter, true}, {contentWithCommentedTextFrontmatter, true}, diff --git a/hugolib/site_render.go b/hugolib/site_render.go index 6583acd06..a8cdca255 100644 --- a/hugolib/site_render.go +++ b/hugolib/site_render.go @@ -134,8 +134,7 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa if shouldRender { if err := pageOutput.renderResources(); err != nil { - // TODO(bep) 2errors - s.Log.ERROR.Printf("Failed to render resources for page %q: %s", page, err) + s.SendError(page.errorf(err, "failed to render page resources")) continue } } @@ -147,7 +146,7 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa } else { layouts, err = s.layouts(pageOutput) if err != nil { - s.Log.ERROR.Printf("Failed to resolve layout output %q for page %q: %s", outFormat.Name, page, err) + s.Log.ERROR.Printf("Failed to resolve layout for output %q for page %q: %s", outFormat.Name, page, err) continue } } diff --git a/hugolib/site_test.go b/hugolib/site_test.go index 2142025cc..0fd3a397a 100644 --- a/hugolib/site_test.go +++ b/hugolib/site_test.go @@ -451,8 +451,7 @@ func doTestSectionNaming(t *testing.T, canonify, uglify, pluralize bool) { } -// TODO(bep) 2errors -func _TestSkipRender(t *testing.T) { +func TestSkipRender(t *testing.T) { t.Parallel() sources := [][2]string{ {filepath.FromSlash("sect/doc1.html"), "---\nmarkup: markdown\n---\n# title\nsome *content*"}, |