notes

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package notes is the core data layer: Note type, parser, Obsidian vault detector, file store, and link graph.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoteNotFound = fmt.Errorf("note not found")

ErrNoteNotFound se devuelve cuando no encontramos la nota.

Functions

func ExtractInlineTags

func ExtractInlineTags(content string) []string

ExtractInlineTags finds #tag patterns outside fenced code blocks and URLs. Returns deduplicated tag names without the leading '#'.

func ExtractWikilinks(content string) []string

ExtractWikilinks returns deduplicated [[wikilink]] targets from content. For [[target|display]] only the target part is returned.

func IsObsidianFile

func IsObsidianFile(path string) bool

IsObsidianFile reports whether path lives inside a .obsidian/ or .trash/ folder and should be skipped during vault walks.

func ParseFrontmatter

func ParseFrontmatter(raw string) (frontmatter map[string]interface{}, body string, err error)

ParseFrontmatter splits raw markdown into a YAML frontmatter map and body. Returns an empty map and the full content when no frontmatter is present.

func SortNotes

func SortNotes(notes []*Note, by string)

SortNotes ordena las notas según lo que pidan.

func ToMarkdown

func ToMarkdown(note *Note) string

ToMarkdown serializes a Note to markdown with YAML frontmatter. Always includes id, title, tags, created, updated plus any Extra fields.

Types

type Graph

type Graph struct {
	Nodes map[string]*GraphNode // keyed by note title
}

Graph is an in-memory bidirectional link graph built from a slice of Notes.

func BuildGraph

func BuildGraph(notes []*Note) *Graph

BuildGraph constructs a bidirectional link graph from a slice of notes.

func (*Graph) MostConnected

func (g *Graph) MostConnected(limit int) []*GraphNode

MostConnected returns the top limit nodes by total connections (links + backlinks). A limit ≤ 0 returns all nodes.

func (*Graph) Orphans

func (g *Graph) Orphans() []*GraphNode

Orphans returns nodes with no outgoing links and no backlinks.

func (*Graph) RenderASCII

func (g *Graph) RenderASCII(rootTitle string, depth int) string

RenderASCII renders a Unicode tree rooted at rootTitle up to depth levels deep. Cycles are annotated with "(↺ cycle)". Falls back to a graph summary when rootTitle is not found.

type GraphNode

type GraphNode struct {
	Title     string
	Path      string
	Tags      []string
	Links     []string // outgoing [[wikilinks]]
	Backlinks []string // notes that link to this one
}

GraphNode represents a single note in the link graph.

type ListOptions

type ListOptions struct {
	Tags   []string // Filter by tags (AND logic — note must have ALL tags)
	Query  string   // Case-insensitive substring match against note title
	Limit  int      // Maximum number of results; 0 means no limit
	SortBy string   // "updated" (default), "created", or "title"
}

ListOptions controla cómo filtramos y paginamos las notas.

type Note

type Note struct {
	ID         string // UUID (e.g. "a1b2c3d4-...")
	Title      string // From frontmatter or first H1
	Path       string // Absolute path to the .md file
	RelPath    string // Relative path from vault root (set by caller)
	Content    string // Body content (after frontmatter)
	RawContent string // Full raw file content

	Tags      []string // From frontmatter + inline #tags
	Links     []string // [[wikilink]] targets (note titles)
	BlockRefs []string // ^block-id references
	Aliases   []string // Obsidian aliases field

	Created time.Time
	Updated time.Time

	Extra map[string]interface{} // Extra frontmatter fields preserved
}

Note represents a single markdown note in the vault.

func ParseContent

func ParseContent(raw string, path string) (*Note, error)

ParseContent parses raw markdown (with optional YAML frontmatter) and returns a Note. path is used for title fallback and Note.Path.

func ParseFile

func ParseFile(path string) (*Note, error)

ParseFile reads the markdown file at path and returns a populated Note.

type ObsidianSettings

type ObsidianSettings struct {
	NewFileLocation  string `json:"newFileLocation"`      // "root", "folder", "current"
	DefaultLocation  string `json:"newFileFolderPath"`    // folder for new notes
	AttachmentFolder string `json:"attachmentFolderPath"` // attachment storage path
	UseMarkdownLinks bool   `json:"useMarkdownLinks"`     // true → [text](path)
}

ObsidianSettings holds a subset of Obsidian's app.json relevant to note creation and attachment handling.

type ObsidianVault

type ObsidianVault struct {
	Path       string           // absolute path to vault root
	IsObsidian bool             // true if .obsidian/ was found
	Settings   ObsidianSettings // parsed from .obsidian/app.json
}

ObsidianVault describes a detected (or absent) Obsidian vault.

func DetectObsidianVault

func DetectObsidianVault(vaultPath string) (*ObsidianVault, error)

DetectObsidianVault checks vaultPath for a .obsidian/ directory. When found it reads app.json for user settings. Missing or malformed settings files are silently ignored — the caller always gets a valid struct back.

func (*ObsidianVault) NoteLocation

func (v *ObsidianVault) NoteLocation(_ string) string

NoteLocation returns the directory where a new note should be created, based on Obsidian's newFileLocation setting. Falls back to the vault root when the "current" mode is requested (it requires editor context we don't have).

type Store

type Store struct {
	VaultPath string         // Absolute path to the vault root
	Vault     *ObsidianVault // Detected Obsidian metadata (may be non-Obsidian)
}

Store maneja las notas en disco a partir de la raíz del vault.

func NewStore

func NewStore(vaultPath string) (*Store, error)

NewStore inicializa el store y expande el ~ si viene en la ruta.

func (*Store) Count

func (s *Store) Count() (int, error)

Count cuenta cuántos archivos .md tenemos.

func (*Store) Create

func (s *Store) Create(folder string, title string, tags []string, content string) (*Note, error)

Create genera un UUID, limpia el nombre del archivo y guarda la nota nueva.

func (*Store) Delete

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

Delete mueve la nota a la papelera en lugar de borrarla definitivamente.

func (*Store) DetectPARAFolders

func (s *Store) DetectPARAFolders() []string

DetectPARAFolders revisa si el usuario usa carpetas numeradas (ej. "1. Projects") o normales ("Projects").

func (*Store) ExtraFolders

func (s *Store) ExtraFolders() []string

ExtraFolders devuelve las carpetas raíz que no son del método PARA ni del sistema.

func (*Store) Get

func (s *Store) Get(idOrTitle string) (*Note, error)

Get busca primero por UUID, luego por título y por último por nombre de archivo.

func (*Store) List

func (s *Store) List(opts ListOptions) ([]*Note, error)

List recorre el vault, lee los .md y devuelve los resultados filtrados y ordenados.

func (*Store) Move

func (s *Store) Move(idOrTitle string, targetFolder string) error

Move mueve la nota a otra carpeta del vault.

func (*Store) Reload

func (s *Store) Reload(note *Note) (*Note, error)

Reload vuelve a leer la nota desde el disco.

func (*Store) RenderTemplate

func (s *Store) RenderTemplate(templateName string, title string) (string, error)

RenderTemplate looks for a template file by name (either in .obsidian/templates/ or templates/), and executes it with the provided title and current date.

func (*Store) Tags

func (s *Store) Tags() (map[string]int, error)

Tags devuelve un mapa con la frecuencia de cada etiqueta.

func (*Store) Update

func (s *Store) Update(note *Note) error

Update actualiza la fecha de modificación y reescribe el archivo.

type TemplateData

type TemplateData struct {
	Title string
	Date  string
}

TemplateData holds the variables that can be used inside a template.

Jump to

Keyboard shortcuts

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