Add "full-path" to template-format

pull/60/head
Peter Stuifzand 3 years ago
parent dba28a6436
commit 4d893b9bd6

@ -5,6 +5,7 @@ The following variables are available in the templates used when formatting note
| Variable | Type | Description |
|---------------|----------|--------------------------------------------------------------------------|
| `path` | string | File path to the note, relative to the current directory |
| `full-path` | string | File path to the note, full path including the notebook directory |
| `title` | string | Note title |
| `link` | string | Markdown link to the note, relative to the current directory<sup>1</sup> |
| `lead` | string | First paragraph extracted from the note content |

@ -23,14 +23,17 @@ func newNoteFormatter(basePath string, template Template, linkFormatter LinkForm
return "", err
}
fullPath := filepath.Join(basePath, note.Path)
snippets := make([]string, 0)
for _, snippet := range note.Snippets {
snippets = append(snippets, noteTermRegex.ReplaceAllString(snippet, termRepl))
}
return template.Render(noteFormatRenderContext{
Path: path,
Title: note.Title,
Path: path,
FullPath: fullPath,
Title: note.Title,
Link: newLazyStringer(func() string {
link, _ := linkFormatter(path, note.Title)
return link
@ -56,6 +59,7 @@ var noteTermRegex = regexp.MustCompile(`<zk:match>(.*?)</zk:match>`)
// templates.
type noteFormatRenderContext struct {
Path string `json:"path"`
FullPath string `json:"fullPath" handlebars:"full-path"`
Title string `json:"title"`
Link fmt.Stringer `json:"link"`
Lead string `json:"lead"`

Loading…
Cancel
Save