Documentation
¶
Index ¶
- Variables
- func EnsurePageIsFolder(storageDir string, pagePath string) error
- func FoldPageFolderIfEmpty(storageDir string, pagePath string) error
- func GeneratePathFromPageNode(entry *PageNode) string
- type Page
- type PageNode
- type PageStore
- func (f *PageStore) CreatePage(parentEntry *PageNode, newEntry *PageNode) error
- func (f *PageStore) DeletePage(entry *PageNode) error
- func (f *PageStore) LoadTree(filename string) (*PageNode, error)
- func (f *PageStore) MovePage(entry *PageNode, parentEntry *PageNode) error
- func (f *PageStore) ReadPageContent(entry *PageNode) (string, error)
- func (f *PageStore) SaveTree(filename string, tree *PageNode) error
- func (f *PageStore) UpdatePage(entry *PageNode, slug string, content string) error
- type SlugService
- type TreeService
- func (t *TreeService) CreatePage(parentID *string, title string, slug string) (*string, error)
- func (t *TreeService) DeletePage(id string, recursive bool) error
- func (t *TreeService) FindPageByID(entry []*PageNode, id string) (*PageNode, error)
- func (t *TreeService) FindPageByRoutePath(entry []*PageNode, routePath string) (*Page, error)
- func (t *TreeService) GetPage(id string) (*Page, error)
- func (t *TreeService) GetTree() *PageNode
- func (t *TreeService) LoadTree() error
- func (t *TreeService) MovePage(id string, parentID string) error
- func (t *TreeService) ReindexPositions(parent *PageNode)
- func (t *TreeService) SaveTree() error
- func (t *TreeService) SortPages(parentID string, orderedIDs []string) error
- func (t *TreeService) UpdatePage(id string, title string, slug string, content string) error
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidSortOrder = errors.New("invalid sort order")
var ErrMovePageCircularReference = errors.New("circular reference detected")
var ErrPageAlreadyExists = errors.New("page already exists")
var ErrPageCannotBeMovedToItself = errors.New("page cannot be moved to itself")
var ErrPageHasChildren = errors.New("page has children")
var ErrPageNotFound = errors.New("page not found")
var ErrParentNotFound = errors.New("parent not found")
var ErrTreeNotLoaded = errors.New("tree not loaded")
Functions ¶
func EnsurePageIsFolder ¶
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 ¶
FoldPageFolderIfEmpty converts a page folder back into a flat file if it contains only "index.md" and nothing else.
Types ¶
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 (*PageNode) HasChildren ¶
type PageStore ¶
type PageStore struct {
// contains filtered or unexported fields
}
func NewPageStore ¶
func (*PageStore) CreatePage ¶
func (*PageStore) DeletePage ¶
func (*PageStore) ReadPageContent ¶
ReadPageContent returns the content of a page
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 ¶
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) 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 ¶
UpdatePage updates a page in the tree