Documentation ¶
Index ¶
- Constants
- Variables
- func AUTOCOMPLETE(a Autocompleter)
- func EXTENSION_PAGE(p string)
- func ExtractAllFromAST[t ast.Node](n ast.Node, kind ast.NodeKind) (a []t)
- func ExtractFirstFromAST[t ast.Node](n ast.Node, kind ast.NodeKind) (found t, ok bool)
- func HELPER(name string, f interface{})
- func IGNORE_DIR(r *regexp.Regexp)
- func Listen(e PageEvent, h PageEventHandler)
- func Log(level, label, text string, args ...interface{}) func()
- func NoContent(w http.ResponseWriter, r *http.Request)
- func PREPEND_WIDGET(s widgetSpace, f func(*Page, Request) template.HTML)
- func PREPROCESSOR(f PreProcessor)
- func Partial(path string, data Locals) string
- func RenderWidget(s widgetSpace, p *Page, r Request) (o template.HTML)
- func Start()
- func Trigger(e PageEvent, p *Page)
- func VIEW(view fs.FS)
- func Vars(r Request) map[string]string
- func WIDGET(s widgetSpace, f func(*Page, Request) template.HTML)
- func WalkPages(ctx context.Context, f func(*Page))
- type Autocomplete
- type Autocompleter
- type HandlerFunc
- type Locals
- type Output
- type Page
- type PageEvent
- type PageEventHandler
- type PreProcessor
- type Request
- type Response
- type Route
- type RouteCheck
- type Suggestion
Constants ¶
const ( PUBLIC_PATH = "public" VIEWS_EXTENSION = ".html" CSRF_COOKIE_NAME = "xlog_csrf" )
const ( DEBUG = "\033[97;42m" INFO = "\033[97;42m" )
const ( TOOLS_WIDGET widgetSpace = iota SIDEBAR_WIDGET AFTER_VIEW_WIDGET ACTION_WIDGET HEAD_WIDGET )
List of widgets spaces that extensions can use to register a widgetFunc to inject content into.
Variables ¶
var ( 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 SIDEBAR bool // is sidebar displayed INDEX string // name of the index page markdown file TEMPLATE string // name of the template file used as default value for editor )
var ( // a function that renders CSRF hidden input field CSRF = csrf.TemplateField )
var MarkDownRenderer = goldmark.New( goldmark.WithExtensions( extension.GFM, extension.DefinitionList, extension.Footnote, highlighting.Highlighting, emoji.Emoji, ), 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 AUTOCOMPLETE ¶
func AUTOCOMPLETE(a Autocompleter)
this function registers an autocompleter function. it should be used by an extension to register a new autocompleter function. these functions are going to be executed when rendering the edit page.
func EXTENSION_PAGE ¶
func EXTENSION_PAGE(p string)
EXTENSION_PAGE announces a path of a page as an extension page, enables the page to be exported when building static version of the knowledgebase
func ExtractAllFromAST ¶
Extract all nodes of a specific type from the AST
func ExtractFirstFromAST ¶
This is a function that takes an AST node and walks the tree depth first recursively calling itself in search for a node of a specific kind can be used to find first image, link, paragraph...etc
func HELPER ¶
func HELPER(name string, f interface{})
HELPER registers a new helper function. all helpers are used when compiling view/templates so registering helpers function must happen before the server starts as compiling views happend right before starting the http server.
func IGNORE_DIR ¶
Register a pattern to be ignored when walking directories.
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 NoContent ¶
func NoContent(w http.ResponseWriter, r *http.Request)
NoContent an output function that writes NoContent http response
func PREPEND_WIDGET ¶
Register widget function to be rendered in a specific space before any other widget. functions registered by this function will have higher priority than the rest. this function is needed for example to register the search input before any other links in the sidebar
func PREPROCESSOR ¶
func PREPROCESSOR(f PreProcessor)
Register a PREPROCESSOR function. extensions should use this function to register a preprocessor.
func RenderWidget ¶
This is used by view and edit routes to render all widgetfuncs registered for specific widget space.
func Start ¶
func Start()
Define the catch all HTTP routes, parse CLI flags and take actions like building the static pages and exit, or start the HTTP server
func Trigger ¶ added in v0.16.0
Trigger event handlers for a specific page event. page methods use this function to trigger all registered handlers when the page is edited or deleted for example.
func VIEW ¶ added in v0.5.0
VIEW registers a filesystem as a view, views are registered such that the latest view directory override older ones. views file extensions are signified by VIEWS_EXTENSION constant and the file path can be used as template name without this extension
Types ¶
type Autocomplete ¶
type Autocomplete struct { StartChar string Suggestions []*Suggestion }
Autocomplete defines what character triggeres the autocomplete feature and what is the list to display in this case.
type Autocompleter ¶
type Autocompleter func() *Autocomplete
This is a function that returns an auto completer instance. this function should be defined by extensions and registered to be executed when rendering the edit page
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request) Output
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 Locals ¶
type Locals map[string]interface{} // passed to views/templates
Some aliases to make it easier
type Output ¶
type Output = http.HandlerFunc
Some aliases to make it easier
func BadRequest ¶
BadRequest returns an output function that writes BadRequest http response
func InternalServerError ¶
InternalServerError returns an output function that writes InternalServerError http response
func Render ¶
Render returns an output function that renders partial with data and writes it as response
func Unauthorized ¶
Unauthorized returns an output function that writes Unauthorized http response
type Page ¶
type Page struct { Name string // page name without '.md' extension // contains filtered or unexported fields }
a Type that represent a page.
func (*Page) AST ¶
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.
func (*Page) FileName ¶
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
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.
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 PreProcessor ¶
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 Route ¶
type Route struct {
// contains filtered or unexported fields
}
func DELETE ¶
func DELETE(path string, handler HandlerFunc, middlewares ...func(http.HandlerFunc) http.HandlerFunc) Route
DELETE defines a new route that gets executed when the request matches path and method is http DELETE. the list of middlewares are executed in order
func GET ¶
func GET(path string, handler HandlerFunc, middlewares ...func(http.HandlerFunc) http.HandlerFunc) Route
GET defines a new route that gets executed when the request matches path and method is http GET. the list of middlewares are executed in order
func POST ¶
func POST(path string, handler HandlerFunc, middlewares ...func(http.HandlerFunc) http.HandlerFunc) Route
POST defines a new route that gets executed when the request matches path and method is http POST. the list of middlewares are executed in order
func ROUTE ¶
func ROUTE(route http.HandlerFunc, checks ...RouteCheck) Route
ROUTE Adds a new HTTP handler function to the list of routes with a list of checks functions. the list of checks are executed when a request comes in if all of them returned true the handler function gets executed.
type RouteCheck ¶
type Suggestion ¶
type Suggestion struct { Text string // The text that gets injected in the editor if this option is choosen DisplayText string // The display text for this item in the menu. this can be more cosmetic. }
Suggestions represent an item in the list of autocomplete menu in the edit page