mirror of
https://github.com/kovetskiy/mark.git
synced 2025-04-24 05:42:40 +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 {
|
for {
|
||||||
templates, markdown, recurse, err = includes.ProcessIncludes(
|
templates, markdown, recurse, err = includes.ProcessIncludes(
|
||||||
|
filepath.Dir(file),
|
||||||
markdown,
|
markdown,
|
||||||
templates,
|
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 {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ var reIncludeDirective = regexp.MustCompile(
|
|||||||
`(?s)<!--\s*Include:\s*(?P<template>\S+)\s*(\n(?P<config>.*?))?-->`)
|
`(?s)<!--\s*Include:\s*(?P<template>\S+)\s*(\n(?P<config>.*?))?-->`)
|
||||||
|
|
||||||
func LoadTemplate(
|
func LoadTemplate(
|
||||||
|
base string,
|
||||||
path string,
|
path string,
|
||||||
templates *template.Template,
|
templates *template.Template,
|
||||||
) (*template.Template, error) {
|
) (*template.Template, error) {
|
||||||
@ -35,7 +36,7 @@ func LoadTemplate(
|
|||||||
|
|
||||||
var body []byte
|
var body []byte
|
||||||
|
|
||||||
body, err := ioutil.ReadFile(path)
|
body, err := ioutil.ReadFile(filepath.Join(base, path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = facts.Format(
|
err = facts.Format(
|
||||||
err,
|
err,
|
||||||
@ -65,6 +66,7 @@ func LoadTemplate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ProcessIncludes(
|
func ProcessIncludes(
|
||||||
|
base string,
|
||||||
contents []byte,
|
contents []byte,
|
||||||
templates *template.Template,
|
templates *template.Template,
|
||||||
) (*template.Template, []byte, bool, error) {
|
) (*template.Template, []byte, bool, error) {
|
||||||
@ -122,7 +124,7 @@ func ProcessIncludes(
|
|||||||
|
|
||||||
log.Tracef(vardump(facts, data), "including template %q", path)
|
log.Tracef(vardump(facts, data), "including template %q", path)
|
||||||
|
|
||||||
templates, err = LoadTemplate(path, templates)
|
templates, err = LoadTemplate(base, path, templates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = facts.Format(err, "unable to load template")
|
err = facts.Format(err, "unable to load template")
|
||||||
|
|
||||||
|
@ -105,6 +105,7 @@ func (macro *Macro) configure(node interface{}, groups [][]byte) interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ExtractMacros(
|
func ExtractMacros(
|
||||||
|
base string,
|
||||||
contents []byte,
|
contents []byte,
|
||||||
templates *template.Template,
|
templates *template.Template,
|
||||||
) ([]Macro, []byte, error) {
|
) ([]Macro, []byte, error) {
|
||||||
@ -133,7 +134,7 @@ func ExtractMacros(
|
|||||||
macro Macro
|
macro Macro
|
||||||
)
|
)
|
||||||
|
|
||||||
macro.Template, err = includes.LoadTemplate(template, templates)
|
macro.Template, err = includes.LoadTemplate(base, template, templates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = karma.Format(err, "unable to load template")
|
err = karma.Format(err, "unable to load template")
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ func macros(templates *template.Template) ([]macro.Macro, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
macros, _, err := macro.ExtractMacros(
|
macros, _, err := macro.ExtractMacros(
|
||||||
|
"",
|
||||||
[]byte(text(
|
[]byte(text(
|
||||||
`<!-- Macro: @\{([^}]+)\}`,
|
`<!-- Macro: @\{([^}]+)\}`,
|
||||||
` Template: ac:link:user`,
|
` Template: ac:link:user`,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user