wiki

package
v2.22.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPageNotFound           = errors.New("page not found")
	ErrPageAlreadyExists      = errors.New("page already exists")
	ErrPagePathConflict       = errors.New("page path conflicts with another node")
	ErrInvalidPageID          = errors.New("invalid page ID")
	ErrPageRevisionNotFound   = errors.New("page revision not found")
	ErrPageAttachmentNotFound = errors.New("page attachment not found")
	ErrInvalidAttachmentName  = errors.New("invalid attachment name")
)

Sentinel errors for page store operations.

Functions

func ValidateAttachmentName

func ValidateAttachmentName(name string) error

ValidateAttachmentName validates that name is a safe attachment file name: a single path segment following the page-ID segment rules. Extensions used by pages and DAG definitions are reserved so attachment files can never be mistaken for either.

func ValidatePageID

func ValidatePageID(id string) error

ValidatePageID validates that id is a safe, well-formed page identifier.

Types

type DeleteError

type DeleteError struct {
	ID    string
	Error string
}

DeleteError represents a single item failure in a batch delete operation.

type ListPagesOptions

type ListPagesOptions struct {
	Page             int
	PerPage          int
	Sort             PageSortField
	Order            PageSortOrder
	PathPrefix       string
	Tags             []string
	ExcludePathRoots []string
}

ListPagesOptions holds parameters for listing pages.

type Page

type Page struct {
	ID          string   `json:"id"`
	Title       string   `json:"title"`
	Description string   `json:"description,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	Content     string   `json:"content"`
	CreatedAt   string   `json:"createdAt"`
	UpdatedAt   string   `json:"updatedAt"`
}

Page is the domain entity for a markdown page.

type PageAttachment

type PageAttachment struct {
	Name    string    `json:"name"`
	Size    int64     `json:"size"`
	SavedAt time.Time `json:"savedAt"`
}

PageAttachment is a binary file attached to a page.

type PageMetadata

type PageMetadata struct {
	ID          string    `json:"id"`
	Title       string    `json:"title"`
	Description string    `json:"description,omitempty"`
	Tags        []string  `json:"tags,omitempty"`
	ModTime     time.Time `json:"modTime"`
}

PageMetadata is a lightweight page view excluding Content.

type PageRevision

type PageRevision struct {
	Rev     string    `json:"rev"`
	SavedAt time.Time `json:"savedAt"`
	Size    int64     `json:"size"`
	Content string    `json:"content,omitempty"`
}

PageRevision is a stored prior version of a page.

type PageSearchResult

type PageSearchResult struct {
	ID                string              `json:"id"`
	Title             string              `json:"title"`
	Description       string              `json:"description,omitempty"`
	Tags              []string            `json:"tags,omitempty"`
	ModTime           time.Time           `json:"modTime"`
	Matches           []*textsearch.Match `json:"matches"`
	MatchCount        int                 `json:"matchCount,omitempty"`
	HasMoreMatches    bool                `json:"hasMoreMatches"`
	NextMatchesCursor string              `json:"nextMatchesCursor,omitempty"`
}

PageSearchResult holds a page ID/title and its grep matches.

type PageSortField

type PageSortField string

PageSortField defines the field to sort pages by.

const (
	PageSortFieldName  PageSortField = "name"
	PageSortFieldType  PageSortField = "type"
	PageSortFieldMTime PageSortField = "mtime"
)

type PageSortOrder

type PageSortOrder string

PageSortOrder defines the sort direction.

const (
	PageSortOrderAsc  PageSortOrder = "asc"
	PageSortOrderDesc PageSortOrder = "desc"
)

type PageStore

type PageStore interface {
	List(ctx context.Context, opts ListPagesOptions) (*pagination.PaginatedResult[*PageTreeNode], error)
	ListFlat(ctx context.Context, opts ListPagesOptions) (*pagination.PaginatedResult[PageMetadata], error)
	Get(ctx context.Context, id string) (*Page, error)
	Create(ctx context.Context, id, content string) error
	Update(ctx context.Context, id, content string) error
	Delete(ctx context.Context, id string) error
	DeleteBatch(ctx context.Context, ids []string) (deleted []string, failed []DeleteError, err error)
	// Rename moves a page or every page under a directory path.
	Rename(ctx context.Context, oldID, newID string) error
	// Backlinks returns metadata for pages linking to target. Target is a
	// stored page ID or a scheme-prefixed wiki-link target such as
	// "dag:name". A relative link held by a page under pathPrefix also
	// matches when pathPrefix + "/" + link equals target.
	Backlinks(ctx context.Context, target, pathPrefix string) ([]PageMetadata, error)
	// ListRevisions returns stored prior versions of a page, newest
	// first, without content. Stores without revision support return an
	// empty list.
	ListRevisions(ctx context.Context, id string) ([]PageRevision, error)
	// GetRevision returns one stored revision including its content.
	GetRevision(ctx context.Context, id, rev string) (*PageRevision, error)
	// PutAttachment stores an attachment for an existing page,
	// replacing any attachment with the same name.
	PutAttachment(ctx context.Context, id, name string, content io.Reader) (*PageAttachment, error)
	// OpenAttachment opens an attachment for reading. The caller closes the
	// returned reader.
	OpenAttachment(ctx context.Context, id, name string) (io.ReadCloser, *PageAttachment, error)
	Search(ctx context.Context, query string) ([]*PageSearchResult, error)
	SearchCursor(ctx context.Context, opts SearchPagesOptions) (*pagination.CursorResult[PageSearchResult], error)
	SearchMatches(ctx context.Context, id string, opts SearchPageMatchesOptions) (*pagination.CursorResult[*textsearch.Match], error)
	// PathExists reports whether id identifies a page or a page directory.
	PathExists(ctx context.Context, id string) (pageExists, directoryExists bool, err error)
}

PageStore defines the interface for page persistence.

type PageTreeNode

type PageTreeNode struct {
	ID       string          `json:"id"`
	Name     string          `json:"name"`
	Title    string          `json:"title,omitempty"`
	Tags     []string        `json:"tags,omitempty"`
	Type     string          `json:"type"` // "file" or "directory"
	Children []*PageTreeNode `json:"children,omitempty"`
	ModTime  time.Time       `json:"modTime"`
}

PageTreeNode represents a file or directory in the page tree.

type SearchPageMatchesOptions

type SearchPageMatchesOptions struct {
	Cursor     string
	Limit      int
	Query      string
	PathPrefix string
}

SearchPageMatchesOptions configures cursor-based snippet loading for one page.

type SearchPagesOptions

type SearchPagesOptions struct {
	Cursor           string
	Limit            int
	Query            string
	MatchLimit       int
	PathPrefix       string
	FilterPrefix     string
	Tags             []string
	ExcludePathRoots []string
}

SearchPagesOptions configures a paginated page search query.

type WikiLink struct {
	Target string
	Anchor string
	Label  string
}

WikiLink is a single [[target]] reference found in page content. Target is returned raw and may carry a colon-delimited scheme (for example "dag:name") instead of a page ID.

func ExtractWikiLinks(content string) []WikiLink

ExtractWikiLinks returns the wiki links in content, in page order. Links inside fenced code blocks and inline code spans are ignored, as are ![[name]] embeds, which reference attachments rather than pages. Targets are returned raw, including scheme-prefixed targets.

Jump to

Keyboard shortcuts

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