Documentation
¶
Overview ¶
Package storage provides the functionality for interacting with the zet database.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsMD ¶
ContainsMD reports whether a slice of files contains a README.md file.
func SplitZettel ¶
SplitZettel breaks a zettel's contents and assigns it's parts to associated fields: title, body, links, and tags.
Example ¶
existingZettels := getTestZettelMap()
db, err := insertTestZettelMap(existingZettels)
if err != nil {
fmt.Printf("Error inserting zettel map: %v", err)
return
}
defer db.Close()
tx, err := db.Beginx()
if err != nil {
return
}
defer tx.Rollback()
const e = `# Example Title
This is some body text.
It can span multiple lines[^f].
See:
* [20231028013031](../20231028013031) Some linked Zettel
* [20240000003031](../20240000003031) Non-existent Zettel
[^f]: [20231028013031](../20231028013031) Another linked Zettel
#tag1 badTag #tag2`
z := &Zettel{}
SplitZettel(tx, z, e)
fmt.Println("Title:", z.Title)
fmt.Println("Body:")
fmt.Printf("%q\n", z.Body)
fmt.Println("Links:")
for _, l := range z.Links {
fmt.Printf("\t%s\n", l.Content)
}
fmt.Println("Tags:")
for _, t := range z.Tags {
fmt.Printf("\t%s\n", t.Name)
}
Output: Title: Example Title Body: "\nThis is some body text.\nIt can span multiple lines[^f].\n\nSee:\n\n\n" Links: [20231028013031](../20231028013031) Some linked Zettel [20231028013031](../20231028013031) Another linked Zettel Tags: tag1 tag2
Types ¶
type ResultZettel ¶
type ResultZettel struct {
Zettel
// TitleSnippet holds a snippet of the zettel's title as returned by
// the SQLite snippet function. It's typically a substring of the
// title that matches the search query, often with added context for
// highlighting support.
TitleSnippet string `db:"title_snippet"`
// BodySnippet contains a snippet of the zettel's body as returned by
// the SQLite snippet function. Similar to TitleSnippet, it includes
// a part of the body text that matches the search criteria. If a
// match was found, it will be surrounded by additional text to
// support highlighting.
BodySnippet string `db:"body_snippet"`
// TagsSnippet holds a snippet of the zettel's tag line returned by the
// SQLite snippet function. If a match was found, it will be
// surrounded by additional text to support highlighting.
TagsSnippet string `db:"tags_snippet"`
}
type Storage ¶
func NewStorage ¶
NewStorage creates and returns a new Storage instance with a given database connection.
func UpdateDB ¶
UpdateDB initializes the database, retrieve zet state from the database, and updates the database to sync the flat files and the data storage.
func (*Storage) AllZettels ¶
AllZettels returns all existing zettel files with optional sorting. Optional argument should be a valid SQL ORDER BY clause, e.g., "mtime DESC".
func (*Storage) Merge ¶
Merge fetches and merges the content of each linked zettel, creating a single body of text.
func (*Storage) SearchZettels ¶
func (s *Storage) SearchZettels(term, before, after string) ([]ResultZettel, error)
SearchZettels searches the zettelkasten for zettels matching the query. The before and after arguments are used for wrapping any matching text. It returns a slice of Zettels.
type Zettel ¶
type Zettel struct {
ID int `db:"id"` // unique id
Name string `db:"name"` // name of file
Title string `db:"title"` // title of file
Body string `db:"body"` // body of file
Links []Link // links to other zettels
Tags []Tag // zettels tags
Mtime string `db:"mtime"` // modification time
DirName string `db:"dir_name"` // modification time
}