core

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2021 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CharsetAlphanum is a charset containing letters and numbers.
	CharsetAlphanum = Charset("0123456789abcdefghijklmnopqrstuvwxyz")
	// CharsetAlphanum is a charset containing hexadecimal characters.
	CharsetHex = Charset("0123456789abcdef")
	// CharsetLetters is a charset containing only letters.
	CharsetLetters = Charset("abcdefghijklmnopqrstuvwxyz")
	// CharsetNumbers is a charset containing only numbers.
	CharsetNumbers = Charset("0123456789")
)
View Source
var (
	// Title of a note.
	StyleTitle = Style("title")
	// Path to notebook file.
	StylePath = Style("path")
	// Searched for term in a note.
	StyleTerm = Style("term")
	// Element to emphasize, for example the short version of a prompt response: [y]es.
	StyleEmphasis = Style("emphasis")
	// Element to understate, for example the content of the note in fzf.
	StyleUnderstate = Style("understate")

	StyleBold          = Style("bold")
	StyleItalic        = Style("italic")
	StyleFaint         = Style("faint")
	StyleUnderline     = Style("underline")
	StyleStrikethrough = Style("strikethrough")
	StyleBlink         = Style("blink")
	StyleReverse       = Style("reverse")
	StyleHidden        = Style("hidden")

	StyleBlack   = Style("black")
	StyleRed     = Style("red")
	StyleGreen   = Style("green")
	StyleYellow  = Style("yellow")
	StyleBlue    = Style("blue")
	StyleMagenta = Style("magenta")
	StyleCyan    = Style("cyan")
	StyleWhite   = Style("white")

	StyleBlackBg   = Style("black-bg")
	StyleRedBg     = Style("red-bg")
	StyleGreenBg   = Style("green-bg")
	StyleYellowBg  = Style("yellow-bg")
	StyleBlueBg    = Style("blue-bg")
	StyleMagentaBg = Style("magenta-bg")
	StyleCyanBg    = Style("cyan-bg")
	StyleWhiteBg   = Style("white-bg")

	StyleBrightBlack   = Style("bright-black")
	StyleBrightRed     = Style("bright-red")
	StyleBrightGreen   = Style("bright-green")
	StyleBrightYellow  = Style("bright-yellow")
	StyleBrightBlue    = Style("bright-blue")
	StyleBrightMagenta = Style("bright-magenta")
	StyleBrightCyan    = Style("bright-cyan")
	StyleBrightWhite   = Style("bright-white")

	StyleBrightBlackBg   = Style("bright-black-bg")
	StyleBrightRedBg     = Style("bright-red-bg")
	StyleBrightGreenBg   = Style("bright-green-bg")
	StyleBrightYellowBg  = Style("bright-yellow-bg")
	StyleBrightBlueBg    = Style("bright-blue-bg")
	StyleBrightMagentaBg = Style("bright-magenta-bg")
	StyleBrightCyanBg    = Style("bright-cyan-bg")
	StyleBrightWhiteBg   = Style("bright-white-bg")
)

Predefined styling rules.

View Source
var NullStyler = nullStyler{}

NullStyler is a Styler with no styling rules.

View Source
var NullTemplate = nullTemplate{}

NullTemplate is a Template always returning an empty string.

View Source
var NullTemplateLoader = nullTemplateLoader{}

NullTemplateLoader a TemplateLoader always returning a NullTemplate.

Functions

This section is empty.

Types

type Case

type Case int

Case represents the letter case to use when generating an ID.

const (
	CaseLower Case = iota + 1
	CaseUpper
	CaseMixed
)

type Charset

type Charset []rune

Charset is a set of characters.

type Collection

type Collection struct {
	// Unique ID of this collection in the Notebook.
	ID CollectionID `json:"id"`
	// Kind of this note collection, such as a tag.
	Kind CollectionKind `json:"kind"`
	// Name of this collection.
	Name string `json:"name"`
	// Number of notes associated with this collection.
	NoteCount int `json:"note_count"`
}

Collection represents a collection, such as a tag.

type CollectionFormatter added in v0.7.0

type CollectionFormatter func(collection Collection) (string, error)

CollectionFormatter formats collections to be printed on the screen.

type CollectionID

type CollectionID int64

CollectionID represents the unique ID of a collection relative to a given NoteIndex implementation.

func (CollectionID) IsValid

func (id CollectionID) IsValid() bool

type CollectionKind

type CollectionKind string

CollectionKind defines a kind of note collection, such as tags.

const (
	CollectionKindTag CollectionKind = "tag"
)

type CollectionRepository

type CollectionRepository interface {

	// FindOrCreate returns the ID of the collection with given kind and name.
	// If the collection does not exist, creates a new one.
	FindOrCreateCollection(name string, kind CollectionKind) (CollectionID, error)

	// FindCollections returns the list of all collections in the repository
	// for the given kind, ordered with the given sorters.
	FindCollections(kind CollectionKind, sorters []CollectionSorter) ([]Collection, error)

	// AssociateNoteCollection creates a new association between a note and a
	// collection, if it does not already exist.
	AssociateNoteCollection(noteID NoteID, collectionID CollectionID) (NoteCollectionID, error)

	// RemoveNoteCollections deletes all collection associations with the given
	// note.
	RemoveNoteAssociations(noteId NoteID) error
}

CollectionRepository persists note collection across sessions.

type CollectionSortField added in v0.7.0

type CollectionSortField int

CollectionSortField represents a collection field used to sort a list of collections.

const (
	// Sort by the collection names.
	CollectionSortName CollectionSortField = iota + 1
	// Sort by the number of notes part of the collection.
	CollectionSortNoteCount
)

type CollectionSorter added in v0.7.0

type CollectionSorter struct {
	Field     CollectionSortField
	Ascending bool
}

CollectionSorter represents an order term used to sort a list of collections.

func CollectionSorterFromString added in v0.7.0

func CollectionSorterFromString(str string) (CollectionSorter, error)

CollectionSorterFromString returns a CollectionSorter from its string representation.

If the input str has for suffix `+`, then the order will be ascending, while descending for `-`. If no suffix is given, then the default order for the sorting field will be used.

func CollectionSortersFromStrings added in v0.7.0

func CollectionSortersFromStrings(strs []string) ([]CollectionSorter, error)

CollectionSortersFromStrings returns a list of CollectionSorter from their string representation.

type Config

type Config struct {
	Note    NoteConfig
	Groups  map[string]GroupConfig
	Format  FormatConfig
	Tool    ToolConfig
	LSP     LSPConfig
	Filters map[string]string
	Aliases map[string]string
	Extra   map[string]string
}

Config holds the user configuration.

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig creates a new Config with the default settings.

func OpenConfig

func OpenConfig(path string, parentConfig Config, fs FileStorage) (Config, error)

OpenConfig creates a new Config instance from its TOML representation stored in the given file.

func ParseConfig

func ParseConfig(content []byte, path string, parentConfig Config) (Config, error)

ParseConfig creates a new Config instance from its TOML representation. path is the config absolute path, from which will be derived the base path for templates.

The parentConfig will be used to inherit default config settings.

func (Config) GroupConfigForPath added in v0.6.0

func (c Config) GroupConfigForPath(path string) (GroupConfig, error)

GroupConfigForPath returns the GroupConfig for the group matching the given path relative to the notebook. Fallback on the root GroupConfig.

func (Config) GroupConfigNamed

func (c Config) GroupConfigNamed(name string) (GroupConfig, error)

GroupConfigNamed returns the GroupConfig for the group with the given name. An empty name matches the root GroupConfig.

func (Config) GroupNameForPath

func (c Config) GroupNameForPath(path string) (string, error)

GroupNameForPath returns the name of the GroupConfig matching the given path, relative to the notebook.

func (Config) RootGroupConfig

func (c Config) RootGroupConfig() GroupConfig

RootGroupConfig returns the default GroupConfig for the root directory and its descendants.

type ContextualNote

type ContextualNote struct {
	Note
	// List of context-sensitive excerpts from the note.
	Snippets []string
}

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 Dir

type Dir struct {
	// Name of the directory, which is the path relative to the notebook's root.
	Name string
	// Absolute path to the directory.
	Path string
	// Name of the config group this directory belongs to, if any.
	Group string
}

Dir represents a directory inside a notebook.

type ErrNoteExists

type ErrNoteExists struct {
	Name string
	Path string
}

ErrNoteExists is an error returned when a note already exists with the generated filename.

func (ErrNoteExists) Error

func (e ErrNoteExists) Error() string

type ErrNotebookNotFound

type ErrNotebookNotFound string

ErrNotebookNotFound is an error returned when a notebook cannot be found at the given path or its parents.

func (ErrNotebookNotFound) Error

func (e ErrNotebookNotFound) Error() string

type FileStorage

type FileStorage interface {

	// WorkingDir returns the current working directory.
	WorkingDir() string

	// Abs makes the given file path absolute if needed, using the FileStorage
	// working directory.
	Abs(path string) (string, error)

	// Rel makes the given absolute file path relative to the current working
	// directory.
	Rel(path string) (string, error)

	// Canonical returns the canonical version of this path, resolving any
	// symbolic link.
	Canonical(path string) string

	// FileExists returns whether a file exists at the given file path.
	FileExists(path string) (bool, error)

	// DirExists returns whether a directory exists at the given file path.
	DirExists(path string) (bool, error)

	// IsDescendantOf returns whether the given path is dir or one of its descendants.
	IsDescendantOf(dir string, path string) (bool, error)

	// Read returns the bytes content of the file at the given file path.
	Read(path string) ([]byte, error)

	// Write creates or overwrite the content at the given file path, creating
	// any intermediate directories if needed.
	Write(path string, content []byte) error
}

FileStorage is a port providing read and write access to a file storage.

type FormatConfig

type FormatConfig struct {
	Markdown MarkdownConfig
}

FormatConfig holds the configuration for document formats, such as Markdown.

type GroupConfig

type GroupConfig struct {
	Paths []string
	Note  NoteConfig
	Extra map[string]string
}

GroupConfig holds the user configuration for a given group of notes.

func (GroupConfig) Clone

func (c GroupConfig) Clone() GroupConfig

Clone creates a copy of the GroupConfig receiver.

func (GroupConfig) IgnoreGlobs added in v0.6.0

func (c GroupConfig) IgnoreGlobs() []string

IgnoreGlobs returns all the Note.Ignore path globs for the group paths, relative to the root of the notebook.

type IDGenerator

type IDGenerator func() string

IDGenerator is a function returning a new ID with each invocation.

type IDGeneratorFactory

type IDGeneratorFactory func(opts IDOptions) func() string

IDGeneratorFactory creates a new IDGenerator function using the given IDOptions.

type IDOptions

type IDOptions struct {
	Length  int
	Charset Charset
	Case    Case
}

IDOptions holds the options used to generate an ID.

type InitOpts added in v0.5.0

type InitOpts struct {
	WikiLinks     bool
	Hashtags      bool
	ColonTags     bool
	MultiwordTags bool
}

InitOpts holds the user preferences when creating a new notebook.

func NewDefaultInitOpts added in v0.9.0

func NewDefaultInitOpts() InitOpts

NewDefaultInitOpts creates a new instance of InitOpts with the default values.

type LSPCompletionConfig added in v0.8.0

type LSPCompletionConfig struct {
	Note LSPCompletionTemplates
}

LSPCompletionConfig holds the LSP auto-completion configuration.

type LSPCompletionTemplates added in v0.8.0

type LSPCompletionTemplates struct {
	Label      opt.String
	FilterText opt.String
	Detail     opt.String
}

LSPCompletionConfig holds the LSP completion templates for a particular completion item type (e.g. note or tag).

type LSPConfig added in v0.5.0

type LSPConfig struct {
	Completion  LSPCompletionConfig
	Diagnostics LSPDiagnosticConfig
}

LSPConfig holds the Language Server Protocol configuration.

type LSPDiagnosticConfig added in v0.5.0

type LSPDiagnosticConfig struct {
	WikiTitle LSPDiagnosticSeverity
	DeadLink  LSPDiagnosticSeverity
}

LSPDiagnosticConfig holds the LSP diagnostics configuration.

type LSPDiagnosticSeverity added in v0.5.0

type LSPDiagnosticSeverity int
const (
	LSPDiagnosticNone    LSPDiagnosticSeverity = 0
	LSPDiagnosticError   LSPDiagnosticSeverity = 1
	LSPDiagnosticWarning LSPDiagnosticSeverity = 2
	LSPDiagnosticInfo    LSPDiagnosticSeverity = 3
	LSPDiagnosticHint    LSPDiagnosticSeverity = 4
)
type Link struct {
	// Label of the link.
	Title string `json:"title"`
	// Destination URI of the link.
	Href string `json:"href"`
	// Type of link, e.g. wiki link.
	Type LinkType `json:"type"`
	// Indicates whether the target is a remote (e.g. HTTP) resource.
	IsExternal bool `json:"isExternal"`
	// Relationships between the note and the linked target.
	Rels []LinkRelation `json:"rels"`
	// Excerpt of the paragraph containing the note.
	Snippet string `json:"snippet"`
	// Start byte offset of the snippet in the note content.
	SnippetStart int `json:"snippetStart"`
	// End byte offset of the snippet in the note content.
	SnippetEnd int `json:"snippetEnd"`
}

Link represents a link in a note to another note or an external resource.

type LinkFilter

type LinkFilter struct {
	Hrefs       []string
	Negate      bool
	Recursive   bool
	MaxDistance int
}

LinkFilter is a note filter used to select notes linking to other ones.

type LinkFormatter

type LinkFormatter func(context LinkFormatterContext) (string, error)

LinkFormatter formats internal links according to user configuration.

func NewCustomLinkFormatter added in v0.5.0

func NewCustomLinkFormatter(config MarkdownConfig, templateLoader TemplateLoader) (LinkFormatter, error)

func NewLinkFormatter

func NewLinkFormatter(config MarkdownConfig, templateLoader TemplateLoader) (LinkFormatter, error)

NewLinkFormatter generates a new LinkFormatter from the user Markdown configuration.

func NewMarkdownLinkFormatter added in v0.5.0

func NewMarkdownLinkFormatter(config MarkdownConfig, onlyHref bool) (LinkFormatter, error)

func NewWikiLinkFormatter added in v0.5.0

func NewWikiLinkFormatter(config MarkdownConfig) (LinkFormatter, error)

type LinkFormatterContext added in v0.7.0

type LinkFormatterContext struct {
	// Filename of the note
	Filename string
	// File path to the note, relative to the notebook root.
	Path string
	// Absolute file path to the note.
	AbsPath string `handlebars:"abs-path"`
	// File path to the note, relative to the current directory.
	RelPath string `handlebars:"rel-path"`
	// Title of the note.
	Title string
	// Metadata extracted from the YAML frontmatter.
	Metadata map[string]interface{}
}

Metadata used to generate a link.

func NewLinkFormatterContext added in v0.7.0

func NewLinkFormatterContext(note MinimalNote, notebookDir string, currentDir string) (LinkFormatterContext, error)

type LinkRelation

type LinkRelation string

LinkRelation defines the relationship between a link's source and target.

const (
	// LinkRelationDown defines the target note as a child of the source.
	LinkRelationDown LinkRelation = "down"
	// LinkRelationDown defines the target note as a parent of the source.
	LinkRelationUp LinkRelation = "up"
)

func LinkRels

func LinkRels(rel ...string) []LinkRelation

LinkRels creates a slice of LinkRelation from a list of strings.

type LinkType added in v0.8.0

type LinkType string

LinkType represents the kind of link, e.g. wiki link.

const (
	LinkTypeImplicit LinkType = "implicit" // No markup, e.g. http://example.com
	LinkTypeMarkdown LinkType = "markdown"
	LinkTypeWikiLink LinkType = "wiki-link"
)

type MarkdownConfig

type MarkdownConfig struct {
	// Hashtags indicates whether #hashtags are supported.
	Hashtags bool
	// ColonTags indicates whether :colon:tags: are supported.
	ColonTags bool
	// MultiwordTags indicates whether #multi-word tags# are supported.
	MultiwordTags bool

	// Format used to generate links between notes.
	// Either "wiki", "markdown" or a custom template. Default is "markdown".
	LinkFormat string
	// Indicates whether a link's path will be percent-encoded.
	// Defaults to true for "markdown" format only, false otherwise.
	LinkEncodePath bool
	// Indicates whether a link's path file extension will be removed.
	LinkDropExtension bool
}

MarkdownConfig holds the configuration for Markdown documents.

type MinimalNote

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{}
}

MinimalNote holds a Note's title and path information, for display purposes.

type NewNoteOpts

type NewNoteOpts struct {
	// Title of the new note.
	Title opt.String
	// Initial content of the note.
	Content string
	// Directory in which to create the note, relative to the root of the notebook.
	Directory opt.String
	// Group this note belongs to.
	Group opt.String
	// Path to a custom template used to render the note.
	Template opt.String
	// Extra variables passed to the templates.
	Extra map[string]string
	// Creation date provided to the templates.
	Date time.Time
	// Don't save the generated note on the file system.
	DryRun bool
}

NewNoteOpts holds the options used to create a new note in a Notebook.

type 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
}

Note holds the metadata and content of a single note.

func (Note) AsMinimalNote added in v0.7.0

func (n Note) AsMinimalNote() MinimalNote

func (Note) Filename added in v0.8.0

func (n Note) Filename() string

Filename returns the filename portion of the note path.

func (Note) FilenameStem added in v0.8.0

func (n Note) FilenameStem() string

FilenameStem returns the filename portion of the note path, excluding its file extension.

type NoteCollectionID

type NoteCollectionID int64

NoteCollectionID represents the unique ID of an association between a note and a collection in a NoteIndex implementation.

func (NoteCollectionID) IsValid

func (id NoteCollectionID) IsValid() bool

type NoteConfig

type NoteConfig struct {
	// Handlebars template used when generating a new filename.
	FilenameTemplate string
	// Extension appended to the filename.
	Extension string
	// Path to the handlebars template used when generating the note content.
	BodyTemplatePath opt.String
	// Language of the note content.
	Lang string
	// Default title to use when none is provided.
	DefaultTitle string
	// Settings used when generating a random ID.
	IDOptions IDOptions
	// Path globs to ignore when indexing notes.
	Ignore []string
}

NoteConfig holds the user configuration used when generating new notes.

type NoteContent added in v0.7.0

type NoteContent struct {
	// Title is the heading of the note.
	Title opt.String
	// Lead is the opening paragraph or section of the note.
	Lead opt.String
	// Body is the content of the note, including the Lead but without the Title.
	Body opt.String
	// Tags is the list of tags found in the note content.
	Tags []string
	// Links is the list of outbound links found in the note.
	Links []Link
	// Additional metadata. For example, extracted from a YAML frontmatter.
	Metadata map[string]interface{}
}

NoteContent holds the data parsed from the note content.

type NoteContentParser added in v0.7.0

type NoteContentParser interface {
	ParseNoteContent(content string) (*NoteContent, error)
}

NoteContentParser parses a note's raw content into its components.

type NoteFindOpts

type NoteFindOpts struct {
	// Filter used to match the notes with FTS predicates.
	Match opt.String
	// Search for exact occurrences of the Match string.
	ExactMatch bool
	// Filter by note hrefs.
	IncludeHrefs []string
	// Filter excluding notes at the given hrefs.
	ExcludeHrefs []string
	// Indicates whether href options can match any portion of a path.
	// This is used for wiki links.
	AllowPartialHrefs bool
	// Filter including notes with the given IDs.
	IncludeIDs []NoteID
	// Filter excluding notes with the given IDs.
	ExcludeIDs []NoteID
	// Filter by tags found in the notes.
	Tags []string
	// Filter the notes mentioning the given ones.
	Mention []string
	// Filter the notes mentioned by the given ones.
	MentionedBy []string
	// Filter to select notes being linked by another one.
	LinkedBy *LinkFilter
	// Filter to select notes linking to another one.
	LinkTo *LinkFilter
	// Filter to select notes which could might be related to the given notes hrefs.
	Related []string
	// Filter to select notes having no other notes linking to them.
	Orphan bool
	// Filter notes created after the given date.
	CreatedStart *time.Time
	// Filter notes created before the given date.
	CreatedEnd *time.Time
	// Filter notes modified after the given date.
	ModifiedStart *time.Time
	// Filter notes modified before the given date.
	ModifiedEnd *time.Time
	// Limits the number of results
	Limit int
	// Sorting criteria
	Sorters []NoteSorter
}

NoteFindOpts holds a set of filtering options used to find notes.

func (NoteFindOpts) ExcludingIDs added in v0.9.0

func (o NoteFindOpts) ExcludingIDs(ids []NoteID) NoteFindOpts

ExcludingIDs creates a new FinderOpts after adding the given IDs to the list of excluded note IDs.

func (NoteFindOpts) IncludingIDs added in v0.9.0

func (o NoteFindOpts) IncludingIDs(ids []NoteID) NoteFindOpts

IncludingIDs creates a new FinderOpts after adding the given IDs to the list of excluded note IDs.

type NoteFormatter

type NoteFormatter func(note ContextualNote) (string, error)

NoteFormatter formats notes to be printed on the screen.

type NoteID

type NoteID int64

NoteID represents the unique ID of a note collection relative to a given NoteIndex implementation.

func (NoteID) IsValid

func (id NoteID) IsValid() bool

type NoteIndex

type NoteIndex interface {
	// Find retrieves the notes matching the given filtering and sorting criteria.
	Find(opts NoteFindOpts) ([]ContextualNote, error)
	// FindMinimal retrieves lightweight metadata for the notes matching the
	// given filtering and sorting criteria.
	FindMinimal(opts NoteFindOpts) ([]MinimalNote, error)

	// FindLinksBetweenNotes retrieves the links between the given notes.
	FindLinksBetweenNotes(ids []NoteID) ([]ResolvedLink, error)

	// FindCollections retrieves all the collections of the given kind.
	FindCollections(kind CollectionKind, sorters []CollectionSorter) ([]Collection, error)

	// Indexed returns the list of indexed note file metadata.
	IndexedPaths() (<-chan paths.Metadata, error)
	// Add indexes a new note.
	Add(note Note) (NoteID, error)
	// Update resets the metadata of an already indexed note.
	Update(note Note) error
	// Remove deletes a note from the index.
	Remove(path string) error

	// Commit performs a set of operations atomically.
	Commit(transaction func(idx NoteIndex) error) error

	// NeedsReindexing returns whether all notes should be reindexed.
	NeedsReindexing() (bool, error)
	// SetNeedsReindexing indicates whether all notes should be reindexed.
	SetNeedsReindexing(needsReindexing bool) error
}

NoteIndex persists and grants access to indexed information about the notes.

type NoteIndexOpts added in v0.8.0

type NoteIndexOpts struct {
	// When true, existing notes will be reindexed.
	Force   bool
	Verbose bool
}

NoteIndexOpts holds the options for the indexing process.

type NoteIndexingStats

type NoteIndexingStats struct {
	// Number of notes in the source.
	SourceCount int `json:"sourceCount"`
	// Number of newly indexed notes.
	AddedCount int `json:"addedCount"`
	// Number of notes modified since last indexing.
	ModifiedCount int `json:"modifiedCount"`
	// Number of notes removed since last indexing.
	RemovedCount int `json:"removedCount"`
	// Duration of the indexing process.
	Duration time.Duration `json:"duration"`
}

NoteIndexingStats holds statistics about a notebook indexing process.

func (NoteIndexingStats) String

func (s NoteIndexingStats) String() string

String implements Stringer

type NoteParser

type NoteParser interface {
	ParseNoteAt(absPath string) (*Note, error)
}

NoteParser parses a note on the file system into a Note model.

type NoteSortField

type NoteSortField int

NoteSortField represents a note field used to sort a list of notes.

const (
	// Sort by creation date.
	NoteSortCreated NoteSortField = iota + 1
	// Sort by modification date.
	NoteSortModified
	// Sort by the file paths.
	NoteSortPath
	// Sort randomly.
	NoteSortRandom
	// Sort by the note titles.
	NoteSortTitle
	// Sort by the number of words in the note bodies.
	NoteSortWordCount
)

type NoteSorter

type NoteSorter struct {
	Field     NoteSortField
	Ascending bool
}

NoteSorter represents an order term used to sort a list of notes.

func NoteSorterFromString

func NoteSorterFromString(str string) (NoteSorter, error)

NoteSorterFromString returns a NoteSorter from its string representation.

If the input str has for suffix `+`, then the order will be ascending, while descending for `-`. If no suffix is given, then the default order for the sorting field will be used.

func NoteSortersFromStrings

func NoteSortersFromStrings(strs []string) ([]NoteSorter, error)

NoteSortersFromStrings returns a list of NoteSorter from their string representation.

type Notebook

type Notebook struct {
	Path   string
	Config Config
	// contains filtered or unexported fields
}

Notebook handles queries and commands performed on an opened notebook.

func NewNotebook

func NewNotebook(
	path string,
	config Config,
	ports NotebookPorts,
) *Notebook

NewNotebook creates a new Notebook instance.

func (*Notebook) DirAt

func (n *Notebook) DirAt(path string) (Dir, error)

DirAt returns a Dir representation of the notebook directory at the given path.

func (*Notebook) FindByHref

func (n *Notebook) FindByHref(href string, allowPartialHref bool) (*MinimalNote, error)

FindByHref retrieves the first note matching the given link href. If allowPartialHref is true, the href can match any unique sub portion of a note path.

func (*Notebook) FindCollections

func (n *Notebook) FindCollections(kind CollectionKind, sorters []CollectionSorter) ([]Collection, error)

FindCollections retrieves all the collections of the given kind.

func (*Notebook) FindLinksBetweenNotes added in v0.8.0

func (n *Notebook) FindLinksBetweenNotes(ids []NoteID) ([]ResolvedLink, error)

FindLinksBetweenNotes retrieves the links between the given notes.

func (*Notebook) FindMatching added in v0.7.0

func (n *Notebook) FindMatching(terms string) (*MinimalNote, error)

FindMatching retrieves the first note matching the given search terms.

func (*Notebook) FindMinimalNote added in v0.7.0

func (n *Notebook) FindMinimalNote(opts NoteFindOpts) (*MinimalNote, error)

FindMinimalNotes retrieves lightweight metadata for the first note matching the given filtering options.

func (*Notebook) FindMinimalNotes

func (n *Notebook) FindMinimalNotes(opts NoteFindOpts) ([]MinimalNote, error)

FindMinimalNotes retrieves lightweight metadata for the notes matching the given filtering options.

func (*Notebook) FindNote added in v0.7.0

func (n *Notebook) FindNote(opts NoteFindOpts) (*Note, error)

FindNote retrieves the first note matching the given filtering options.

func (*Notebook) FindNotes

func (n *Notebook) FindNotes(opts NoteFindOpts) ([]ContextualNote, error)

FindNotes retrieves the notes matching the given filtering options.

func (*Notebook) Index

func (n *Notebook) Index(opts NoteIndexOpts) (stats NoteIndexingStats, err error)

Index indexes the content of the notebook to be searchable.

func (*Notebook) NewCollectionFormatter added in v0.7.0

func (n *Notebook) NewCollectionFormatter(templateString string) (CollectionFormatter, error)

NewCollectionFormatter returns a CollectionFormatter used to format notes with the given template.

func (*Notebook) NewLinkFormatter

func (n *Notebook) NewLinkFormatter() (LinkFormatter, error)

NewLinkFormatter returns a LinkFormatter used to generate internal links between notes.

func (*Notebook) NewNote

func (n *Notebook) NewNote(opts NewNoteOpts) (*Note, error)

NewNote generates a new note in the notebook, index and returns it.

Returns ErrNoteExists if no free filename can be generated for this note.

func (*Notebook) NewNoteFormatter

func (n *Notebook) NewNoteFormatter(templateString string) (NoteFormatter, error)

NewNoteFormatter returns a NoteFormatter used to format notes with the given template.

func (*Notebook) ParseNoteAt added in v0.7.0

func (n *Notebook) ParseNoteAt(absPath string) (*Note, error)

ParseNoteAt implements NoteParser.

func (*Notebook) ParseNoteWithContent added in v0.8.0

func (n *Notebook) ParseNoteWithContent(absPath string, content []byte) (*Note, error)

func (*Notebook) RelPath

func (n *Notebook) RelPath(originalPath string) (string, error)

RelPath returns the path relative to the notebook root to the given path.

func (*Notebook) RequireDirAt

func (n *Notebook) RequireDirAt(path string) (Dir, error)

RequireDirAt is the same as DirAt, but checks that the directory exists before returning the Dir.

func (*Notebook) RootDir

func (n *Notebook) RootDir() Dir

RootDir returns the root directory for this notebook.

type NotebookFactory

type NotebookFactory func(path string, config Config) (*Notebook, error)

NotebookFactory creates a new Notebook instance at the given root path.

type NotebookPorts

type NotebookPorts struct {
	NoteIndex             NoteIndex
	NoteContentParser     NoteContentParser
	TemplateLoaderFactory TemplateLoaderFactory
	IDGeneratorFactory    IDGeneratorFactory
	FS                    FileStorage
	Logger                util.Logger
	OSEnv                 func() map[string]string
}

type NotebookStore

type NotebookStore struct {
	// contains filtered or unexported fields
}

NotebookStore retrieves or creates new notebooks.

func NewNotebookStore

func NewNotebookStore(config Config, ports NotebookStorePorts) *NotebookStore

NewNotebookStore creates a new NotebookStore instance using the given options and port implementations.

func (*NotebookStore) Init

func (ns *NotebookStore) Init(path string, options InitOpts) (*Notebook, error)

Init creates a new notebook at the given file path.

func (*NotebookStore) Open

func (ns *NotebookStore) Open(path string) (*Notebook, error)

Open returns a new Notebook instance for the notebook containing the given file path.

type NotebookStorePorts

type NotebookStorePorts struct {
	NotebookFactory NotebookFactory
	TemplateLoader  TemplateLoader
	FS              FileStorage
}
type ResolvedLink struct {
	Link
	SourceID   NoteID `json:"sourceId"`
	SourcePath string `json:"sourcePath"`
	TargetID   NoteID `json:"targetId"`
	TargetPath string `json:"targetPath"`
}

ResolvedLink represents a link between two indexed notes.

type Style

type Style string

Style is a key representing a single styling rule.

type Styler

type Styler interface {
	// Style formats the given text according to the provided styling rules.
	Style(text string, rules ...Style) (string, error)
	// Style formats the given text according to the provided styling rules,
	// panicking if the rules are unknown.
	MustStyle(text string, rules ...Style) string
}

Styler stylizes text according to predefined styling rules.

A rule key can be either semantic, e.g. "title" or explicit, e.g. "red".

type Template

type Template interface {

	// Styler used to format the templates content.
	Styler() Styler

	// Render generates this template using the given variable context.
	Render(context interface{}) (string, error)
}

Template produces a string using a given context.

type TemplateFunc

type TemplateFunc func(context interface{}) (string, error)

TemplateFunc is an adapter to use a function as a Template.

func (TemplateFunc) Render

func (f TemplateFunc) Render(context interface{}) (string, error)

Render implements Template.

func (TemplateFunc) Styler

func (f TemplateFunc) Styler() Styler

Styler implements Template.

type TemplateLoader

type TemplateLoader interface {
	// LoadTemplate creates a Template instance from a string template.
	LoadTemplate(template string) (Template, error)

	// LoadTemplate creates a Template instance from a template stored in the
	// file at the given path.
	// The path may be relative to template directories registered to the loader.
	LoadTemplateAt(path string) (Template, error)
}

TemplateLoader parses a string into a new Template instance.

type TemplateLoaderFactory

type TemplateLoaderFactory func(language string) (TemplateLoader, error)

TemplateLoaderFactory creates a new instance of an implementation of the TemplateLoader port.

type ToolConfig

type ToolConfig struct {
	Editor     opt.String
	Pager      opt.String
	FzfPreview opt.String
	FzfLine    opt.String
}

ToolConfig holds the external tooling configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL