shithub: hugo

Download patch

ref: 766c82a6bbf4423a037beb2b1967f720080e4658
parent: 9f9b93af2c379b10d2d5c514cfe5f0658795b9bb
author: C. Hoeppler <[email protected]>
date: Thu Oct 13 06:30:43 EDT 2016

Add context to asciidoc/-tor error logging

Add DocumentName (path to the file being rendered) to RenderingContext
and use that information to include the path in the error print.

See #2399
Closes #2567

--- a/helpers/content.go
+++ b/helpers/content.go
@@ -354,6 +354,7 @@
 	Content        []byte
 	PageFmt        string
 	DocumentID     string
+	DocumentName   string
 	Config         *Blackfriday
 	RenderTOC      bool
 	FileResolver   FileResolverFunc
@@ -383,7 +384,7 @@
 	case "markdown":
 		return markdownRender(ctx)
 	case "asciidoc":
-		return getAsciidocContent(ctx.Content)
+		return getAsciidocContent(ctx)
 	case "mmark":
 		return mmarkRender(ctx)
 	case "rst":
@@ -533,7 +534,8 @@
 
 // getAsciidocContent calls asciidoctor or asciidoc as an external helper
 // to convert AsciiDoc content to HTML.
-func getAsciidocContent(content []byte) []byte {
+func getAsciidocContent(ctx *RenderingContext) []byte {
+	content := ctx.Content
 	cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)
 
 	path := getAsciidocExecPath()
@@ -555,7 +557,7 @@
 	for _, item := range strings.Split(string(cmderr.Bytes()), "\n") {
 		item := strings.TrimSpace(item)
 		if item != "" {
-			jww.ERROR.Println(item)
+			jww.ERROR.Println(strings.Replace(item, "<stdin>", ctx.DocumentName, 1))
 		}
 	}
 	if err != nil {
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -380,7 +380,8 @@
 	return helpers.RenderBytes(&helpers.RenderingContext{
 		Content: content, RenderTOC: true, PageFmt: p.determineMarkupType(),
 		ConfigProvider: p.Language(),
-		DocumentID:     p.UniqueID(), Config: p.getRenderingConfig(), LinkResolver: fn, FileResolver: fileFn})
+		DocumentID:     p.UniqueID(), DocumentName: p.Path(),
+		Config: p.getRenderingConfig(), LinkResolver: fn, FileResolver: fileFn})
 }
 
 func (p *Page) getRenderingConfig() *helpers.Blackfriday {
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -243,7 +243,9 @@
 			newInner := helpers.RenderBytes(&helpers.RenderingContext{
 				Content: []byte(inner), PageFmt: p.determineMarkupType(),
 				ConfigProvider: p.Language(),
-				DocumentID:     p.UniqueID(), Config: p.getRenderingConfig()})
+				DocumentID:     p.UniqueID(),
+				DocumentName:   p.Path(),
+				Config:         p.getRenderingConfig()})
 
 			// If the type is “unknown” or “markdown”, we assume the markdown
 			// generation has been performed. Given the input: `a line`, markdown