hooks

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: AGPL-3.0 Imports: 16 Imported by: 0

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

View Source
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
)
View Source
const (
	ArchiveBoxTrigger = "@archivebox"
)

Variables

View Source
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 BkMktabHook(b *gosuki.Bookmark) error

func BkNotifySend

func BkNotifySend(b *gosuki.Bookmark) error

func HooksScheduler added in v1.3.0

func HooksScheduler(incoming <-chan HookJob)

HooksScheduler calls bookmark hooks on queued hook jobs

func NodeMktabHook

func NodeMktabHook(n *tree.Node) error

func NodeNotifySend

func NodeNotifySend(n *tree.Node) error

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.

func (Hook[T]) Kind added in v1.3.0

func (h Hook[T]) Kind() Kind

func (Hook[T]) Name

func (h Hook[T]) Name() string

type HookJob added in v1.3.0

type HookJob struct {
	Book *gosuki.Bookmark
	Kind Kind
}

type HookMap

type HookMap map[string]NamedHook

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

type Hookable interface {
	*gosuki.Bookmark | *tree.Node
}

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 NamedHook

type NamedHook interface {
	Name() string
	Kind() Kind
}

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
}

Jump to

Keyboard shortcuts

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