Add context to asciidoc/-tor error logging
authorC. Hoeppler <hoeppler@gmx.net>
Thu, 13 Oct 2016 08:30:43 +0000 (10:30 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 13 Oct 2016 11:48:43 +0000 (13:48 +0200)
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

helpers/content.go
hugolib/page.go
hugolib/shortcode.go

index f2909f20838a0612226914c081f02fa8c3ebabe8..516fc72b975d53b6fa1616578c458263707383c4 100644 (file)
@@ -354,6 +354,7 @@ type RenderingContext struct {
        Content        []byte
        PageFmt        string
        DocumentID     string
+       DocumentName   string
        Config         *Blackfriday
        RenderTOC      bool
        FileResolver   FileResolverFunc
@@ -383,7 +384,7 @@ func RenderBytes(ctx *RenderingContext) []byte {
        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 @@ func HasAsciidoc() bool {
 
 // 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 @@ func getAsciidocContent(content []byte) []byte {
        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 {
index abd56b3ea91c0e6dbad9d04c2fc8e354e80a8e50..d2205e32ff6851f5b4d2e9f79531655cc79f8f31 100644 (file)
@@ -380,7 +380,8 @@ func (p *Page) renderContent(content []byte) []byte {
        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 {
index 88c06baf5fc16c1f62474e7dc12b752879aabcb3..0b583b75360e46365b4c9a6b824d67dd89f2e1bf 100644 (file)
@@ -243,7 +243,9 @@ func renderShortcode(sc shortcode, parent *ShortcodeWithPage, p *Page, t tpl.Tem
                        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