mirror of
https://github.com/kovetskiy/mark.git
synced 2025-04-23 21:32:41 +08:00
Add subdirectories related templates (#158)
This commit is contained in:
parent
2251e8ad8a
commit
9a4f9ff32d
3
main.go
3
main.go
@ -209,6 +209,7 @@ func processFile(
|
||||
|
||||
for {
|
||||
templates, markdown, recurse, err = includes.ProcessIncludes(
|
||||
filepath.Dir(file),
|
||||
markdown,
|
||||
templates,
|
||||
)
|
||||
@ -221,7 +222,7 @@ func processFile(
|
||||
}
|
||||
}
|
||||
|
||||
macros, markdown, err := macro.ExtractMacros(markdown, templates)
|
||||
macros, markdown, err := macro.ExtractMacros(filepath.Dir(file), markdown, templates)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ var reIncludeDirective = regexp.MustCompile(
|
||||
`(?s)<!--\s*Include:\s*(?P<template>\S+)\s*(\n(?P<config>.*?))?-->`)
|
||||
|
||||
func LoadTemplate(
|
||||
base string,
|
||||
path string,
|
||||
templates *template.Template,
|
||||
) (*template.Template, error) {
|
||||
@ -35,7 +36,7 @@ func LoadTemplate(
|
||||
|
||||
var body []byte
|
||||
|
||||
body, err := ioutil.ReadFile(path)
|
||||
body, err := ioutil.ReadFile(filepath.Join(base, path))
|
||||
if err != nil {
|
||||
err = facts.Format(
|
||||
err,
|
||||
@ -65,6 +66,7 @@ func LoadTemplate(
|
||||
}
|
||||
|
||||
func ProcessIncludes(
|
||||
base string,
|
||||
contents []byte,
|
||||
templates *template.Template,
|
||||
) (*template.Template, []byte, bool, error) {
|
||||
@ -122,7 +124,7 @@ func ProcessIncludes(
|
||||
|
||||
log.Tracef(vardump(facts, data), "including template %q", path)
|
||||
|
||||
templates, err = LoadTemplate(path, templates)
|
||||
templates, err = LoadTemplate(base, path, templates)
|
||||
if err != nil {
|
||||
err = facts.Format(err, "unable to load template")
|
||||
|
||||
|
@ -105,6 +105,7 @@ func (macro *Macro) configure(node interface{}, groups [][]byte) interface{} {
|
||||
}
|
||||
|
||||
func ExtractMacros(
|
||||
base string,
|
||||
contents []byte,
|
||||
templates *template.Template,
|
||||
) ([]Macro, []byte, error) {
|
||||
@ -133,7 +134,7 @@ func ExtractMacros(
|
||||
macro Macro
|
||||
)
|
||||
|
||||
macro.Template, err = includes.LoadTemplate(template, templates)
|
||||
macro.Template, err = includes.LoadTemplate(base, template, templates)
|
||||
if err != nil {
|
||||
err = karma.Format(err, "unable to load template")
|
||||
|
||||
|
@ -41,6 +41,7 @@ func macros(templates *template.Template) ([]macro.Macro, error) {
|
||||
}
|
||||
|
||||
macros, _, err := macro.ExtractMacros(
|
||||
"",
|
||||
[]byte(text(
|
||||
`<!-- Macro: @\{([^}]+)\}`,
|
||||
` Template: ac:link:user`,
|
||||
|
Loading…
x
Reference in New Issue
Block a user