zk

package
v0.0.0-...-3628093 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2023 License: BSD-2-Clause Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitZK

func InitZK(root string) error

InitZK will initialize a new zk with the specified path as the root directory. If the path already exists, it must be empty.

Types

type GrepResult

type GrepResult struct {
	Note  NoteMeta
	Line  string
	Error error
}

GrepResult contains a single matching line returned from the Grep function. The Note field is the id of the note which matched The Line field is the text of the note which matched.

type Note

type Note struct {
	NoteMeta
	Body string
}

type NoteMeta

type NoteMeta struct {
	Id       int
	Title    string
	Subnotes []int
	Files    []string
	Parent   int
}

func (*NoteMeta) Equal

func (o *NoteMeta) Equal(n NoteMeta) bool

type ZK

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

func NewZK

func NewZK(root string) (z *ZK, err error)

NewZK creates a ZK object rooted at the specified directory. The directory should have been previously initialized with the InitZK function.

func (*ZK) AddAlias

func (z *ZK) AddAlias(id int, name string) error

AddAlias installs an alias, allowing the note with the given id to be referred to by the specified name.

func (*ZK) AddFile

func (z *ZK) AddFile(id int, path string, dstName string) error

AddFile copies the file at the specified path into the given note's files. If dstName is not empty, the resulting file will be given that name.

func (*ZK) Aliases

func (z *ZK) Aliases() map[string]int

Aliases returns a *copy* of the map of aliases

func (*ZK) Close

func (z *ZK) Close()

func (*ZK) GetFilePath

func (z *ZK) GetFilePath(id int, name string) (string, error)

GetFilePath returns an absolute path to a given file within a note

func (*ZK) GetFileReader

func (z *ZK) GetFileReader(id int, name string) (io.Reader, error)

GetFileReader returns an io.Reader attached to the specified file within a note

func (*ZK) GetNote

func (z *ZK) GetNote(id int) (note Note, err error)

GetNote returns the full contents of the specified note ID, including the body. Unlike GetNoteMeta, it actually reads from the disk and will update the in-memory state if out of sync.

func (*ZK) GetNoteBodyPath

func (z *ZK) GetNoteBodyPath(id int) (path string, err error)

GetNoteBodyPath returns an absolute path to the given note's body file, suitable for passing to an editor. Note that changing the note's title here by editing this file will not change the title in the in-memory metadata until GetNote, Rescan, or another function which reads and parses the on-disk files is called.

func (*ZK) GetNoteMeta

func (z *ZK) GetNoteMeta(id int) (md NoteMeta, err error)

func (*ZK) GetOrphans

func (z *ZK) GetOrphans() (orphans []NoteMeta)

GetOrphans returns a list of "orphaned" notes, notes which are not the subnote of any other note.

func (*ZK) Grep

func (z *ZK) Grep(pattern string, notes []int) (c chan *GrepResult, err error)

Grep searches note bodies for a regular expression and returns a channel of *GrepResult. If the notes parameter is non-empty, it will restrict the search to only the specified note IDs.

func (*ZK) LinkNote

func (z *ZK) LinkNote(parent, id int) error

LinkNote links the specified note as a child of the parent note.

func (*ZK) MetadataDump

func (z *ZK) MetadataDump() map[int]NoteMeta

MetadataDump returns the entire contents of the in-memory state. This can be useful when walking the entire tree.

func (*ZK) NewNote

func (z *ZK) NewNote(parent int, body string) (int, error)

func (*ZK) RemoveAlias

func (z *ZK) RemoveAlias(name string)

RemoveAlias removes the specified alias.

func (*ZK) RemoveFile

func (z *ZK) RemoveFile(id int, name string) error

RemoveFile removes the specified file from the note.

func (*ZK) Rescan

func (z *ZK) Rescan() error

Rescan will attempt to re-derive the state from the contents of the zk directory. Useful if you have manually messed with the directories, or if things just seem out of sync.

func (*ZK) ResolveNoteId

func (z *ZK) ResolveNoteId(name string) (int, error)

ResolveNoteId returns the numeric ID from a string name. You'll use this to determine if the user has specified an exact ID or an alias.

func (*ZK) TreeGrep

func (z *ZK) TreeGrep(pattern string, root int) (c chan *GrepResult, err error)

TreeGrep searches note bodies for a regular expression. It takes as arguments a regular expression string and a note ID. That note, and the entire tree of subnotes below it, are searched.

func (*ZK) UnlinkNote

func (z *ZK) UnlinkNote(parent, id int) error

UnlinkNote removes the specified note from the parent note's subnotes

func (*ZK) UpdateNote

func (z *ZK) UpdateNote(id int, body string) error

Jump to

Keyboard shortcuts

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