summaryrefslogtreecommitdiffstats
path: root/helpers
diff options
context:
space:
mode:
authorNiklas Fasching <niklas.fasching@gmail.com>2019-10-03 23:27:51 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-10-07 17:30:15 +0200
commit020a6fbd7f6996ed84d80ba6c37fe0d8c2536806 (patch)
treeffe1aa927b6c89830fc5d5782867db2830c11878 /helpers
parentb152216d5c8adbf1bfa4c6fb7b2a50b6866c685e (diff)
Add BaseFs to RenderingContext
The org mode renderer supports including other files [1]. We don't want to allow reading of arbitrary files (go-org defaults to ioutil.ReadFile [2]) but want to make use of the FileSystem abstractions hugo provides. For starters we will allow reading from the content directory only [1]: e.g. `#+INCLUDE: ./foo.py src python` includes `foo.py` as a python source block.
Diffstat (limited to 'helpers')
-rw-r--r--helpers/content.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/helpers/content.go b/helpers/content.go
index f6576c04f..591403cb0 100644
--- a/helpers/content.go
+++ b/helpers/content.go
@@ -27,6 +27,7 @@ import (
"unicode/utf8"
"github.com/gohugoio/hugo/common/maps"
+ "github.com/gohugoio/hugo/hugolib/filesystems"
"github.com/niklasfasching/go-org/org"
bp "github.com/gohugoio/hugo/bufferpool"
@@ -34,6 +35,7 @@ import (
"github.com/miekg/mmark"
"github.com/mitchellh/mapstructure"
"github.com/russross/blackfriday"
+ "github.com/spf13/afero"
jww "github.com/spf13/jwalterweatherman"
"strings"
@@ -466,6 +468,7 @@ func ExtractTOC(content []byte) (newcontent []byte, toc []byte) {
// for a given content rendering.
// By creating you must set the Config, otherwise it will panic.
type RenderingContext struct {
+ BaseFs *filesystems.BaseFs
Content []byte
PageFmt string
DocumentID string
@@ -752,6 +755,9 @@ func getPandocContent(ctx *RenderingContext) []byte {
func orgRender(ctx *RenderingContext, c ContentSpec) []byte {
config := org.New()
config.Log = jww.WARN
+ config.ReadFile = func(filename string) ([]byte, error) {
+ return afero.ReadFile(ctx.BaseFs.Content.Fs, filename)
+ }
writer := org.NewHTMLWriter()
writer.HighlightCodeBlock = func(source, lang string) string {
highlightedSource, err := c.Highlight(source, lang, "")