help

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 20 Imported by: 0

README

Knowledgebase

Serves a directory of directories that contain markdown pages and images. Example structure in ./pages and example instantiation below. Supports tagging and pagination on the index.

By default, uses its own vanilla-tailwind style. Can be customised if you want by passing your own template and/or css dir.

description: A demo help page
tags:
- demo
- example
- greetings
title: Hello World

**Hello World!**

This is a totally great help page!

## More Things

There are _so_ many more things! You can bang on about them.

And you can have new lines.

Even [links](https://google.com)

* lists
* too

!["and images with alt text!"](./cat_caviar.jpg)
package routes

import (
	"log"

	"github.com/davidbanham/help"
	"github.com/gorilla/mux"
)

var errRes = func(w http.ResponseWriter, r *http.Request, code int, message string, err error) {
	log.Println("Oh no! An error!", code, message, err)
}

func init() {
	help.SetContentPath("./help/")

	// optional
	//help.UseCustomAssets("./assets/")
	//help.UseCustomTemplates("./views/*.html")

	r := mux.NewRouter()

	r.Path("/knowledgebase").
		Methods("GET").
		Handler(http.RedirectHandler("/knowledgebase/index", http.StatusFound))

	r.PathPrefix("/knowledgebase").
		Methods("GET").
		Handler(http.StripPrefix("/knowledgebase", help.Router(&errRes)))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Router

func Router(errorHandler *func(w http.ResponseWriter, r *http.Request, code int, message string, err error)) http.Handler

func ServeHelpAsset

func ServeHelpAsset(w http.ResponseWriter, r *http.Request) error

func ServeHelpIndex

func ServeHelpIndex(w http.ResponseWriter, r *http.Request) error

func ServeHelpPageAsset

func ServeHelpPageAsset(w http.ResponseWriter, r *http.Request) error

func ServeTopicPage

func ServeTopicPage(w http.ResponseWriter, r *http.Request) error

func SetContentPath

func SetContentPath(path string)

func UseCustomAssets

func UseCustomAssets(path string)

func UseCustomTemplates

func UseCustomTemplates(path string)

Types

type ErrorHandler

type ErrorHandler func(w http.ResponseWriter, r *http.Request, code int, message string, err error)

type Gettable

type Gettable interface {
	// For example, url.Values
	Get(string) string
}

type HelpTopic

type HelpTopic struct {
	Name        string
	Title       string
	Content     string
	Markup      string
	Description string
	Tags        []string
}

func (*HelpTopic) Hydrate

func (topic *HelpTopic) Hydrate() error

func (*HelpTopic) StubOut

func (topic *HelpTopic) StubOut()

type Index

type Index []HelpTopic

func BuildIndex

func BuildIndex() (Index, error)

func (Index) FilterToTag

func (index Index) FilterToTag(target string) Index

func (Index) Paginate

func (this Index) Paginate(pagination *Pagination) Index

type Pagination

type Pagination struct {
	MoreAvailable   bool
	Limit           int
	Skip            int
	DefaultPageSize int
}

func (Pagination) GivenPage

func (this Pagination) GivenPage(pageNum int) QueryPage

func (Pagination) NextPage

func (this Pagination) NextPage() url.Values

func (Pagination) Page

func (this Pagination) Page() QueryPage

func (Pagination) Pages

func (this Pagination) Pages() []int

func (*Pagination) Paginate

func (this *Pagination) Paginate(form Gettable)

func (Pagination) PaginationQuery

func (this Pagination) PaginationQuery() string

func (Pagination) PrevPage

func (this Pagination) PrevPage() url.Values

func (Pagination) Values

func (this Pagination) Values() url.Values

type QueryPage

type QueryPage struct {
	Number int
	Values url.Values
}

Jump to

Keyboard shortcuts

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