loam

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Path  string // Path to .loam/index.json
	Index *Index
}

Cache manages the loading, updating, and saving of the index.

func NewCache

func NewCache(vaultPath string) *Cache

NewCache initializes a Cache at the given path.

func (*Cache) Get

func (c *Cache) Get(relPath string, currentMtime time.Time) (*IndexEntry, bool)

Get retrieves an entry if it exists and is fresh. Returns entry and true if hit. Returns nil and false if miss or stale.

func (*Cache) Load

func (c *Cache) Load() error

Load reads the cache from disk. If not found or invalid, returns empty index (no error).

func (*Cache) Prune

func (c *Cache) Prune(keep map[string]bool)

Prune removes entries that are not in the 'keep' set.

func (*Cache) Save

func (c *Cache) Save() error

Save attempts to persist the cache to disk if it's dirty.

func (*Cache) Set

func (c *Cache) Set(relPath string, entry *IndexEntry)

Set updates an entry in the cache.

type Index

type Index struct {
	Version int                    `json:"version"`
	Entries map[string]*IndexEntry `json:"entries"` // Key is relative path (e.g. "notes/foo.md")
	// contains filtered or unexported fields
}

Index represents the persistent cache state.

type IndexEntry

type IndexEntry struct {
	ID           string    `json:"id"`
	Title        string    `json:"title,omitempty"`
	Tags         []string  `json:"tags,omitempty"`
	LastModified time.Time `json:"lastLimit"` // Ensure typo is fixed: LastModified
}

IndexEntry represents collected metadata for a single file.

type Metadata

type Metadata map[string]interface{}

Metadata aliases the flexible YAML frontmatter map.

type Note

type Note struct {
	ID       string   // Typically the filename without extension
	Metadata Metadata // Parsed YAML frontmatter
	Content  string   // The markdown body
}

Note represents a Markdown file with optional YAML frontmatter.

func Parse

func Parse(r io.Reader) (*Note, error)

Parse reads a stream and decodes it into a Note. It detects if the stream starts with a frontmatter block (delimeted by ---).

func (*Note) String

func (n *Note) String() (string, error)

String serializes the note back to Markdown with Frontmatter.

type Vault

type Vault struct {
	Path   string
	Git    *git.Client
	Cache  *Cache
	Logger *slog.Logger
}

Vault represents a directory containing notes backed by Git.

func NewVault

func NewVault(path string, logger *slog.Logger) (*Vault, error)

NewVault creates a Vault instance rooted at the given path. It ensures the path exists and initializes the Git client.

func (*Vault) Commit

func (v *Vault) Commit(msg string) error

Commit persists the staged changes to the Git history.

func (*Vault) Delete

func (v *Vault) Delete(id string) error

Delete removes a note from the vault and stages the deletion in Git.

func (*Vault) List

func (v *Vault) List() ([]Note, error)

List returns a list of all notes in the vault. It scans the directory recursively for .md files and parses them.

func (*Vault) Read

func (v *Vault) Read(id string) (*Note, error)

Read loads a note by its ID (filename without extension). It looks for {ID}.md in the vault root.

func (*Vault) Sync

func (v *Vault) Sync() error

Sync synchronizes the vault with the remote repository. It effectively performs a git pull --rebase and git push.

func (*Vault) Write

func (v *Vault) Write(n *Note) error

Write saves a note to the vault and stages it in Git. It writes the file atomically and calls 'git add'.

Jump to

Keyboard shortcuts

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