Documentation ¶
Index ¶
- Variables
- func ErrorReponse(status int, message string, err error) error
- func GetLog(ctx context.Context) logrus.FieldLogger
- func RequestID(r *http.Request) string
- func StoreLog(ctx context.Context, log logrus.FieldLogger) context.Context
- type App
- func (a *App) Error(ctx context.Context, w http.ResponseWriter, r *http.Request, status int, ...)
- func (a *App) GitMiddleware(next scaffold.Handler) scaffold.Handler
- func (a *App) LogMetricsMiddleware(next scaffold.Handler) scaffold.Handler
- func (a *App) NotFound(ctx context.Context, w http.ResponseWriter, r *http.Request)
- func (a *App) RedirectHome(w http.ResponseWriter, r *http.Request)
- func (a *App) Routes(router *scaffold.Router)
- func (a *App) Serve()
- func (a *App) TrailingSlashMiddleware(next scaffold.Handler) scaffold.Handler
- type Article
- type ArticleModel
- type Blog
- func (b *Blog) Article(ctx context.Context, w http.ResponseWriter, r *http.Request) error
- func (b *Blog) ArticleModel(ctx context.Context, r *http.Request, article *Article) *ArticleModel
- func (b *Blog) BaseURL(ctx context.Context, r *http.Request) *url.URL
- func (b *Blog) FileLoaderMiddleware(next scaffold.Handler) scaffold.Handler
- func (b *Blog) GitURL(r *http.Request) string
- func (b *Blog) Index(ctx context.Context, w http.ResponseWriter, r *http.Request) error
- func (b *Blog) IndexModel(ctx context.Context, r *http.Request, index Index) *IndexModel
- func (b *Blog) Routes(router *scaffold.Router)
- type Cache
- func (c *Cache) BranchInfo(branch string) (tid string, id string, err error)
- func (c *Cache) Build(tid string, id string) bool
- func (c *Cache) Clean()
- func (c *Cache) Clear()
- func (c *Cache) ClearOne(id string)
- func (c *Cache) CommitInfo(commitID string) (tid string, id string, err error)
- func (c *Cache) GetArticle(tid string, id string, article string) (*Article, bool)
- func (c *Cache) GetArticleTemplate(tid string, id string) *template.Template
- func (c *Cache) GetFile(tid string, id string, path string) (io.Reader, bool)
- func (c *Cache) GetIndex(tid string, id string) (Index, bool)
- func (c *Cache) GetIndexTemplate(tid string, id string) *template.Template
- type Config
- type Index
- type IndexModel
Constants ¶
This section is empty.
Variables ¶
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
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 ¶
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 (*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 ¶
GitMiddleware handles webdav request for the git repo
func (*App) LogMetricsMiddleware ¶
LogMetricsMiddleware logs metrics for a request
func (*App) RedirectHome ¶
func (a *App) RedirectHome(w http.ResponseWriter, r *http.Request)
RedirectHome redirects home
type ArticleModel ¶
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) ArticleModel ¶
ArticleModel creates an ArticleModel for use in the article tempalte
func (*Blog) FileLoaderMiddleware ¶
FileLoaderMiddleware is used to load files from the tree Middleware is used as it does not require a specific path
func (*Blog) IndexModel ¶
IndexModel creates an IndexModel for use in the index template
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 ¶
BranchInfo gets the commit and tree ids of a branch
func (*Cache) CommitInfo ¶
CommitInfo gets the commit and tree ids of a commit
func (*Cache) GetArticle ¶
GetArticle gets an article from tree and commit ids
func (*Cache) GetArticleTemplate ¶
GetArticleTemplate gets the template from the cache
type Index ¶
type Index []Article
Index is an article index
type IndexModel ¶
IndexModel is the model passed to the index template
func (*IndexModel) Pagination ¶
func (i *IndexModel) Pagination() template.HTML
Pagination creates pagination for the index