spock

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2014 License: GPL-2.0 Imports: 30 Imported by: 0

README

Spock wiki

Spock is a simple wiki software heavily inspired by GitHub's Gollum and is mostly intended as a personal documentation system. I wrote it as a frontend for my technical notes.

Please note: This is alpha software and should be used with caution!

Why another wiki software?

  • I don't want to fight with runtime dependencies, virtualenvs and such.
  • I have a bunch of notes written in Markdown and RestructuredText formats.
  • I like to edit wiki pages with my text editor.
  • I like to use git to maintain the history of my notes.
  • I don't want to run a full LAMP stack just to use my wiki.
  • I'm having some fun with Go.

Features

  • wiki pages can be written in Markdown or RestructuredText and can be edited with your preferred text editor
  • git is used as the underlying storage system
  • full text search (beta)
  • nice browser editor thanks to CodeMirror

NOTE: RestructuredText is not rendered by Go code, see below.

Usage

The first time you launch Spock it will need to create the repository directory:

./spock -repo ~/Documents/wiki -init

Typical usage:

./spock -repo ~/Documents/wiki

Installing Spock from sources

Requirements:

  • recent version of Go1 (tested on Go 1.3)
  • a C compiler
  • cmake (to build libgit2)
  • pkg-config (to build libgit2)
  • git (to fetch some go dependencies)
  • mercurial (to fetch some go dependencies)
  • Go 1.x (tested on Go 1.3)
  • icu4c
  • leveldb (optional)
  • Python docutils (optional, used for rst rendering)

Note: you cannot use the libgit2 package provided by your package manager because git2go needs a specific version of the library.

On a Debian based GNU/Linux system you should be able to install all the required dependencies running:

sudo apt-get install python-docutils cmake git mercurial libicu-dev libleveldb-dev

On OS X with homebrew:

brew install mercurial cmake icu4c pkg-config leveldb
Building Spock

To build Spock you first need to build git2go linking to a specific version of libgit2

go get -d github.com/libgit2/git2go
cd $GOPATH/src/github.com/libgit2/git2go
git submodule update --init
make install

NOTE: make install will only build git2go, statically linking libgit2

Now you can build Spock by running make; if you system doesn't ship with an updated version of libleveldb you can edit the Makefile and remove leveldb from the Go build tags.

To render RestructuredText pages you will also need the rst2html program, included in docutils Python package; rst2html must be present in $PATH:

sudo pip install docutils
# or
sudo easy_install docutils

Author

Daniel Kertesz daniel@spatof.org

Spock includes a copy of CodeMirror 4.5: https://github.com/marijnh/codemirror

Documentation

Overview

Spock is a simple wiki software inspired by GitHub's Gollum.

Index

Constants

View Source
const (
	DefaultExtension = "md"
)
View Source
const (
	// IndexDirName is the name of the directory containing the bleve index
	IndexDirName = ".bleve"
)
View Source
const (
	NewPageCSSClass = "new-page"
)

Variables

View Source
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.

View Source
var PAGE_EXTENSIONS = []string{"md", "rst", "txt"}

Valid page extensions.

Functions

func AddAlert

func AddAlert(message, level string, r *vRequest)

func AddCSSClasses added in v0.5.0

func AddCSSClasses(pages []string, path string, html []byte) ([]byte, error)

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 AddNewPageClass(node *html.Node)

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 LoadRiceTemplate(name string, funcMap *template.FuncMap, box *rice.Box) *template.Template

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

func MkMissingDirs(filename string) error

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

func ShortenPageName(name string) string

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

type Alert struct {
	Level   string
	Message string
}

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 CommitLog

type CommitLog struct {
	Id      string
	Message string
	Name    string
	Email   string
	When    time.Time
}

The struct used to pack all informations regarding a single VCS commit.

type CommitSignature

type CommitSignature struct {
	Name  string
	Email string
	When  time.Time
}

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 OpenIndex

func OpenIndex(basepath string) (*Index, error)

func (*Index) AddPage

func (idx *Index) AddPage(page *Page) error

func (*Index) Close

func (idx *Index) Close()

func (*Index) DeletePage

func (idx *Index) DeletePage(page *Page) error

func (*Index) DocCount

func (idx *Index) DocCount() uint64

func (*Index) IndexWiki

func (idx *Index) IndexWiki(storage Storage) error

type LinkCollector added in v0.5.0

type LinkCollector struct {
	Pages []string
	Path  string
}

func (LinkCollector) Find added in v0.5.0

func (lc LinkCollector) Find(rootNode *html.Node) []*html.Node

type OidSet

type OidSet struct {
	// contains filtered or unexported fields
}

func NewOidSet

func NewOidSet() *OidSet

func (*OidSet) Add

func (o *OidSet) Add(oid *git.Oid) bool

type Page

type Page struct {
	Path     string
	Header   *PageHeader
	RawBytes []byte
	Content  []byte
	Mtime    time.Time
}

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

func LoadPage(path, relpath string) (*Page, error)

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 NewPage

func NewPage(path string) *Page

NewPage is the preferred way to create new Page objects.

func (*Page) GetMarkup

func (page *Page) GetMarkup() (markup string)

GetMarkup return the page markup based on header informations or filename extension.

func (*Page) Render

func (page *Page) Render() (html []byte, err error)

Render renders the HTML version of a Wiki page.

func (*Page) RenderPlaintext

func (page *Page) RenderPlaintext() (txt []byte, err error)

func (*Page) RenderPreview

func (page *Page) RenderPreview(content []byte) (html []byte, err error)

func (*Page) SetRawBytes added in v0.5.0

func (page *Page) SetRawBytes(content []byte) (err error)

func (*Page) ShortName

func (page *Page) ShortName() string

ShortName is the "short" (i.e. without the filename extension) name of a page.

func (*Page) String added in v0.4.0

func (page *Page) String() string

func (*Page) ToWikiPage

func (page *Page) ToWikiPage() (*WikiPage, error)
type PageHeader struct {
	Title       string
	Description string
	Language    string
	Markup      string
}

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 SearchResult struct {
	Title     string
	Highlight template.HTML
}

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{}

type User

type User struct {
	Authenticated bool
	Name          string
	Email         string
}

User is a representation of a wiki user.

func UserFromSession

func UserFromSession(session *sessions.Session) *User

type WikiPage

type WikiPage struct {
	Title  string    `json:"title"`
	BodyEn string    `json:"body_en"`
	BodyIt string    `json:"body_it"`
	Body   string    `json:"body"`
	Mtime  time.Time `json:"mtime"`
}

func (*WikiPage) Type

func (wp *WikiPage) Type() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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