engine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildBackreferences

func BuildBackreferences(notes []model.Note) []model.Note

BuildBackreferences analyzes all notes and populates the ReferencedBy field for each note based on wikilinks found in other notes' content

func GetAllNotesFromTree deprecated

func GetAllNotesFromTree(root *TreeNode) []model.Note

GetAllNotesFromTree extracts all notes from the tree structure

Deprecated: Use NotesService.GetAllNotes() instead for cleaner syntax and thread-safe access. This function remains available for cases where you need to work with a tree directly.

func ParseHashtagLinks(content string) string

ParseHashtagLinks converts hashtags in content to clickable links It avoids false positives by: 1. Ignoring hashtags inside code blocks (both inline ` and multi-line ```) 2. Only matching hashtags preceded by whitespace or start of line 3. Avoiding hashtags that are part of URLs or other text

func ParseTagLinksInMetadata

func ParseTagLinksInMetadata(metadata map[string]any) map[string]any

ParseTagLinksInMetadata processes tags in metadata and converts them to clickable links

func ParseWikiLinks(content string, tree *TreeNode) string

ParseWikiLinks transforms [[linktitle]] and [[linktitle|displayname]] into [title](link) format

func ParseWikiLinksInMetadata deprecated

func ParseWikiLinksInMetadata(metadata map[string]any, tree *TreeNode) map[string]any

ParseWikiLinksInMetadata processes wikilinks in metadata values (strings and lists)

Deprecated: Use NotesService.ParseWikiLinksInMetadata(metadata) instead for cleaner syntax. This function remains available for cases where you need to work with a tree directly.

func ProcessMarkdownLinks(content string) string

ProcessMarkdownLinks removes .md extensions from markdown links before rendering

func RemoveCommentBlocks

func RemoveCommentBlocks(content string) string

RemoveCommentBlocks removes all content between %% markers (inclusive)

func SearchNotesByFilename

func SearchNotesByFilename(notes []model.Note, searchQuery string) []model.Note

SearchNotesByFilename searches notes by filename (title and slug) and returns filtered results This function shows matches in the file name first, folder names second

func Slugify

func Slugify(text string, options SlugifyOptions) string

Slugify converts a string to a URL-friendly slug with configurable options

func SlugifyHeading

func SlugifyHeading(text string) string

SlugifyHeading creates a slug for a heading using heading-specific options

func SlugifyNote

func SlugifyNote(text string) string

SlugifyNote creates a slug for a note using note-specific options

func SlugifyNoteWithCaseLogic

func SlugifyNoteWithCaseLogic(text, existingSlug string) string

SlugifyNoteWithCaseLogic creates a slug for a note with special case-preserving logic This function preserves case when creating from titles but converts existing slugs to lowercase

Types

type HeadingMatch

type HeadingMatch struct {
	Note    model.Note
	Heading string // The matched heading text
	Level   int    // 1 for H1, 2 for H2, 3 for H3
	Context string // Surrounding text (~150 chars)
	LineNum int    // Line number in note for potential linking
	Score   int    // Relevance score
}

HeadingMatch represents a match within a note's heading

func SearchNotesByHeadings

func SearchNotesByHeadings(notes []model.Note, searchQuery string, limit int) []HeadingMatch

SearchNotesByHeadings searches for headings (H1-H3) matching the query

type NoteScored

type NoteScored struct {
	Note  model.Note
	Score int
}

type NotesService

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

NotesService manages the notes data with thread-safe access

func NewNotesService

func NewNotesService(notesMap *map[string]model.Note, tree *TreeNode, tagIndex TagIndex) *NotesService

NewNotesService creates a new NotesService with the given data

func (*NotesService) FilterTreeBySearch

func (ns *NotesService) FilterTreeBySearch(query string) *TreeNode

FilterTreeBySearch filters the tree to only show nodes matching the search query This is a convenience method that wraps engine.FilterTreeBySearch

func (*NotesService) GetAllNotes

func (ns *NotesService) GetAllNotes() []model.Note

GetAllNotes extracts all notes from the tree structure This is a convenience method that wraps engine.GetAllNotesFromTree

func (*NotesService) GetHomeSlug

func (ns *NotesService) GetHomeSlug(homeNoteSlug string) string

GetHomeSlug determines the home note slug based on priority: 1. The provided homeNoteSlug config value (if it exists in notes) 2. First note in alphabetical order 3. Empty string if no notes exist

func (*NotesService) GetNote

func (ns *NotesService) GetNote(slug string) (model.Note, bool)

GetNote safely retrieves a note by slug

func (*NotesService) GetNotesMap

func (ns *NotesService) GetNotesMap() map[string]model.Note

GetNotesMap returns a thread-safe copy of the notesMap

func (*NotesService) GetTagIndex

func (ns *NotesService) GetTagIndex() TagIndex

GetTagIndex returns the tag index with a read lock

func (*NotesService) GetTree

func (ns *NotesService) GetTree() *TreeNode

GetTree returns the tree with a read lock

func (ns *NotesService) ParseWikiLinks(content string) string

ParseWikiLinks processes wiki-style links in content This is a convenience method that wraps engine.ParseWikiLinks

func (*NotesService) ParseWikiLinksInMetadata

func (ns *NotesService) ParseWikiLinksInMetadata(metadata map[string]any) map[string]any

ParseWikiLinksInMetadata processes wikilinks in metadata values This is a convenience method that wraps engine.ParseWikiLinksInMetadata

func (*NotesService) UpdateData

func (ns *NotesService) UpdateData(notesMap *map[string]model.Note, tree *TreeNode, tagIndex TagIndex)

UpdateData safely updates the service's notesMap, tree, and tagIndex with new data

type SlugifyOptions

type SlugifyOptions struct {
	// PreserveSlashes keeps forward slashes in the slug (useful for paths)
	PreserveSlashes bool
	// URLEncode applies URL encoding to the result
	URLEncode bool
	// RemoveExtension removes file extensions like .md
	RemoveExtension bool
	// TrimSlashes removes leading and trailing slashes
	TrimSlashes bool
	// PreserveCase keeps the original case instead of converting to lowercase
	PreserveCase bool
}

SlugifyOptions defines options for slugification behavior

func DefaultHeadingSlugOptions

func DefaultHeadingSlugOptions() SlugifyOptions

DefaultHeadingSlugOptions returns the default options for heading slugification

func DefaultNoteSlugOptions

func DefaultNoteSlugOptions() SlugifyOptions

DefaultNoteSlugOptions returns the default options for note slugification

type TagIndex

type TagIndex map[string][]model.Note

TagIndex maps tag names to notes that contain them

func BuildTagIndex

func BuildTagIndex(notes []model.Note) TagIndex

BuildTagIndex creates an index of all tags found in notes Tags can come from: 1. Metadata "tags" field (array of strings) 2. Free text with syntax #[A-Za-z/-]+

func (TagIndex) GetAllTags

func (tagIndex TagIndex) GetAllTags() []string

GetAllTags returns all unique tags in the index

func (TagIndex) GetNotesWithTag

func (tagIndex TagIndex) GetNotesWithTag(tag string) []model.Note

GetNotesWithTag returns all notes that contain the specified tag

func (TagIndex) GetTagsContaining

func (tagIndex TagIndex) GetTagsContaining(substring string) []string

GetTagsContaining returns all tags that contain the specified substring

type TreeNode

type TreeNode struct {
	Name     string      `json:"name"`     // Display name (folder name or note title)
	Path     string      `json:"path"`     // Full path from root
	IsFolder bool        `json:"isFolder"` // True if this is a folder, false if it's a note
	Note     *model.Note `json:"note"`     // Reference to the note if this is a note node
	Children []*TreeNode `json:"children"` // Child nodes (subfolders and notes)
	IsOpen   bool        `json:"isOpen"`   // Whether the folder is expanded in the UI
}

TreeNode represents a node in the file tree structure

func BuildTree

func BuildTree(notes []model.Note) *TreeNode

BuildTree creates a tree structure from a list of notes

func FilterTreeBySearch deprecated

func FilterTreeBySearch(root *TreeNode, query string) *TreeNode

FilterTreeBySearch filters the tree to only show nodes that match the search query

Deprecated: Use NotesService.FilterTreeBySearch(query) instead for cleaner syntax. This function remains available for cases where you need to work with a tree directly.

func FindNoteInTree

func FindNoteInTree(root *TreeNode, slug string) *TreeNode

FindNoteInTree searches for a note by slug in the tree

func (*TreeNode) AllNotes

func (t *TreeNode) AllNotes(yield func(*TreeNode) bool)

AllNotes yields all notes in the tree using Go 1.23 iterator pattern

Jump to

Keyboard shortcuts

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