Documentation
¶
Index ¶
- Constants
- Variables
- func AUTOCOMPLETE(a Autocompleter)
- func BadRequest(w http.ResponseWriter, r *http.Request)
- func DELETE(path string, handler HandlerFunc, ...)
- 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 GET(path string, handler HandlerFunc, ...)
- func HELPER(name string, f interface{})
- func IGNORE_DIR(r *regexp.Regexp)
- func InternalServerError(err error) http.HandlerFunc
- func Log(level, label, text string, args ...interface{}) func()
- func NoContent(w http.ResponseWriter, r *http.Request)
- func NotFound(w http.ResponseWriter, r *http.Request)
- func POST(path string, handler HandlerFunc, ...)
- func PREPEND_WIDGET(s widgetSpace, f func(*Page, Request) template.HTML)
- func PREPROCESSOR(f PreProcessor)
- func Partial(path string, data Locals) string
- func PlainText(text string) http.HandlerFunc
- func ROUTE(route http.HandlerFunc, checks ...RouteCheck)
- func Redirect(url string) http.HandlerFunc
- func Render(path string, data Locals) http.HandlerFunc
- func RenderWidget(s widgetSpace, p *Page, r Request) (o template.HTML)
- func Start()
- func Unauthorized(w http.ResponseWriter, r *http.Request)
- 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 Handler
- type HandlerFunc
- type Locals
- type Output
- type Page
- func (p *Page) AST() ast.Node
- func (p *Page) Content() string
- func (p *Page) Delete() bool
- func (p *Page) Emoji() string
- func (p *Page) Exists() bool
- func (p *Page) FileName() string
- func (p *Page) ModTime() time.Time
- func (p *Page) RTL() bool
- func (p *Page) Render() string
- func (p *Page) Write(content string) bool
- type PageEvent
- type PageEventHandler
- type PageEventsMap
- type PreProcessor
- type Request
- type Response
- type Route
- type RouteCheck
- type Suggestion
Constants ¶
const ( STATIC_DIR_PATH = "public" ASSETS_DIR_PATH = "assets" VIEWS_EXTENSION = ".html" CSRF_COOKIE_NAME = "xlog_csrf" )
const ( KB int64 = 1 << (10 * iota) MB GB TB PB )
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 ( BIND_ADDRESS string CSRF = csrf.TemplateField )
var ( SOURCE string BUILD string READONLY bool SITENAME string SIDEBAR bool INDEX string TEMPLATE string )
var BUILD_PERMS fs.FileMode = 0744
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
var PageEvents = PageEventsMap{}
a map to keep all page events and respective list of event handlers
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 BadRequest ¶
func BadRequest(w http.ResponseWriter, r *http.Request)
func DELETE ¶
func DELETE(path string, handler HandlerFunc, middlewares ...func(http.HandlerFunc) http.HandlerFunc)
func EXTENSION_PAGE ¶
func EXTENSION_PAGE(p string)
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 GET ¶
func GET(path string, handler HandlerFunc, middlewares ...func(http.HandlerFunc) http.HandlerFunc)
func IGNORE_DIR ¶
Register a pattern to be ignored when walking directories.
func InternalServerError ¶
func InternalServerError(err error) http.HandlerFunc
func POST ¶
func POST(path string, handler HandlerFunc, middlewares ...func(http.HandlerFunc) http.HandlerFunc)
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 PlainText ¶
func PlainText(text string) http.HandlerFunc
func ROUTE ¶
func ROUTE(route http.HandlerFunc, checks ...RouteCheck)
func Redirect ¶
func Redirect(url string) http.HandlerFunc
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 Unauthorized ¶
func Unauthorized(w http.ResponseWriter, r *http.Request)
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 Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Mux/Handler ===========================================
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request) http.HandlerFunc
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 GetPageEditHandler ¶
Edit page, gets the page from path, if it doesn't exist it'll use the template.md content as default value
func GetPageHandler ¶
Shows a page. the page name is the path itself. if the page doesn't exist it redirect to edit page otherwise will render it to HTML
func PostPageHandler ¶
Save new content of the page
func RootHandler ¶
Redirect to `/index` to render the index page.
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
func (*Page) RTL ¶
checks if the page includes any arabic character if so it returns true. this is used by the editor to switch direction. it could be useful too for extensions or something
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 PageEventsMap ¶
type PageEventsMap map[PageEvent][]PageEventHandler
a map of all handlers functions registered for each page event.
func (PageEventsMap) Listen ¶
func (c PageEventsMap) 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 (PageEventsMap) Trigger ¶
func (c PageEventsMap) Trigger(e PageEvent, p *Page)
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.
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
}
Mux/Handler ===========================================
type RouteCheck ¶
Mux/Handler ===========================================
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