feat: added the source path to the runtime.

This commit is contained in:
Andrey Parhomenko 2024-06-14 23:53:29 +05:00
parent c9e78e8b7e
commit 3266727e1e
2 changed files with 4 additions and 0 deletions

View file

@ -17,4 +17,5 @@ type ContextValues struct {
IsIndex bool IsIndex bool
IndexSuffix string IndexSuffix string
Ext string Ext string
SourcePath string
} }

View file

@ -77,6 +77,7 @@ func DefaultPP(mod string) *tpp.Preprocessor {
s.Add("__is_index__", vals.IsIndex) s.Add("__is_index__", vals.IsIndex)
s.Add("__index_suffix__", vals.IndexSuffix) s.Add("__index_suffix__", vals.IndexSuffix)
s.Add("__tpp_ext__", vals.Ext) s.Add("__tpp_ext__", vals.Ext)
s.Add("__source_path__", vals.SourcePath)
}).SetPreCode(func(ctx context.Context) []byte { }).SetPreCode(func(ctx context.Context) []byte {
return []byte(` return []byte(`
markdown := func(...args) { markdown := func(...args) {
@ -92,6 +93,7 @@ func DefaultPP(mod string) *tpp.Preprocessor {
context.is_index = __is_index__ context.is_index = __is_index__
context.index_suffix = __index_suffix__ context.index_suffix = __index_suffix__
context.tpp_ext = __tpp_ext__ context.tpp_ext = __tpp_ext__
context.source_path = __source_path__
import("./pre")(context) import("./pre")(context)
`) `)
@ -171,6 +173,7 @@ func (h *Handler) ServeHTTP(
IsIndex: isIndex, IsIndex: isIndex,
IndexSuffix: h.indexSuffix, IndexSuffix: h.indexSuffix,
Ext: h.ext, Ext: h.ext,
SourcePath: h.sourcePath,
}, },
) )