2021-04-14 18:14:01 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2021-10-23 17:24:46 +00:00
|
|
|
"path/filepath"
|
2021-04-14 18:14:01 +00:00
|
|
|
"time"
|
2021-10-23 17:24:46 +00:00
|
|
|
|
2024-01-10 21:47:22 +00:00
|
|
|
"github.com/zk-org/zk/internal/util/paths"
|
2021-04-14 18:14:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NoteID represents the unique ID of a note collection relative to a given
|
|
|
|
// NoteIndex implementation.
|
|
|
|
type NoteID int64
|
|
|
|
|
|
|
|
func (id NoteID) IsValid() bool {
|
|
|
|
return id > 0
|
|
|
|
}
|
|
|
|
|
2021-09-25 17:28:29 +00:00
|
|
|
// MinimalNote holds a Note's title and path information, for display purposes.
|
|
|
|
type MinimalNote struct {
|
|
|
|
// Unique ID of this note in a notebook.
|
|
|
|
ID NoteID
|
|
|
|
// Path relative to the root of the notebook.
|
|
|
|
Path string
|
|
|
|
// Title of the note.
|
|
|
|
Title string
|
|
|
|
// JSON dictionary of raw metadata extracted from the frontmatter.
|
|
|
|
Metadata map[string]interface{}
|
|
|
|
}
|
|
|
|
|
2021-04-14 18:14:01 +00:00
|
|
|
// Note holds the metadata and content of a single note.
|
|
|
|
type Note struct {
|
|
|
|
// Unique ID of this note in a NoteRepository.
|
|
|
|
ID NoteID
|
|
|
|
// Path relative to the root of the notebook.
|
|
|
|
Path string
|
|
|
|
// Title of the note.
|
|
|
|
Title string
|
|
|
|
// First paragraph from the note body.
|
|
|
|
Lead string
|
|
|
|
// Content of the note, after any frontmatter and title heading.
|
|
|
|
Body string
|
|
|
|
// Whole raw content of the note.
|
|
|
|
RawContent string
|
|
|
|
// Number of words found in the content.
|
|
|
|
WordCount int
|
|
|
|
// List of outgoing links (internal or external) found in the content.
|
|
|
|
Links []Link
|
|
|
|
// List of tags found in the content.
|
|
|
|
Tags []string
|
|
|
|
// JSON dictionary of raw metadata extracted from the frontmatter.
|
|
|
|
Metadata map[string]interface{}
|
|
|
|
// Date of creation.
|
|
|
|
Created time.Time
|
|
|
|
// Date of last modification.
|
|
|
|
Modified time.Time
|
|
|
|
// Checksum of the note content.
|
|
|
|
Checksum string
|
|
|
|
}
|
|
|
|
|
2021-09-25 17:28:29 +00:00
|
|
|
func (n Note) AsMinimalNote() MinimalNote {
|
|
|
|
return MinimalNote{
|
|
|
|
ID: n.ID,
|
|
|
|
Path: n.Path,
|
|
|
|
Title: n.Title,
|
|
|
|
Metadata: n.Metadata,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-23 17:24:46 +00:00
|
|
|
// Filename returns the filename portion of the note path.
|
|
|
|
func (n Note) Filename() string {
|
|
|
|
return filepath.Base(n.Path)
|
|
|
|
}
|
|
|
|
|
|
|
|
// FilenameStem returns the filename portion of the note path, excluding its
|
|
|
|
// file extension.
|
|
|
|
func (n Note) FilenameStem() string {
|
|
|
|
return paths.FilenameStem(n.Path)
|
|
|
|
}
|
|
|
|
|
2021-04-14 18:14:01 +00:00
|
|
|
// ContextualNote holds a Note and context-sensitive content snippets.
|
|
|
|
//
|
|
|
|
// This is used for example:
|
|
|
|
// * to show an excerpt with highlighted search terms
|
|
|
|
// * when following links, to print the source paragraph
|
|
|
|
type ContextualNote struct {
|
|
|
|
Note
|
|
|
|
// List of context-sensitive excerpts from the note.
|
|
|
|
Snippets []string
|
|
|
|
}
|