obsidian

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExecuteUriError                    = "Failed to execute Obsidian URI"
	NoteDoesNotExistError              = "Cannot find note in vault"
	VaultAccessError                   = "Failed to access vault directory"
	VaultReadError                     = "Failed to read notes in vault"
	VaultWriteError                    = "Failed to write to update notes in vault"
	ObsidianCLIConfigReadError         = "Cannot find vault config, please use set-default command to set default vault or use --vault flag"
	ObsidianCLIConfigParseError        = "Could not parse vault config file, please use set-default command to set default vault or use --vault flag"
	ObsidianCLIConfigDirWriteEror      = "Failed to create vault config directory. Please ensure you have the correct permissions."
	ObsidianCLIConfigGenerateJSONError = "Failed to generate vault config file. Please ensure vault name does not contain any special characters."
	ObsidianCLIConfigWriteError        = "Failed to write vault config file. Please ensure you have correct permissions."
	ObsidianConfigReadError            = "Failed to read Obsidian config file. Please ensure vault has been set up in Obsidian."
	ObsidianConfigParseError           = "Failed to parse Obsidian config file. Please ensure vault has been set up in Obsidian."
	ObsidianConfigVaultNotFoundError   = "Vault not found in Obsidian config file. Please ensure vault has been set up in Obsidian."
)

Variables

View Source
var CliConfigPath = config.CliPath
View Source
var ErrPathTraversal = errors.New("path traversal detected: path must remain within vault directory")

ErrPathTraversal is returned when a path attempts to escape the base directory

View Source
var JsonMarshal = json.Marshal
View Source
var ObsidianConfigFile = config.ObsidianFile
View Source
var Run = open.Run

Functions

func AddMdSuffix

func AddMdSuffix(str string) string

func GenerateBacklinkSearchPatterns

func GenerateBacklinkSearchPatterns(notePath string) []string

GenerateBacklinkSearchPatterns creates patterns to find links pointing to a note.

func GenerateLinkReplacements

func GenerateLinkReplacements(oldNotePath, newNotePath string) map[string]string

GenerateLinkReplacements creates all replacement patterns for updating links when moving a note. It normalizes path separators to forward slashes for cross-platform consistency, as Obsidian uses forward slashes in links regardless of operating system. This handles: - Simple wikilinks: [[note]], [[note|alias]], [[note#heading]] - Path-based wikilinks: [folder/note], [[folder/note|alias]], [[folder/note#heading]] - Markdown links: [text](folder/note.md), [text](./folder/note.md)

func GenerateNoteLinkTexts

func GenerateNoteLinkTexts(noteName string) [3]string

func ListEntries

func ListEntries(vaultPath, relativePath string) ([]string, error)

func OpenInEditor

func OpenInEditor(filePath string) error

OpenInEditor opens the specified file path in the user's preferred editor It supports common GUI editors with appropriate wait flags

func RemoveMdSuffix

func RemoveMdSuffix(str string) string

func ReplaceContent

func ReplaceContent(content []byte, replacements map[string]string) []byte

func ShouldSkipDirectoryOrFile

func ShouldSkipDirectoryOrFile(info os.FileInfo) bool

func ValidatePath

func ValidatePath(basePath, relativePath string) (string, error)

ValidatePath ensures the given relative path, when combined with basePath, stays within basePath. It returns the cleaned absolute path on success.

This function: 1. Rejects absolute paths 2. Cleans both paths and joins them 3. Verifies the result starts with the base path

Returns: - The validated absolute path - ErrPathTraversal if path escapes basePath - Other errors for filesystem issues

Types

type CliConfig

type CliConfig struct {
	DefaultVaultName string `json:"default_vault_name"`
}

type FuzzyFinder

type FuzzyFinder struct{}

func (*FuzzyFinder) Find

func (f *FuzzyFinder) Find(slice interface{}, itemFunc func(i int) string, opts ...interface{}) (int, error)

type FuzzyFinderManager

type FuzzyFinderManager interface {
	Find(slice interface{}, itemFunc func(i int) string, opts ...interface{}) (int, error)
}

type Note

type Note struct {
}

func (*Note) Delete

func (m *Note) Delete(path string) error
func (m *Note) FindBacklinks(vaultPath, noteName string) ([]NoteMatch, error)

func (*Note) GetContents

func (m *Note) GetContents(vaultPath string, noteName string) (string, error)

func (*Note) GetNotesList

func (m *Note) GetNotesList(vaultPath string) ([]string, error)

func (*Note) Move

func (m *Note) Move(originalPath string, newPath string) error

func (*Note) SearchNotesWithSnippets

func (m *Note) SearchNotesWithSnippets(vaultPath string, query string) ([]NoteMatch, error)

func (*Note) SetContents

func (m *Note) SetContents(vaultPath string, noteName string, content string) error
func (m *Note) UpdateLinks(vaultPath string, oldNoteName string, newNoteName string) error

type NoteManager

type NoteManager interface {
	Move(string, string) error
	Delete(string) error
	UpdateLinks(string, string, string) error
	GetContents(string, string) (string, error)
	SetContents(string, string, string) error
	GetNotesList(string) ([]string, error)
	SearchNotesWithSnippets(string, string) ([]NoteMatch, error)
	FindBacklinks(string, string) ([]NoteMatch, error)
}

type NoteMatch

type NoteMatch struct {
	FilePath   string
	LineNumber int
	MatchLine  string
}

type ObsidianVaultConfig

type ObsidianVaultConfig struct {
	Vaults map[string]struct {
		Path string `json:"path"`
	} `json:"vaults"`
}

type Uri

type Uri struct {
}

func (*Uri) Construct

func (u *Uri) Construct(baseUri string, params map[string]string) string

func (*Uri) Execute

func (u *Uri) Execute(uri string) error

type UriManager

type UriManager interface {
	Construct(baseUri string, params map[string]string) string
	Execute(uri string) error
}

type Vault

type Vault struct {
	Name string
}

func (*Vault) DefaultName

func (v *Vault) DefaultName() (string, error)

func (*Vault) Path

func (v *Vault) Path() (string, error)

func (*Vault) SetDefaultName

func (v *Vault) SetDefaultName(name string) error

type VaultManager

type VaultManager interface {
	DefaultName() (string, error)
	SetDefaultName(name string) error
	Path() (string, error)
}

Jump to

Keyboard shortcuts

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