Documentation
¶
Overview ¶
Package hooks permits to register custom hooks that will be called during the parsing process of a bookmark file. Hooks can be used to extract tags, commands or other custom data from a bookmark title or description.
They can effectively be used as a command line interface to the host system through the browser builtin Ctrl+D bookmark feature.
This is an example implementation of a hook that simply sends a notification using the notification daemon of the system.
Index ¶
- Constants
- Variables
- func BkMktabHook(b *gosuki.Bookmark) error
- func BkNotifySend(b *gosuki.Bookmark) error
- func HooksScheduler(incoming <-chan HookJob)
- func NodeMktabHook(n *tree.Node) error
- func NodeNotifySend(n *tree.Node) error
- func SortByPriority(hooks []NamedHook)
- type Hook
- type HookJob
- type HookMap
- type HookRunner
- type Hookable
- type Kind
- type MarkTab
- type NamedHook
- type Rule
Constants ¶
const ( // BrowserHook is executed for each bookmark loading in every browser // instance. Primarily used for internal gosuki operations, this hook runs // on all bookmarks whenever a bookmark change occurs. BrowserHook = 1 << iota // triggered when bookmarks are inserted the main database GlobalInsertHook // triggered when bookmarks are updated in the main database GlobalUpdateHook )
const (
ArchiveBoxTrigger = "@archivebox"
)
Variables ¶
var Defined = HookMap{ "node_tags_from_name": Hook[*tree.Node]{ Func: parsing.ParseNodeTags, // contains filtered or unexported fields }, "bk_tags_from_name": Hook[*gosuki.Bookmark]{ Func: parsing.ParseBkTags, // contains filtered or unexported fields }, }
Functions ¶
func BkMktabHook ¶
func BkNotifySend ¶
func HooksScheduler ¶ added in v1.3.0
func HooksScheduler(incoming <-chan HookJob)
HooksScheduler calls bookmark hooks on queued hook jobs
func NodeMktabHook ¶
func NodeNotifySend ¶
func SortByPriority ¶
func SortByPriority(hooks []NamedHook)
SortByPriority sorts a slice of NamedHook by priority, with higher priority (lower uint value) first. This uses reflection to access the priority field of each hook.
Types ¶
type Hook ¶
type Hook[T Hookable] struct { // Function to call on a node or bookmark. Must return an error if // processing fails. Func func(T) error // contains filtered or unexported fields }
A Hook is a function that takes a Hookable type (*Bookmark or *Node) and performs an arbitrary process. Hooks are executed during bookmark loading or real-time detection of changes.
For example, the TAG extraction process is managed by the ParseXTags hook.
Hooks can also be used to handle custom user commands and messages found in bookmark fields.
type HookRunner ¶
type HookRunner interface {
// CallHooks executes all registered hooks on the provided target (e.g., a
// node or bookmark). This method is typically called during the main Run()
// lifecycle of a browser.
CallHooks(any) error
}
HookRunner defines the interface for browsers that can register custom hooks. Implementers can define hooks that are executed during the main Run() method to process commands and messages found in tags or parsed data from browsers.
type Hookable ¶
Hookable defines types that can have hooks applied to them, either *gosuki.Bookmark or *tree.Node.
type Kind ¶ added in v1.3.0
type Kind int
Kind represents the category of a hook, determining when and how it is executed.
type MarkTab ¶
type MarkTab struct {
Rules []Rule // Rules contains all the parsed rules from the marktab file.
}
MarkTab represents a collection of rules defined in the marktab file as lines.
type Rule ¶
type Rule struct {
Trigger string // keyword to detect in the bookmark tags
Pattern string // regular expression used for matching against the bookmark URL or title.
Command string // shell command to execute when both the trigger and pattern match the bookmark tags.
// contains filtered or unexported fields
}