tree

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSortOrder = errors.New("invalid sort order")
View Source
var ErrMovePageCircularReference = errors.New("circular reference detected")
View Source
var ErrPageAlreadyExists = errors.New("page already exists")
View Source
var ErrPageCannotBeMovedToItself = errors.New("page cannot be moved to itself")
View Source
var ErrPageHasChildren = errors.New("page has children")
View Source
var ErrPageNotFound = errors.New("page not found")
View Source
var ErrParentNotFound = errors.New("parent not found")
View Source
var ErrTreeNotLoaded = errors.New("tree not loaded")

Functions

func EnsurePageIsFolder

func EnsurePageIsFolder(storageDir string, pagePath string) error

EnsurePageIsFolder checks if a page path is still a flat .md file, and if so, converts it into a folder with an index.md file.

func FoldPageFolderIfEmpty

func FoldPageFolderIfEmpty(storageDir string, pagePath string) error

FoldPageFolderIfEmpty converts a page folder back into a flat file if it contains only "index.md" and nothing else.

func GeneratePathFromPageNode

func GeneratePathFromPageNode(entry *PageNode) string

Types

type Page

type Page struct {
	*PageNode
	Content string `json:"content"`
}

type PageNode

type PageNode struct {
	ID       string      `json:"id"`       // Unique identifier for the entry
	Title    string      `json:"title"`    // Title is the name of the entry
	Slug     string      `json:"slug"`     // Slug is the path of the entry
	Children []*PageNode `json:"children"` // Children are the children of the entry
	Position int         `json:"position"` // Position is the position of the entry
	Parent   *PageNode   `json:"-"`
}

PageNode represents a single node in the tree It has an ID, a parent, a path, and children The ID is a unique identifier for the entry

func (*PageNode) ChildAlreadyExists

func (p *PageNode) ChildAlreadyExists(slug string) bool

func (*PageNode) HasChildren

func (p *PageNode) HasChildren() bool

func (*PageNode) IsChildOf

func (p *PageNode) IsChildOf(childID string, recursive bool) bool

type PageStore

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

func NewPageStore

func NewPageStore(storageDir string) *PageStore

func (*PageStore) CreatePage

func (f *PageStore) CreatePage(parentEntry *PageNode, newEntry *PageNode) error

func (*PageStore) DeletePage

func (f *PageStore) DeletePage(entry *PageNode) error

func (*PageStore) LoadTree

func (f *PageStore) LoadTree(filename string) (*PageNode, error)

func (*PageStore) MovePage

func (f *PageStore) MovePage(entry *PageNode, parentEntry *PageNode) error

MovePage moves a page to a other node

func (*PageStore) ReadPageContent

func (f *PageStore) ReadPageContent(entry *PageNode) (string, error)

ReadPageContent returns the content of a page

func (*PageStore) SaveTree

func (f *PageStore) SaveTree(filename string, tree *PageNode) error

func (*PageStore) UpdatePage

func (f *PageStore) UpdatePage(entry *PageNode, slug string, content string) error

type SlugService

type SlugService struct {
}

func NewSlugService

func NewSlugService() *SlugService

func (*SlugService) GenerateUniqueFilename

func (s *SlugService) GenerateUniqueFilename(existing []string, desired string) string

func (*SlugService) GenerateUniqueSlug

func (s *SlugService) GenerateUniqueSlug(parent *PageNode, desired string) string

GenerateUniqueSlug returns a slug that doesn't conflict with siblings of the given parent

func (*SlugService) IsValidSlug

func (s *SlugService) IsValidSlug(slug string) error

func (*SlugService) NormalizeFilename

func (s *SlugService) NormalizeFilename(filename string) string

type TreeService

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

TreeService is our main component for handling tree operations We use this service to create pages, delete pages, update pages, etc.

func NewTreeService

func NewTreeService(storageDir string) *TreeService

NewTreeService creates a new TreeService

func (*TreeService) CreatePage

func (t *TreeService) CreatePage(parentID *string, title string, slug string) (*string, error)

Create Page adds a new page to the tree

func (*TreeService) DeletePage

func (t *TreeService) DeletePage(id string, recursive bool) error

DeletePage deletes a page from the tree

func (*TreeService) FindPageByID

func (t *TreeService) FindPageByID(entry []*PageNode, id string) (*PageNode, error)

FindPageByID finds a page in the tree by its ID If the page is not found, it returns an error

func (*TreeService) FindPageByRoutePath

func (t *TreeService) FindPageByRoutePath(entry []*PageNode, routePath string) (*Page, error)

FindPageByPath finds a page in the tree by its path

func (*TreeService) GetPage

func (t *TreeService) GetPage(id string) (*Page, error)

GetPage returns a page by its ID

func (*TreeService) GetTree

func (t *TreeService) GetTree() *PageNode

GetTree returns the tree

func (*TreeService) LoadTree

func (t *TreeService) LoadTree() error

LoadTree loads the tree from the storage directory If the tree does not exist, it creates a new tree

func (*TreeService) MovePage

func (t *TreeService) MovePage(id string, parentID string) error

MovePage moves a page to another parent

func (*TreeService) ReindexPositions

func (t *TreeService) ReindexPositions(parent *PageNode)

func (*TreeService) SaveTree

func (t *TreeService) SaveTree() error

func (*TreeService) SortPages

func (t *TreeService) SortPages(parentID string, orderedIDs []string) error

func (*TreeService) UpdatePage

func (t *TreeService) UpdatePage(id string, title string, slug string, content string) error

UpdatePage updates a page in the tree

Jump to

Keyboard shortcuts

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