Documentation
¶
Index ¶
- Variables
- func Banner(p Page) string
- func Delete(path string, handler HandlerFunc)
- func EachPage(ctx context.Context, f func(Page))
- func Emoji(p Page) string
- func FindAllInAST[t ast.Node](n ast.Node) (a []t)
- func FindInAST[t ast.Node](n ast.Node) (found t, ok bool)
- func Get(path string, handler HandlerFunc)
- func IgnorePath(r *regexp.Regexp)
- func IsFontAwesome(i string) bool
- func IsIgnoredPath(d string) bool
- func Listen(e PageEvent, h PageEventHandler)
- func MapPage[T any](ctx context.Context, f func(Page) T) []T
- func Partial(path string, data Locals) template.HTML
- func Post(path string, handler HandlerFunc)
- func Properties(p Page) map[string]Property
- func RegisterBuildPage(p string, encloseInDir bool)
- func RegisterCommand(c func(Page) []Command)
- func RegisterExtension(e Extension)
- func RegisterHelper(name string, f any) error
- func RegisterJS(f string)
- func RegisterLink(l func(Page) []Command)
- func RegisterPageSource(p PageSource)
- func RegisterPreprocessor(f Preprocessor)
- func RegisterProperty(a func(Page) []Property)
- func RegisterQuickCommand(c func(Page) []Command)
- func RegisterStaticDir(f fs.FS)
- func RegisterTemplate(t fs.FS, subDir string)
- func RegisterWidget(s WidgetSpace, priority float32, f WidgetFunc)
- func RenderWidget(s WidgetSpace, p Page) (o template.HTML)
- func RequireHTMX()
- func Start(ctx context.Context)
- func Trigger(e PageEvent, p Page)
- type Command
- type Configuration
- type DynamicPage
- func (DynamicPage) AST() ([]byte, ast.Node)
- func (DynamicPage) Content() Markdown
- func (DynamicPage) Delete() bool
- func (DynamicPage) Exists() bool
- func (DynamicPage) FileName() string
- func (DynamicPage) ModTime() time.Time
- func (d DynamicPage) Name() string
- func (d DynamicPage) Render() template.HTML
- func (DynamicPage) Write(Markdown) bool
- type Extension
- type HandlerFunc
- type Locals
- type Markdown
- type Output
- func BadRequest(msg string) Output
- func Cache(out Output) Output
- func InternalServerError(err error) Output
- func JsonResponse(a any) Output
- func NoContent() Output
- func NotFound(msg string) Output
- func PlainText(text string) Output
- func Redirect(url string) Output
- func Render(path string, data Locals) Output
- type Page
- type PageEvent
- type PageEventHandler
- type PageSource
- type Preprocessor
- type Property
- type Request
- type Response
- type WidgetFunc
- type WidgetSpace
Constants ¶
This section is empty.
Variables ¶
var ( // a function that returns the CSRF token CSRF = csrf.Token )
var ErrHelperRegistered = errors.New("Helper already registered")
var MarkdownConverter = sync.OnceValue(func() goldmark.Markdown { return goldmark.New( goldmark.WithExtensions( extension.GFM, extension.DefinitionList, extension.Footnote, extension.Typographer, highlighting.NewHighlighting( highlighting.WithCustomStyle(styles.Get(Config.CodeStyle)), highlighting.WithFormatOptions( chroma_html.WithLineNumbers(true), ), ), emoji.Emoji, ), goldmark.WithParserOptions( parser.WithAutoHeadingID(), ), goldmark.WithRendererOptions( html.WithHardWraps(), html.WithUnsafe(), ), ) })
The instance of markdown renderer. this is what takes the page content and converts it to HTML. it defines what features to use from goldmark and what options to turn on
Functions ¶
func Delete ¶ added in v0.22.0
func Delete(path string, handler HandlerFunc)
Delete defines a new route that gets executed when the request matches path and method is http Delete.
func EachPage ¶ added in v0.24.0
EachPage iterates on all available pages. many extensions uses it to get all pages and maybe parse them and extract needed information
func FindAllInAST ¶ added in v0.25.0
Extract all nodes of a specific type from the AST
func FindInAST ¶ added in v0.25.0
FindInAST takes an AST node and walks the tree depth first searching for a node of a specific type can be used to find first image, link, paragraph...etc
func Get ¶ added in v0.22.0
func Get(path string, handler HandlerFunc)
Get defines a new route that gets executed when the request matches path and method is http Get.
func IgnorePath ¶ added in v1.7.0
IgnorePath Register a pattern to be ignored when walking directories.
func IsFontAwesome ¶ added in v1.7.0
func IsIgnoredPath ¶ added in v1.7.0
IsIgnoredPath checks if a file path should be ignored according to the list of ignored paths. page source implementations can use it to ignore files from their sources
func Listen ¶ added in v0.16.0
func Listen(e PageEvent, h PageEventHandler)
Register an event handler to be executed when PageEvent is triggered. extensions can use this to register hooks under specific page events. extensions that keeps a cached version of the pages list for example needs to register handlers to update its cache
func MapPage ¶ added in v1.7.0
MapPage Similar to EachPage but iterates concurrently and accumulates returns in a slice
func Partial ¶
Partial executes a template by it's path name. it passes data to the template. returning the output of the template. in case of an error it will return the error string as the output
func Post ¶ added in v0.22.0
func Post(path string, handler HandlerFunc)
Post defines a new route that gets executed when the request matches path and method is http Post.
func Properties ¶ added in v0.42.0
Properties return a list of properties for a page. It executes all functions registered with RegisterProperty and collect results in one slice. Can be passed to the view to render a page properties
func RegisterBuildPage ¶ added in v0.28.0
RegisterBuildPage registers a path of a page to export when building static version of the knowledgebase. encloseInDir will write the output to p/index.html instead instead of writing to p directly. that can help have paths with no .html extension to be served with the exact name.
func RegisterCommand ¶ added in v0.27.0
RegisterCommand registers a new command
func RegisterExtension ¶ added in v1.7.0
func RegisterExtension(e Extension)
func RegisterHelper ¶ added in v0.28.0
RegisterHelper registers a new helper function. all helpers are used when compiling templates. so registering helpers function must happen before the server starts as compiling templates happened right before starting the http server.
func RegisterJS ¶ added in v1.7.0
func RegisterJS(f string)
RegisterJS adds a Javascript library URL/path to be included in the scripts used by the template
func RegisterLink ¶ added in v0.31.0
Register a new links function, should return a list of Links
func RegisterPageSource ¶ added in v0.80.0
func RegisterPageSource(p PageSource)
func RegisterPreprocessor ¶ added in v0.28.0
func RegisterPreprocessor(f Preprocessor)
RegisterPreprocessor registers a Preprocessor function. extensions should use this function to register a preprocessor.
func RegisterProperty ¶ added in v0.36.0
RegisterProperty registers a function that returns a set of properties for the page
func RegisterQuickCommand ¶ added in v0.36.0
func RegisterStaticDir ¶ added in v0.77.0
RegisterStaticDir adds a filesystem to the filesystems list scanned for files when serving static files. can be used to add a directory of CSS or JS files by extensions
func RegisterTemplate ¶ added in v0.28.0
RegisterTemplate registers a filesystem that contains templates, specifying subDir as the subdirectory name that contains the templates. templates are registered such that the latest registered directory override older ones. template file extensions are signified by '.html' extension and the file path can be used as template name without this extension
func RegisterWidget ¶ added in v0.28.0
func RegisterWidget(s WidgetSpace, priority float32, f WidgetFunc)
RegisterWidget Register a function to a widget space. functions registered will be executed in order of priority lower to higher when rendering view or edit page. the return values of these widgetfuncs will pass down to the template and injected in reserved places.
func RenderWidget ¶
func RenderWidget(s WidgetSpace, p Page) (o template.HTML)
This is used by view and edit routes to render all widgetfuncs registered for specific widget space.
func RequireHTMX ¶ added in v1.7.0
func RequireHTMX()
RequireHTMX registes HTML library, this helps include one version of HTMX
Types ¶
type Command ¶ added in v0.27.0
type Command interface { // Icon returns the Fontawesome icon class name for the Command Icon() string // Name of the command. to be displayed in the list Name() string // Attrs a map of attributes to their values Attrs() map[template.HTMLAttr]any }
Command defines a structure used for 3 categories of lists: 1. Commands for Ctrl+K actions menu 2. Quick commands displayed in the default template at the top right of the page 3. Links displayed in the navigation bar The template decides where and how to display commands. it can choose to use them in a different way than the default template
func Commands ¶ added in v0.42.0
Commands return the list of commands for a page. when a page is displayed it executes all functions registered with RegisterCommand and collect all results in one slice. result can be passed to the view to render the commands list
func Links ¶ added in v0.42.0
Links returns a list of links for a Page. it executes all functions registered with RegisterLink and collect them in one slice. Can be passed to the view to render in the footer for example.
func QuickCommands ¶ added in v0.42.0
QuickCommands return the list of QuickCommands for a page. it executes all functions registered with RegisterQuickCommand and collect all results in one slice. result can be passed to the view to render the Quick commands list
type Configuration ¶ added in v1.7.0
type Configuration struct { Source string // path to markdown files directory Build string // path to write built files Readonly bool // is xlog in readonly mode Sitename string // name of knowledgebase Index string // name of the index page markdown file NotFoundPage string // name of the index page markdown file BindAddress string // bind address for the server ServeInsecure bool // should the server use https for cookie CodeStyle string CsrfCookieName string DisabledExtensions string }
var Config Configuration
type DynamicPage ¶ added in v1.7.0
DynamicPage implement Page interface and allow extensions to define a page to be passed to templates without having underlying file on desk
func (DynamicPage) Content ¶ added in v1.7.0
func (DynamicPage) Content() Markdown
func (DynamicPage) Delete ¶ added in v1.7.0
func (DynamicPage) Delete() bool
func (DynamicPage) Exists ¶ added in v1.7.0
func (DynamicPage) Exists() bool
func (DynamicPage) FileName ¶ added in v1.7.0
func (DynamicPage) FileName() string
func (DynamicPage) ModTime ¶ added in v1.7.0
func (DynamicPage) ModTime() time.Time
func (DynamicPage) Name ¶ added in v1.7.0
func (d DynamicPage) Name() string
func (DynamicPage) Render ¶ added in v1.7.0
func (d DynamicPage) Render() template.HTML
func (DynamicPage) Write ¶ added in v1.7.0
func (DynamicPage) Write(Markdown) bool
type HandlerFunc ¶
HandlerFunc is the type of an HTTP handler function + returns output function. it makes it easier to return the output directly instead of writing the output to w then return.
type Markdown ¶ added in v0.45.0
type Markdown string
Markdown is used instead of string to make sure it's clear the string is markdown string
func PreProcess ¶ added in v0.83.0
This function take the page content and pass it through all registered preprocessors and return the last preprocessor output to the caller
type Output ¶
type Output = http.HandlerFunc
alias of http.HandlerFunc as output is expected from defined http handlers
func BadRequest ¶
BadRequest returns an output function that writes BadRequest http response
func Cache ¶ added in v1.5.0
Cache wraps Output and adds header to instruct the browser to cache the output
func InternalServerError ¶
InternalServerError returns an output function that writes InternalServerError http response
func JsonResponse ¶ added in v0.43.0
func NoContent ¶
func NoContent() Output
NoContent returns an output function that writes NoContent http status
type Page ¶
type Page interface { // Name returns page name without '.md' extension Name() string // returns the filename, makes sure it converts slashes to backslashes when // needed. this is safe to use when trying to access the file that represent the // page FileName() string // checks if the page underlying file exists on disk or not. Exists() bool // Renders the page content to HTML. it makes sure all preprocessors are called Render() template.HTML // Reads the underlying file and returns the content Content() Markdown // Deletes the file and makes sure it triggers the AfterDelete event Delete() bool // Overwrite page content with new content. making sure to trigger before and // after write events. Write(Markdown) bool // ModTime Return the last modification time of the underlying file ModTime() time.Time // Parses the page content and returns the Abstract Syntax Tree (AST). // extensions can use it to walk the tree and modify it or collect statistics or // parts of the page. for example the following "Emoji" function uses it to // extract the first emoji. AST() ([]byte, ast.Node) }
a Type that represent a page.
type PageEvent ¶
type PageEvent int
a type used to define events to be used when the page is manipulated for example modified, renamed, deleted...etc.
const ( PageChanged PageEvent = iota PageDeleted PageNotFound // user requested a page that's not found )
List of page events. extensions can use these events to register a function to be executed when this event is triggered. extensions that require to be notified when the page is created or overwritten or deleted should register an event handler for the interesting events.
type PageEventHandler ¶
a function that handles a page event. this should be implemented by an extension and then registered. it will get executed when the event is triggered
type PageSource ¶ added in v0.80.0
type Preprocessor ¶ added in v0.22.0
A Preprocessor is a function that takes the whole page content and returns a modified version of the content. extensions should define this type and register is so that when page is rendered it will execute all of them in order like a pipeline each function output is passed as an input to the next. at the end the last preprocessor output is then rendered to HTML
type Property ¶ added in v0.36.0
type Property interface { // Icon returns the fontawesome icon class name or emoji Icon() string // Name returns the name of the property Name() string // Value returns the value of the property Value() any }
Property represent a piece of information about the current page such as last update time, number of versions, number of words, reading time...etc
type Response ¶
type Response = http.ResponseWriter
alias http.ResponseWriter for shorter handler declaration
type WidgetFunc ¶ added in v0.54.0
WidgetFunc a function that takes the current page and returns the widget. This can be used by extensions to define new widgets to be rendered in view or edit pages. the extension should define this func type and register it to be rendered in a specific widgetSpace such as before or after the page.
type WidgetSpace ¶ added in v0.54.0
type WidgetSpace string
WidgetSpace used to represent a widgets spaces. it's used to register widgets to be injected in the view or edit pages
var ( WidgetAfterView WidgetSpace = "after_view" // widgets rendered after the content of the view page WidgetBeforeView WidgetSpace = "before_view" // widgets rendered before the content of the view page WidgetHead WidgetSpace = "head" // widgets rendered in page <head> tag )
List of widgets spaces that extensions can use to register a WidgetFunc to inject content into.