Skip to content

Commit 5a82369

Browse files
committed
Generate a bibliography with Pandoc.
--- ... bibliography: "bibliography.bib" --- Cite something [@cite_id]. This adds the pandoc arguments --bibliography content/[file] to Pandoc.
1 parent b84389c commit 5a82369

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

helpers/content.go

+12
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ 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{}
456457
Content []byte
457458
PageFmt string
458459
DocumentID string
@@ -713,7 +714,18 @@ func getPandocContent(ctx *RenderingContext) []byte {
713714
" Leaving pandoc content unrendered.")
714715
return ctx.Content
715716
}
717+
718+
jww.INFO.Println("Rendering", ctx.DocumentName, "with", path, "...")
716719
args := []string{"--mathjax"}
720+
721+
pathCiteproc, errCiteproc := exec.LookPath("pandoc-citeproc")
722+
if errCiteproc == nil {
723+
if bib, ok := ctx.Frontmatter["bibliography"].(string); ok {
724+
args = append(args, "--bibliography", "content/"+bib)
725+
jww.INFO.Println("Rendering bibliography ", bib, "with", pathCiteproc, "...")
726+
}
727+
}
728+
717729
return externallyRenderContent(ctx, path, args)
718730
}
719731

hugolib/page.go

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

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

0 commit comments

Comments
 (0)