Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "abs-path" to template-format #60

Merged
merged 3 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/template-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
pstuifzand marked this conversation as resolved.
Show resolved Hide resolved
| `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 |
Expand Down
8 changes: 6 additions & 2 deletions internal/core/note_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
Expand Down