Skip to content

Commit ca12f73

Browse files
committed
Pass frontmatter to external helper.
With Pandoc this allows for passing e.g. --- ... bibliography: "content/bibliography.bib" nocite: '@*' link-citations: true --- to create a fully bibliography out of a .bib file.
1 parent 5a82369 commit ca12f73

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

helpers/content.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,15 @@ func ExtractTOC(content []byte) (newcontent []byte, toc []byte) {
453453
// for a given content rendering.
454454
// By creating you must set the Config, otherwise it will panic.
455455
type RenderingContext struct {
456-
Frontmatter map[string]interface{}
457-
Content []byte
458-
PageFmt string
459-
DocumentID string
460-
DocumentName string
461-
Config *BlackFriday
462-
RenderTOC bool
463-
Cfg config.Provider
456+
Frontmatter map[string]interface{}
457+
FrontmatterRaw []byte
458+
Content []byte
459+
PageFmt string
460+
DocumentID string
461+
DocumentName string
462+
Config *BlackFriday
463+
RenderTOC bool
464+
Cfg config.Provider
464465
}
465466

466467
// RenderBytes renders a []byte.
@@ -721,8 +722,8 @@ func getPandocContent(ctx *RenderingContext) []byte {
721722
pathCiteproc, errCiteproc := exec.LookPath("pandoc-citeproc")
722723
if errCiteproc == nil {
723724
if bib, ok := ctx.Frontmatter["bibliography"].(string); ok {
724-
args = append(args, "--bibliography", "content/"+bib)
725-
jww.INFO.Println("Rendering bibliography ", bib, "with", pathCiteproc, "...")
725+
args = append(args, "--filter", "pandoc-citeproc")
726+
jww.INFO.Println("Rendering bibliography", bib, "with", pathCiteproc, "...")
726727
}
727728
}
728729

@@ -737,7 +738,8 @@ func orgRender(ctx *RenderingContext, c ContentSpec) []byte {
737738
}
738739

739740
func externallyRenderContent(ctx *RenderingContext, path string, args []string) []byte {
740-
content := ctx.Content
741+
content := ctx.FrontmatterRaw
742+
content = append(content, ctx.Content...)
741743
cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)
742744

743745
cmd := exec.Command(path, args...)

hugolib/page.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,9 @@ func (p *Page) setAutoSummary() error {
862862

863863
func (p *Page) renderContent(content []byte) []byte {
864864
return p.s.ContentSpec.RenderBytes(&helpers.RenderingContext{
865-
Frontmatter: p.params,
866-
Content: content, RenderTOC: true, PageFmt: p.Markup,
865+
Frontmatter: p.params,
866+
FrontmatterRaw: p.frontmatter,
867+
Content: content, RenderTOC: true, PageFmt: p.Markup,
867868
Cfg: p.Language(),
868869
DocumentID: p.UniqueID(), DocumentName: p.Path(),
869870
Config: p.getRenderingConfig()})

0 commit comments

Comments
 (0)