Skip to content

Commit a70e6dc

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 d03711b commit a70e6dc

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
@@ -455,14 +455,15 @@ func ExtractTOC(content []byte) (newcontent []byte, toc []byte) {
455455
// for a given content rendering.
456456
// By creating you must set the Config, otherwise it will panic.
457457
type RenderingContext struct {
458-
Frontmatter map[string]interface{}
459-
Content []byte
460-
PageFmt string
461-
DocumentID string
462-
DocumentName string
463-
Config *BlackFriday
464-
RenderTOC bool
465-
Cfg config.Provider
458+
Frontmatter map[string]interface{}
459+
FrontmatterRaw []byte
460+
Content []byte
461+
PageFmt string
462+
DocumentID string
463+
DocumentName string
464+
Config *BlackFriday
465+
RenderTOC bool
466+
Cfg config.Provider
466467
}
467468

468469
// RenderBytes renders a []byte.
@@ -723,8 +724,8 @@ func getPandocContent(ctx *RenderingContext) []byte {
723724
pathCiteproc, errCiteproc := exec.LookPath("pandoc-citeproc")
724725
if errCiteproc == nil {
725726
if bib, ok := ctx.Frontmatter["bibliography"].(string); ok {
726-
args = append(args, "--bibliography", "content/"+bib)
727-
jww.INFO.Println("Rendering bibliography ", bib, "with", pathCiteproc, "...")
727+
args = append(args, "--filter", "pandoc-citeproc")
728+
jww.INFO.Println("Rendering bibliography", bib, "with", pathCiteproc, "...")
728729
}
729730
}
730731

@@ -739,7 +740,8 @@ func orgRender(ctx *RenderingContext, c ContentSpec) []byte {
739740
}
740741

741742
func externallyRenderContent(ctx *RenderingContext, path string, args []string) []byte {
742-
content := ctx.Content
743+
content := ctx.FrontmatterRaw
744+
content = append(content, ctx.Content...)
743745
cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)
744746

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

hugolib/page.go

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

878878
func (p *Page) renderContent(content []byte) []byte {
879879
return p.s.ContentSpec.RenderBytes(&helpers.RenderingContext{
880-
Frontmatter: p.params,
881-
Content: content, RenderTOC: true, PageFmt: p.Markup,
880+
Frontmatter: p.params,
881+
FrontmatterRaw: p.frontmatter,
882+
Content: content, RenderTOC: true, PageFmt: p.Markup,
882883
Cfg: p.Language(),
883884
DocumentID: p.UniqueID(), DocumentName: p.Path(),
884885
Config: p.getRenderingConfig()})

0 commit comments

Comments
 (0)