Documentation ¶
Index ¶
- type Collection
- func (collection *Collection) Add(entry *Entry) error
- func (collection *Collection) AddMany(entries ...*Entry) error
- func (collection *Collection) Delete(entry *Entry) error
- func (collection *Collection) Filter(filters ...Filter) (*Collection, error)
- func (collection *Collection) FindLinksTo(entry *Entry) []Link
- func (collection *Collection) In(entry *Entry) bool
- func (collection *Collection) Len() int
- func (collection *Collection) List() List
- func (collection *Collection) ResolveLink(link Link) *Entry
- type Entry
- type ErrEntryAlreadyExists
- type ErrEntryDoesntExist
- type ErrEntryParseFailed
- type ErrEntryReadFailed
- type ErrListOutOfBounds
- type Filter
- func FilterAnd(filters ...Filter) Filter
- func FilterContentsExact(contents ...string) Filter
- func FilterContentsMatch(substrings ...string) Filter
- func FilterFrom(date time.Time) Filter
- func FilterLength(length int) Filter
- func FilterNot(filters ...Filter) Filter
- func FilterOr(filters ...Filter) Filter
- func FilterPathsExact(paths ...string) Filter
- func FilterPathsMatch(paths ...string) Filter
- func FilterTags(tags ...string) Filter
- func FilterTitlesExact(titles ...string) Filter
- func FilterTitlesMatch(titles ...string) Filter
- func FilterUntil(date time.Time) Filter
- type Link
- type LinkType
- type List
- type Parser
- type Query
- type SortType
- type SortableByAlpha
- type SortableByDate
- type SortableByPathAlpha
- type YAMLFrontMatter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection represents a searchable collection of entries. It can be used to resolve links.
func DirGraph ¶
func DirGraph(path string) (graph *Collection, entryErrs []error, err error)
DirGraph returns an Collection built from a directory. It will return an Collection, a list of errors that occured while parsing entries and finally an error that occured when processing the directory or adding an entry.
func NewCollection ¶
func NewCollection() *Collection
NewCollection returns a new, initialised Collection.
func (*Collection) Add ¶
func (collection *Collection) Add(entry *Entry) error
Add adds an entry to the entry collection. If it already exists, it will return an ErrEntryAlreadyExists.
func (*Collection) AddMany ¶
func (collection *Collection) AddMany(entries ...*Entry) error
AddMany adds multiple Entries to the collection at once. It is a shorthand for manually calling .Add on every argument.
func (*Collection) Delete ¶
func (collection *Collection) Delete(entry *Entry) error
Delete removes an entry from the entry collection. If doesn't exist, it will return an ErrEntryDoesntExist.
func (*Collection) Filter ¶
func (collection *Collection) Filter(filters ...Filter) (*Collection, error)
Filter runs the filters specified on the entries collection. It returns a copy of the entries collection.
func (*Collection) FindLinksTo ¶
func (collection *Collection) FindLinksTo(entry *Entry) []Link
FindLinksTo returns a list of links present in the collection which link to the entry specified..
func (*Collection) In ¶
func (collection *Collection) In(entry *Entry) bool
In returns true if the entry exists in the collection. It returns false otherwise.
func (*Collection) Len ¶
func (collection *Collection) Len() int
Len returns the amount of entries in the collection.
func (*Collection) List ¶
func (collection *Collection) List() List
List converts the collection into an List.
func (*Collection) ResolveLink ¶
func (collection *Collection) ResolveLink(link Link) *Entry
ResolveLink takes a link and returns the entry that this link points to. TODO: come up with a better way of handling links which match multiple entries (because they share titles). At the moment it returns the first match. If it can't find the matching entry, it will return nil.
type Entry ¶
type Entry struct { // Path to entry file. Path string `json:"path"` // Contents is the contents of the file without front matter. Contents string `json:"contents"` // OriginalContents is the contents of the file with the front matter. OriginalContents string `json:"originalContents"` // Tags are all the tags present in the document. For example, "@!journal". Tags []string `json:"tags"` // OutboundLinks are links going from this entry to another one. // These are known when the entry is parsed. OutboundLinks []Link `json:"outboundLinks"` // Date extracted from the entry. Date time.Time `json:"date"` // ModTime is the modification time for the entry. // Note: this is not always accurate, since encrypting and decryting all the files will "modify" them. Therefore it cannot be used for sorting // accurately. ModTime time.Time `json:"mod_time"` // Title of the entry. Title string `json:"title"` // Metadata is all the front-matter. Metadata map[string]interface{} `json:"metadata"` }
Entry represents a parsed `entry.md` file.
func NewEntryFromFile ¶
NewEntryFromFile returns a new Entry given a file system and a path to the `entry.md` file in that file system. It will return an error if the entry cannot be read.
type ErrEntryAlreadyExists ¶
ErrEntryAlreadyExists is returned by an EntryGraph when you attempt to add a duplicate entry.
func (ErrEntryAlreadyExists) Error ¶
func (e ErrEntryAlreadyExists) Error() string
Error returns a string representing the error.
type ErrEntryDoesntExist ¶
ErrEntryDoesntExist is returned by an EntryGraph when you attempt to delete a non-existant entry.
func (ErrEntryDoesntExist) Error ¶
func (e ErrEntryDoesntExist) Error() string
Error returns a string representing the error.
type ErrEntryParseFailed ¶
ErrEntryParseFailed is returned when the entry.md file cannot be parsed.
func (ErrEntryParseFailed) Error ¶
func (e ErrEntryParseFailed) Error() string
Error returns a string representing the error.
func (ErrEntryParseFailed) Unwrap ¶
func (e ErrEntryParseFailed) Unwrap() error
Unwrap returns the error embedded in the ErrEntryParseFailed.
type ErrEntryReadFailed ¶
ErrEntryReadFailed is returned when an entry cannot be read.
func (ErrEntryReadFailed) Error ¶
func (e ErrEntryReadFailed) Error() string
Error returns a string representing the error.
func (ErrEntryReadFailed) Unwrap ¶
func (e ErrEntryReadFailed) Unwrap() error
Unwrap returns the error embedded in the ErrEntryReadFailed.
type ErrListOutOfBounds ¶
ErrListOutOfBounds is returned by an Entry list when an attempt to get out of bounds data is made.
func (ErrListOutOfBounds) Error ¶
func (e ErrListOutOfBounds) Error() string
Error returns a string representing the error.
type Filter ¶
Filter is a function which returns true or false depending on whether an entry matches given criteria.
func FilterAnd ¶
FilterAnd takes multiple filters and creates a new filter. This new filter will only be true if all the filters it contains return true, i.e. an AND operation.
func FilterContentsExact ¶
FilterContentsExact will allow entries with matching contents (i.e. the content contains one of the substrings specified).
func FilterContentsMatch ¶
FilterContentsMatch will allow entries with matching contents (i.e. the content contains one of the substrings specified).
func FilterFrom ¶
FilterFrom will remove all entries before the given date.
func FilterLength ¶
FilterLength will remove all entries under the given length.
func FilterNot ¶
FilterNot takes a filter and negates it. For example,
FilterNot(FilterPathsMatch)
will remove all matching paths. If multiple filters are given, they are converted into one using FilterAnd.
func FilterOr ¶
FilterOr takes multiple filters and creates a new filter. This new filter will be true if any of the filters it contains return true, i.e. an OR operation.
func FilterPathsExact ¶
FilterPathsExact will allow only an entry with the given path. If a path is given which contains entries itself, only the parent path will be allowed.
func FilterPathsMatch ¶
FilterPathsMatch will allow only entries from the given paths. If a path is given which contains entries itself, all the entries inside that path are also allowed.
func FilterTags ¶
FilterTags only allows entries with the given tags.
func FilterTitlesExact ¶
FilterTitlesExact which match the given titles. This function matches exact titles, not substrings.
func FilterTitlesMatch ¶
FilterTitlesMatch which match the given titles. This function will allow entries where the title given is a substring.
func FilterUntil ¶
FilterUntil will remove all entries after the given date.
type Link ¶
type Link struct { // Parent is the entry that is being linked from. Parent *Entry `json:"-"` // Path is the path to the entry being linked to. This is blank if it's a title link. Path string `json:"path"` // Title is the title of the entry being linked to. This is blank if it's a path link. Title string `json:"title"` // Name is the name of the link. If no other name was specified, this is blank. Name string `json:"name"` // Type is the type of link. Type LinkType `json:"type"` // Loc is the location of the link in the entry text, represented by a two-element slice of the start and and positions. // The link text itself is at strippedContents[Loc[0]:Loc[1]] Loc []int `json:"loc"` }
Link represents an outbound link from one Entry to another.
type LinkType ¶
type LinkType int
LinkType represents a type of link. This could be: - A link by title (LinkTitleNoName), e.g. "[[Pizza]]" - A link by title with a name (LinkTitleWithName), e.g. "[[Pizza](Alternate name)]" - A link by path (LinkPathNoName), e.g. "{{food/pizza}}" - A link by path with a name (LinkPathWithName), e.g. "{{food/pizza}(Altername name)"
const ( // LinkTitleNoName is a link by title, e.g. "[[Pizza]]" LinkTitleNoName LinkType = iota // LinkTitleWithName is a link by title with a name, e.g. "[[Pizza](Alternate name)]" LinkTitleWithName // LinkPathNoName is a link by path, e.g. "{{food/pizza}}" LinkPathNoName // LinkPathWithName is a link by path with a name, e.g. "{{food/pizza}(Altername name)" LinkPathWithName )
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is a list of entries.
func (List) First ¶
First returns the first N entries in the list. If there's not N entries, it will return as many as possible.
func (List) FromOffset ¶
FromOffset returns n entries from a given offset. If there aren't enough entries from offset, it will return as many as it can. If offset is out of bounds, it will return an ErrListOutOfbounds
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser represents an entry parser.
func (Parser) Parse ¶
Parse the content of an `entry.md` file into an Entry struct. It does this in 4 stages: 1. Parse the front matter and remove it from the entry's content. 2. Gets a title and date value from the entry content if they weren't specified in the front-matter. 3. Parse tags. 4. Parse links.
type Query ¶
type Query struct { From time.Time Until time.Time MinLength int MaxLength int Tags []string TagsExclude []string ContentsExact [][]string ContentsMatch [][]string ContentsExactExclude [][]string ContentsMatchExclude [][]string PathsExact [][]string PathsMatch [][]string PathsExactExclude [][]string PathsMatchExclude [][]string TitlesExact [][]string TitlesMatch [][]string TitlesExactExclude [][]string TitlesMatchExclude [][]string }
Query represents a high-level specification of what entries should match. For options like ContentsMatch, they are specified as a slice of slices. Each sub-slice contains the arguments to the call to their matching filter function. So multiple slices will become multiple, seperate filter calls. This means options within sub-slices act as OR -- entries matching either criteria will be allowed. The sub-slices themselves will act as AND, meaning entries have to match all criteria to be allowed.
Consider the difference between:
TitlesMatch: [][]string{{"Pizza", "Bananas"}} // Match any titles with Pizza OR Bananas TitlesMatch: [][]string{{"Pizza"}, {"Bananas"}} // Match any titles with both Pizza AND Bananas
type SortableByAlpha ¶
type SortableByAlpha []*Entry
SortableByAlpha implements sort.Interface for []*Entry based on the alphabetical ordering of titles. Courtesy of this StackOverflow answer: https://stackoverflow.com/questions/35076109/in-golang-how-can-i-sort-a-list-of-strings-alphabetically-without-completely-ig
func (SortableByAlpha) Len ¶
func (es SortableByAlpha) Len() int
func (SortableByAlpha) Less ¶
func (es SortableByAlpha) Less(i, j int) bool
func (SortableByAlpha) Swap ¶
func (es SortableByAlpha) Swap(i, j int)
type SortableByDate ¶
type SortableByDate []*Entry
SortableByDate implements the sort.Interface for []*Entry based on entry dates.
func (SortableByDate) Len ¶
func (es SortableByDate) Len() int
func (SortableByDate) Less ¶
func (es SortableByDate) Less(i, j int) bool
func (SortableByDate) Swap ¶
func (es SortableByDate) Swap(i, j int)
type SortableByPathAlpha ¶
type SortableByPathAlpha []*Entry
SortableByPathAlpha implements sort.Interface for []*Entry based on the alphabetical ordering of titles. Courtesy of this StackOverflow answer: https://stackoverflow.com/questions/35076109/in-golang-how-can-i-sort-a-list-of-strings-alphabetically-without-completely-ig
func (SortableByPathAlpha) Len ¶
func (es SortableByPathAlpha) Len() int
func (SortableByPathAlpha) Less ¶
func (es SortableByPathAlpha) Less(i, j int) bool
func (SortableByPathAlpha) Swap ¶
func (es SortableByPathAlpha) Swap(i, j int)
type YAMLFrontMatter ¶
type YAMLFrontMatter struct { Date string `yaml:"date"` Title string `yaml:"title"` Tags []string `yaml:"tags"` }
YAMLFrontMatter represents the normal YAML front matter at the start of an entry.