markdown

package
v0.0.0-...-4b60cfd Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MarkdownV2

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

MarkdownV2 implements storage.StorageV2 interface using JSON files. Days are stored as JSON files in a days/ subdirectory. Templates are stored as JSON files in a templates/ subdirectory.

func NewV2

func NewV2(basePath string) (*MarkdownV2, error)

NewV2 creates a new MarkdownV2 storage instance. It ensures the necessary directories exist (days/, templates/).

Parameters:

  • basePath: The base directory where storage files will be created

Returns an error if directory creation fails.

func (*MarkdownV2) Close

func (m *MarkdownV2) Close() error

Close closes the storage connection and releases any resources. For file-based storage, this is a no-op.

func (*MarkdownV2) CreateBlock

func (m *MarkdownV2) CreateBlock(date time.Time, blk block.Block) error

CreateBlock creates a new block for the given date. The date will be normalized to midnight local time. The block's ID, CreatedAt, and UpdatedAt timestamps MUST be set by the caller.

func (*MarkdownV2) CreateTemplate

func (m *MarkdownV2) CreateTemplate(t storage.Template) error

CreateTemplate creates a new template with attributes. The template's ID, CreatedAt, and UpdatedAt timestamps MUST be set by the caller. Implementations SHOULD validate these fields and return ErrValidation if they are missing or invalid.

func (*MarkdownV2) DeleteBlock

func (m *MarkdownV2) DeleteBlock(blockID string) error

DeleteBlock deletes a block by ID. Returns ErrNotFound if the block doesn't exist. Returns ErrValidation if blockID is empty.

func (*MarkdownV2) DeleteDay

func (m *MarkdownV2) DeleteDay(date time.Time) error

DeleteDay deletes a day and all its blocks. Returns ErrNotFound if the day doesn't exist.

func (*MarkdownV2) DeleteTemplate

func (m *MarkdownV2) DeleteTemplate(id string) error

DeleteTemplate deletes a template by ID. Returns ErrNotFound if the template doesn't exist. Returns ErrValidation if id is empty.

func (*MarkdownV2) GetBlock

func (m *MarkdownV2) GetBlock(blockID string) (block.Block, time.Time, error)

GetBlock returns a block by ID along with the date it belongs to. Returns ErrNotFound if the block doesn't exist. Returns ErrValidation if blockID is empty.

func (*MarkdownV2) GetDay

func (m *MarkdownV2) GetDay(date time.Time) (day.Day, error)

GetDay returns the day for the given date, creating an empty day if it doesn't exist. The date parameter will be normalized to midnight local time.

func (*MarkdownV2) GetTemplate

func (m *MarkdownV2) GetTemplate(id string) (storage.Template, error)

GetTemplate returns a template by ID. Returns ErrNotFound if the template doesn't exist. Returns ErrValidation if id is empty.

func (*MarkdownV2) GetTemplateByName

func (m *MarkdownV2) GetTemplateByName(name string) (storage.Template, error)

GetTemplateByName returns a template by name. Returns ErrNotFound if the template doesn't exist. Returns ErrValidation if name is empty.

func (*MarkdownV2) ListBlocks

func (m *MarkdownV2) ListBlocks(date time.Time) ([]block.Block, error)

ListBlocks returns all blocks for the given date, ordered by CreatedAt ascending. Returns an empty slice if no blocks exist for the date.

func (*MarkdownV2) ListDays

func (m *MarkdownV2) ListDays(opts storage.ListDaysOptions) ([]storage.DaySummary, error)

ListDays returns a list of day summaries matching the filter criteria. Days are returned in descending order by date (most recent first). TODO: Implement ListDays - scan days directory, filter by opts, return summaries

func (*MarkdownV2) ListTemplates

func (m *MarkdownV2) ListTemplates() ([]storage.Template, error)

ListTemplates returns all templates ordered by name ascending.

func (*MarkdownV2) SearchBlocks

func (m *MarkdownV2) SearchBlocks(opts storage.SearchOptions) ([]storage.BlockResult, error)

SearchBlocks searches for blocks matching the given criteria. Results are ordered by date descending, then by CreatedAt descending. TODO: Implement SearchBlocks - scan days, filter by attributes/content/date, return results

func (*MarkdownV2) UpdateBlock

func (m *MarkdownV2) UpdateBlock(blockID string, content string, attributes map[string]string) error

UpdateBlock updates the content and attributes of a block. The block's UpdatedAt timestamp will be updated automatically. Returns ErrNotFound if the block doesn't exist. Returns ErrValidation if blockID is empty or content is invalid.

func (*MarkdownV2) UpdateTemplate

func (m *MarkdownV2) UpdateTemplate(id string, name string, content string, attributes map[string]string) (storage.Template, error)

UpdateTemplate updates a template's name, content, and attributes. The template's UpdatedAt timestamp will be updated automatically. Returns the updated template or ErrNotFound if the template doesn't exist. Returns ErrValidation if id or name is empty.

type Store

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

Store implements storage.Storage using Markdown files with YAML front-matter.

func New

func New(dataDir string) (*Store, error)

New creates a new Markdown file storage backend.

func (*Store) AttachContext

func (s *Store) AttachContext(entryID string, contextID string) error

AttachContext adds a context reference to an entry's frontmatter.

func (*Store) Close

func (s *Store) Close() error

Close is a no-op for the Markdown backend.

func (*Store) Create

func (s *Store) Create(e entry.Entry) error

Create persists a new diary entry as a Markdown file.

func (*Store) CreateContext

func (s *Store) CreateContext(c storage.Context) error

CreateContext persists a new context as a JSON file.

func (*Store) CreateTemplate

func (s *Store) CreateTemplate(t storage.Template) error

CreateTemplate persists a new template as a Markdown file.

func (*Store) Delete

func (s *Store) Delete(id string) error

Delete removes an entry permanently.

func (*Store) DeleteContext

func (s *Store) DeleteContext(id string) error

DeleteContext removes a context by ID and detaches it from all entries. To avoid orphaned references, we detach from all entries first, then delete the context file.

func (*Store) DeleteTemplate

func (s *Store) DeleteTemplate(id string) error

DeleteTemplate removes a template by ID.

func (*Store) DetachContext

func (s *Store) DetachContext(entryID string, contextID string) error

DetachContext removes a context reference from an entry's frontmatter.

func (*Store) Get

func (s *Store) Get(id string) (entry.Entry, error)

Get retrieves an entry by ID by scanning the directory tree.

func (*Store) GetContext

func (s *Store) GetContext(id string) (storage.Context, error)

GetContext retrieves a context by ID.

func (*Store) GetContextByName

func (s *Store) GetContextByName(name string) (storage.Context, error)

GetContextByName retrieves a context by name.

func (*Store) GetTemplate

func (s *Store) GetTemplate(id string) (storage.Template, error)

GetTemplate retrieves a template by ID by scanning the templates directory.

func (*Store) GetTemplateByName

func (s *Store) GetTemplateByName(name string) (storage.Template, error)

GetTemplateByName retrieves a template by name.

func (*Store) List

func (s *Store) List(opts storage.ListOptions) ([]entry.Entry, error)

List returns entries matching the given options.

func (*Store) ListContexts

func (s *Store) ListContexts() ([]storage.Context, error)

ListContexts returns all contexts sorted by name.

func (*Store) ListDays

func (s *Store) ListDays(opts storage.ListDaysOptions) ([]storage.DaySummary, error)

ListDays returns aggregated day summaries by scanning the directory tree.

func (*Store) ListTemplates

func (s *Store) ListTemplates() ([]storage.Template, error)

ListTemplates returns all templates sorted by name.

func (*Store) Update

func (s *Store) Update(id string, content string, templates []entry.TemplateRef) (entry.Entry, error)

Update modifies an existing entry's content and optionally its template refs. Pass nil for templates to preserve existing refs.

func (*Store) UpdateTemplate

func (s *Store) UpdateTemplate(id string, name string, content string, attributes map[string]string) (storage.Template, error)

UpdateTemplate modifies an existing template's name, content, and attributes.

Jump to

Keyboard shortcuts

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