blog

package module
v0.0.0-...-8cce6fd Latest Latest
Warning

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

Go to latest
Published: May 24, 2016 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ArticleTemplate, _ = template.New("article").Parse(`<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>Git based blogging</title> <meta name="description" content="Adam Talbot's code ramblings"> <meta name="author" content="Adam Talbot"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.4.1/themes/prism.min.css"> <style>@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,800); html, body{padding: 0; margin: 0; font-family: 'Open Sans', sans-serif;}.header{background: #222; padding: 0.8em 1em; color: #CCC;}.header:after{content:''; display:block; clear:both;}.header__logo{display: inline-block; text-align: center; font-weight: 900; font-family: monospace; font-size: 25px; border: 2px solid #CCCCCC; padding: 2px 5px; margin: 0 0.8em; vertical-align: middle;}.header__title{display: inline-block; vertical-align: middle;}.header__git{display: inline-block; float: right; font-style: italic; font-family: monospace;}.home{display:block; margin: 1em;}.article{border: 2px solid #222; margin: 1em; padding: 1em;}</style></head><body> <header class="header"> <div class="header__logo">B L<br/>O G</div><h1 class="header__title">Git based blogging</h1> <div class="header__git">git clone {{.GitURL}}</div></header> <a class="home" href="{{.BaseURL}}">Home</a> <div class="article"> <p>{{.Article.Full}}</p><i>Posted on {{.Article.Mod}}</i> </div><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.4.1/prism.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.4.1/components/prism-go.min.js"></script></body></html>`)

ArticleTemplate is the default article template

View Source
var IndexTemplate, _ = template.New("index").Parse(`<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>Git based blogging</title> <meta name="description" content="Adam Talbot's code ramblings"> <meta name="author" content="Adam Talbot"> <style>@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,800); html, body{padding: 0; margin: 0; font-family: 'Open Sans', sans-serif;}.header{background: #222; padding: 0.8em 1em; color: #CCC;}.header:after{content:''; display:block; clear:both;}.header__logo{display: inline-block; text-align: center; font-weight: 900; font-family: monospace; font-size: 25px; border: 2px solid #CCCCCC; padding: 2px 5px; margin: 0 0.8em; vertical-align: middle;}.header__title{display: inline-block; vertical-align: middle;}.header__git{display: inline-block; float: right; font-style: italic; font-family: monospace;}.article{border: 2px solid #222; margin: 1em; padding: 1em;}.pagination{text-align: center;}.pagination a{text-decoration: none;}</style></head><body> <header class="header"> <div class="header__logo">B L<br/>O G</div><h1 class="header__title">Git based blogging</h1> <div class="header__git">git clone {{.GitURL}}</div></header>{{range $article :=.Articles}}<div class="article"> <p>{{$article.Preview $.BaseURL}}</p><i>Posted on {{$article.Mod}}</i> </div>{{end}}<div class="pagination">{{.Pagination}}</div></body></html>`)

IndexTemplate is the default index template

Functions

func ErrorReponse

func ErrorReponse(status int, message string, err error) error

func GetLog

func GetLog(ctx context.Context) logrus.FieldLogger

GetLog gets the log

func RequestID

func RequestID(r *http.Request) string

RequestID generates a request id from a request

func StoreLog

func StoreLog(ctx context.Context, log logrus.FieldLogger) context.Context

StoreLog stores a log in the context

Types

type App

type App struct {
	Config *Config         `inject:""`
	Repo   *git.Repository `inject:""`
	Blog   *Blog           `inject:""`
	// contains filtered or unexported fields
}

App is the base platform

func NewApp

func NewApp(config *Config) (*App, error)

NewApp creates a new app and injects dependencies into graph

func (*App) Error

func (a *App) Error(ctx context.Context, w http.ResponseWriter, r *http.Request, status int, err error)

Error is a scaffold error handler

func (*App) GitMiddleware

func (a *App) GitMiddleware(next scaffold.Handler) scaffold.Handler

GitMiddleware handles webdav request for the git repo

func (*App) LogMetricsMiddleware

func (a *App) LogMetricsMiddleware(next scaffold.Handler) scaffold.Handler

LogMetricsMiddleware logs metrics for a request

func (*App) NotFound

func (a *App) NotFound(ctx context.Context, w http.ResponseWriter, r *http.Request)

NotFound is a not found handler

func (*App) RedirectHome

func (a *App) RedirectHome(w http.ResponseWriter, r *http.Request)

RedirectHome redirects home

func (*App) Routes

func (a *App) Routes(router *scaffold.Router)

Routes implements scaffold.Platform.Router

func (*App) Serve

func (a *App) Serve()

Serve the application

func (*App) TrailingSlashMiddleware

func (a *App) TrailingSlashMiddleware(next scaffold.Handler) scaffold.Handler

TrailingSlashMiddleware forces urls without extensions to have trailing slashes

type Article

type Article struct {
	Name string
	Mod  time.Time
	Data []byte
}

Article contains information on an article

func (*Article) Full

func (a *Article) Full() template.HTML

Full returns the full article

func (*Article) Preview

func (a *Article) Preview(baseURL *url.URL) template.HTML

Preview generates a preview for the article listing

type ArticleModel

type ArticleModel struct {
	GitURL  string
	Article *Article
	BaseURL *url.URL
}

ArticleModel is the model passed to the article template

type Blog

type Blog struct {
	Repo   *git.Repository `inject:""`
	Config *Config         `inject:""`
	Cache  *Cache          `inject:""`
}

Blog is the blog platfomr

func (*Blog) Article

func (b *Blog) Article(ctx context.Context, w http.ResponseWriter, r *http.Request) error

Article is the article handler

func (*Blog) ArticleModel

func (b *Blog) ArticleModel(ctx context.Context, r *http.Request, article *Article) *ArticleModel

ArticleModel creates an ArticleModel for use in the article tempalte

func (*Blog) BaseURL

func (b *Blog) BaseURL(ctx context.Context, r *http.Request) *url.URL

BaseURL calculates the base url, for example / or /branch/master/

func (*Blog) FileLoaderMiddleware

func (b *Blog) FileLoaderMiddleware(next scaffold.Handler) scaffold.Handler

FileLoaderMiddleware is used to load files from the tree Middleware is used as it does not require a specific path

func (*Blog) GitURL

func (b *Blog) GitURL(r *http.Request) string

GitURL calculates the git url based on the request host

func (*Blog) Index

func (b *Blog) Index(ctx context.Context, w http.ResponseWriter, r *http.Request) error

Index is the index handler

func (*Blog) IndexModel

func (b *Blog) IndexModel(ctx context.Context, r *http.Request, index Index) *IndexModel

IndexModel creates an IndexModel for use in the index template

func (*Blog) Routes

func (b *Blog) Routes(router *scaffold.Router)

Routes implements scaffold.Platform.Routes

type Cache

type Cache struct {
	Repo *git.Repository `inject:""`

	Branches map[string]*commitInfo
	Commits  map[string]*commitInfo
	// contains filtered or unexported fields
}

Cache gets and caches file trees and articles

func (*Cache) BranchInfo

func (c *Cache) BranchInfo(branch string) (tid string, id string, err error)

BranchInfo gets the commit and tree ids of a branch

func (*Cache) Build

func (c *Cache) Build(tid string, id string) bool

Build gets and caches information on a tree and commit id combo

func (*Cache) Clean

func (c *Cache) Clean()

Clean removes old cached items

func (*Cache) Clear

func (c *Cache) Clear()

Clear clears the cache

func (*Cache) ClearOne

func (c *Cache) ClearOne(id string)

ClearOne clears the cache for one commit id

func (*Cache) CommitInfo

func (c *Cache) CommitInfo(commitID string) (tid string, id string, err error)

CommitInfo gets the commit and tree ids of a commit

func (*Cache) GetArticle

func (c *Cache) GetArticle(tid string, id string, article string) (*Article, bool)

GetArticle gets an article from tree and commit ids

func (*Cache) GetArticleTemplate

func (c *Cache) GetArticleTemplate(tid string, id string) *template.Template

GetArticleTemplate gets the template from the cache

func (*Cache) GetFile

func (c *Cache) GetFile(tid string, id string, path string) (io.Reader, bool)

GetFile gets a file from tree and commit ids

func (*Cache) GetIndex

func (c *Cache) GetIndex(tid string, id string) (Index, bool)

GetIndex gets an Index from tree and commit ids

func (*Cache) GetIndexTemplate

func (c *Cache) GetIndexTemplate(tid string, id string) *template.Template

GetIndexTemplate gets the template from the cache

type Config

type Config struct {
	Path   string `json:"path"`
	Listen string `json:"listen"`
}

Config is the blog config

type Index

type Index []Article

Index is an article index

func (Index) Len

func (i Index) Len() int

func (Index) Less

func (i Index) Less(e, j int) bool

func (Index) Page

func (i Index) Page(page int, length int) []Article

Page gets the articles on a given page given a page length

func (Index) Pages

func (i Index) Pages(length int) int

Pages is the number of pages given a page length

func (Index) Swap

func (i Index) Swap(e, j int)

type IndexModel

type IndexModel struct {
	GitURL   string
	Page     int
	Count    int
	Articles []Article
	BaseURL  *url.URL
}

IndexModel is the model passed to the index template

func (*IndexModel) Pagination

func (i *IndexModel) Pagination() template.HTML

Pagination creates pagination for the index

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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