Documentation ¶
Overview ¶
Spock is a simple wiki software inspired by GitHub's Gollum.
Index ¶
- Constants
- Variables
- func AddAlert(message, level string, r *vRequest)
- func AddCSSClasses(pages []string, path string, html []byte) ([]byte, error)
- func AddNewPageClass(node *html.Node)
- func DeletePage(w http.ResponseWriter, r *vRequest)
- func DiffPage(w http.ResponseWriter, r *vRequest)
- func EditNewPage(page *Page, w http.ResponseWriter, r *vRequest)
- func EditPage(w http.ResponseWriter, r *vRequest)
- func IndexAllPages(w http.ResponseWriter, r *vRequest)
- func IndexRedirect(w http.ResponseWriter, r *vRequest)
- func ListPages(w http.ResponseWriter, r *vRequest)
- func LoadRiceTemplate(name string, funcMap *template.FuncMap, box *rice.Box) *template.Template
- func Login(w http.ResponseWriter, r *vRequest)
- func Logout(w http.ResponseWriter, r *vRequest)
- func LookupAuthor(r *vRequest) (fullname, email string)
- func MkMissingDirs(filename string) error
- func RenamePage(w http.ResponseWriter, r *vRequest)
- func RunServer(address string, ac *AppContext) error
- func SearchPages(w http.ResponseWriter, r *vRequest)
- func ServeFile(w http.ResponseWriter, r *vRequest)
- func ShortenPageName(name string) string
- func ShowPage(w http.ResponseWriter, r *vRequest)
- func ShowPageLog(w http.ResponseWriter, r *vRequest)
- func WithRequest(ac *AppContext, h vHandler) http.Handler
- type Alert
- type AppContext
- type CommitLog
- type CommitSignature
- type Configuration
- type GitStorage
- func (gs *GitStorage) CommitFile(path string, signature *CommitSignature, message string) (revId RevID, err error)
- func (gs *GitStorage) DeletePage(path string, signature *CommitSignature, message string) (revId RevID, err error)
- func (gs *GitStorage) DiffPage(page *Page, revA, revB string) ([]string, error)
- func (gs *GitStorage) GetLastCommit(path string) (*CommitLog, error)
- func (gs *GitStorage) JoinPath(relpath string) (string, error)
- func (gs *GitStorage) ListPages() ([]string, error)
- func (gs *GitStorage) LogsForPage(path string) (result []CommitLog, err error)
- func (gs *GitStorage) LookupPage(relpath string) (*Page, bool, error)
- func (gs *GitStorage) MakeAbsPath(path string) string
- func (gs *GitStorage) RenamePage(origPath, destPath string, signature *CommitSignature, message string) (revId RevID, err error)
- func (gs *GitStorage) SavePage(page *Page, sig *CommitSignature, message string) error
- type Index
- type LinkCollector
- type OidSet
- type Page
- func (page *Page) GetMarkup() (markup string)
- func (page *Page) Render() (html []byte, err error)
- func (page *Page) RenderPlaintext() (txt []byte, err error)
- func (page *Page) RenderPreview(content []byte) (html []byte, err error)
- func (page *Page) SetRawBytes(content []byte) (err error)
- func (page *Page) ShortName() string
- func (page *Page) String() string
- func (page *Page) ToWikiPage() (*WikiPage, error)
- type PageHeader
- type RevID
- type SearchResult
- type SearchResults
- type Storage
- type TemplateContext
- type User
- type WikiPage
Constants ¶
const (
DefaultExtension = "md"
)
const (
// IndexDirName is the name of the directory containing the bleve index
IndexDirName = ".bleve"
)
const (
NewPageCSSClass = "new-page"
)
Variables ¶
var NewPageContent = `---
title: "My page"
description: "A brief page description..."
language: "en"
---
# My document title
My first paragraph.
`
NewPageContent is the initial content of a new Wiki page.
var PAGE_EXTENSIONS = []string{"md", "rst", "txt"}
Valid page extensions.
Functions ¶
func AddCSSClasses ¶ added in v0.5.0
AddCSSClasses add the "new-page" CSS class to all the non-existent pages linked in a HTML page. The arguments are: a list of wiki pages, the dir component of the current page (used for relative links) and the raw HTML.
func AddNewPageClass ¶ added in v0.5.0
func DeletePage ¶
func DeletePage(w http.ResponseWriter, r *vRequest)
func DiffPage ¶
func DiffPage(w http.ResponseWriter, r *vRequest)
func EditNewPage ¶
func EditNewPage(page *Page, w http.ResponseWriter, r *vRequest)
func EditPage ¶
func EditPage(w http.ResponseWriter, r *vRequest)
func IndexAllPages ¶ added in v0.5.0
func IndexAllPages(w http.ResponseWriter, r *vRequest)
func IndexRedirect ¶
func IndexRedirect(w http.ResponseWriter, r *vRequest)
func ListPages ¶
func ListPages(w http.ResponseWriter, r *vRequest)
func LoadRiceTemplate ¶ added in v0.5.0
func Login ¶
func Login(w http.ResponseWriter, r *vRequest)
func Logout ¶
func Logout(w http.ResponseWriter, r *vRequest)
func LookupAuthor ¶
func LookupAuthor(r *vRequest) (fullname, email string)
func MkMissingDirs ¶
MkMissingDirs creates parent directories for the specified 'filename'.
func RenamePage ¶
func RenamePage(w http.ResponseWriter, r *vRequest)
func RunServer ¶
func RunServer(address string, ac *AppContext) error
func SearchPages ¶
func SearchPages(w http.ResponseWriter, r *vRequest)
func ServeFile ¶ added in v0.5.0
func ServeFile(w http.ResponseWriter, r *vRequest)
func ShortenPageName ¶
ShortenPageName returns the filename without the extension.
func ShowPage ¶
func ShowPage(w http.ResponseWriter, r *vRequest)
func ShowPageLog ¶
func ShowPageLog(w http.ResponseWriter, r *vRequest)
func WithRequest ¶
func WithRequest(ac *AppContext, h vHandler) http.Handler
Types ¶
type Alert ¶
Alert is used to show informational messages in the web GUI.
func GetAlerts ¶
func GetAlerts(r *vRequest, w http.ResponseWriter) []*Alert
Return a slice of session Alerts; note: will save the current session.
type AppContext ¶
type AppContext struct { SessionStore sessions.Store Storage Storage Router *mux.Router Templates map[string]*template.Template XsrfSecret string Index Index }
func (*AppContext) RenderTemplate ¶
func (ac *AppContext) RenderTemplate(name string, context TemplateContext, w http.ResponseWriter)
func (*AppContext) Search ¶
func (ac *AppContext) Search(searchQuery string, size, from int) (*bleve.SearchResult, error)
type CommitSignature ¶
The struct used when creating a new commit
type Configuration ¶
type Configuration struct {
SecretKey string `json:"secret_key"`
}
func NewConfiguration ¶
func NewConfiguration(filename string) (*Configuration, error)
func (*Configuration) Validate ¶
func (cfg *Configuration) Validate() bool
type GitStorage ¶
type GitStorage struct { WorkDir string // contains filtered or unexported fields }
func CreateGitStorage ¶
func CreateGitStorage(path string) (*GitStorage, error)
Create a new git repository, initializing it.
func OpenGitStorage ¶
func OpenGitStorage(path string, create bool) (*GitStorage, error)
Open an existing git repository, optionally creating a new one if the specified directory is not found and 'create' is true.
func (*GitStorage) CommitFile ¶
func (gs *GitStorage) CommitFile(path string, signature *CommitSignature, message string) (revId RevID, err error)
func (*GitStorage) DeletePage ¶
func (gs *GitStorage) DeletePage(path string, signature *CommitSignature, message string) (revId RevID, err error)
func (*GitStorage) DiffPage ¶
func (gs *GitStorage) DiffPage(page *Page, revA, revB string) ([]string, error)
func (*GitStorage) GetLastCommit ¶
func (gs *GitStorage) GetLastCommit(path string) (*CommitLog, error)
func (*GitStorage) JoinPath ¶ added in v0.5.0
func (gs *GitStorage) JoinPath(relpath string) (string, error)
func (*GitStorage) ListPages ¶
func (gs *GitStorage) ListPages() ([]string, error)
func (*GitStorage) LogsForPage ¶
func (gs *GitStorage) LogsForPage(path string) (result []CommitLog, err error)
func (*GitStorage) LookupPage ¶
func (gs *GitStorage) LookupPage(relpath string) (*Page, bool, error)
LookupPage is used to fetch pages from the wiki storage. The "relpath" argument refers to a page path relative to the root of the wiki; for example "notes/Linux" and "/notes/Linux" both refers to the "Linux" page found inside the "/notes" wiki directory. Remember that wiki pages are qualified by their "wiki filename", that is the page filename without the extension.
Paths are checked for directory traversal attacks and an error will be returned if the "relpath" argument refers to a file outside the wiki repository.
func (*GitStorage) MakeAbsPath ¶
func (gs *GitStorage) MakeAbsPath(path string) string
func (*GitStorage) RenamePage ¶
func (gs *GitStorage) RenamePage(origPath, destPath string, signature *CommitSignature, message string) (revId RevID, err error)
func (*GitStorage) SavePage ¶
func (gs *GitStorage) SavePage(page *Page, sig *CommitSignature, message string) error
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
func (*Index) DeletePage ¶
type LinkCollector ¶ added in v0.5.0
type Page ¶
Page is a wiki page. The Path attribute contains the relative path to the file containing the wiki page (e.g. docs/programming/python.md).
func LoadPage ¶
LoadPage loads a page from the filesystem; the "path" argument must be an absolute filename, and the "relpath" must be relative "wiki path" plus the file extension; example arguments: "/var/spock/repository/notes/Linux.md" and "notes/Linux.md".
func (*Page) GetMarkup ¶
GetMarkup return the page markup based on header informations or filename extension.
func (*Page) RenderPlaintext ¶
func (*Page) RenderPreview ¶
func (*Page) SetRawBytes ¶ added in v0.5.0
func (*Page) ShortName ¶
ShortName is the "short" (i.e. without the filename extension) name of a page.
func (*Page) ToWikiPage ¶
type PageHeader ¶
PageHeader is the optional YAML header of a wiki page.
func ParsePageBytes ¶
func ParsePageBytes(data []byte) (*PageHeader, []byte, error)
type RevID ¶
type RevID string
RevID represents a revision id; with git is the SHA hash of a commit.
type SearchResult ¶
type SearchResults ¶
type SearchResults struct { Total uint64 Took time.Duration Results []*SearchResult }
type Storage ¶
type Storage interface { JoinPath(relpath string) (string, error) // Lookup a single Page LookupPage(pagepath string) (*Page, bool, error) // CRUD RenamePage(origPath, destPath string, signature *CommitSignature, message string) (RevID, error) DeletePage(path string, signature *CommitSignature, message string) (RevID, error) SavePage(page *Page, sig *CommitSignature, message string) error // Get the commit logs for a Page. LogsForPage(path string) ([]CommitLog, error) // Get the last commit for a single Page. (deprecate?) GetLastCommit(path string) (*CommitLog, error) // List all the pages inside this Storage. ListPages() ([]string, error) // Returns a diff between the current page content and another revision. (rewrite?) DiffPage(page *Page, revA, revB string) ([]string, error) }
This is the interface to the version control system used as a backend.
type TemplateContext ¶
type TemplateContext map[string]interface{}