From 3266727e1e09e0e015f3351a95650d4f05a70571 Mon Sep 17 00:00:00 2001 From: surdeus Date: Fri, 14 Jun 2024 23:53:29 +0500 Subject: [PATCH] feat: added the source path to the runtime. --- context.go | 1 + handler.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/context.go b/context.go index 5b8813d..55747c7 100644 --- a/context.go +++ b/context.go @@ -17,4 +17,5 @@ type ContextValues struct { IsIndex bool IndexSuffix string Ext string + SourcePath string } diff --git a/handler.go b/handler.go index 2ef2326..588f3f9 100644 --- a/handler.go +++ b/handler.go @@ -77,6 +77,7 @@ func DefaultPP(mod string) *tpp.Preprocessor { s.Add("__is_index__", vals.IsIndex) s.Add("__index_suffix__", vals.IndexSuffix) s.Add("__tpp_ext__", vals.Ext) + s.Add("__source_path__", vals.SourcePath) }).SetPreCode(func(ctx context.Context) []byte { return []byte(` markdown := func(...args) { @@ -92,6 +93,7 @@ func DefaultPP(mod string) *tpp.Preprocessor { context.is_index = __is_index__ context.index_suffix = __index_suffix__ context.tpp_ext = __tpp_ext__ + context.source_path = __source_path__ import("./pre")(context) `) @@ -171,6 +173,7 @@ func (h *Handler) ServeHTTP( IsIndex: isIndex, IndexSuffix: h.indexSuffix, Ext: h.ext, + SourcePath: h.sourcePath, }, )