autosite: github.com/hkjn/autosite Index | Files

package autosite

import "github.com/hkjn/autosite"

Package autosite hosts websites automatically based on file structure.

See https://github.com/hkjn/hkjnweb for a setup (that implements http://www.hkjn.me / http://blog.hkjn.me) using this package.

Example usage:

mysite := New(
  "Some title",   // for HTML <head>
  "pages/*.tmpl", // pattern for pages on disk
  "domain.com",   // live domain
  []string{       // shared templates
    "base.tmpl",
    "other.tmpl",
  },
  func(r *http.Request) Logger {
    return appengine.NewContext(r)
  },
  !appengine.IsDevAppServer(),
  template.FuncMap{
    "live": func() bool { !appengine.IsDevAppServer() }
  },
)
mysite.Register()

This will host pages like domain.com/Foo and /Bar if there's files pages/Foo.tmpl and pages/Bar.tmpl relative to the calling package, also using "base.tmpl" and "other.tmpl" to compile the templates for rendering those pages.

The template functions specified are are available within templates, in addition to the built-in ones. In the example above, {{live}} could be used.

The following data is available within each template:

{{.Title}}: The <title> of the page.
{{.Date.Year}}, {{.Date.Month}}: Year and month that the page was
   published, if file pattern includes it.
{{.URI}}: URI to the page.

Support for blogs in autosite

Example usage:

myblog := NewBlog(
  "Some title",       // for HTML <head>
  "blog/*/*/*.tmpl",  // pattern for posts on disk
  "blogdomain.com",   // live domain
  []string{           // shared templates
    "base.tmpl",
    "blog.tmpl",
  },
  []string{           // templates for special handlers
    "base.tmpl",
    "listing.tmpl",
  },
)
myblog.Register()

This will host pages like blogdomain.com/2014/02/Foo and 2016/01/Bar if there's files blog/2014/02/Foo.tmpl and blog/2016/01/Bar.tmpl relative to the calling package, also using "base.tmpl" and "blog.tmpl" for all blog posts.

Special handlers for listing posts will be registered, using "base.tmpl" and "listing.tmpl":

* the index (/) will show all posts from all years.
* for each year YYYY that has at least one blog post, /YYYY will
  be registered, showing all posts from that year.
* for each year + month YYYY/MM that have at least one blog post,
  /YYYY/MM will be registered, showing all posts from that month
  in that year.

Within the templates for these "blog listing" handlers, the following data is available in addition to the usual:

* {{.Data.Posts}}: a slice of the posts for that unit of time (all time, one
  year, or one month, respectively)
* {{.Data.TimeUnit}}: the unit of time itself ("April, 2014",
  "2014" or "all time", respectively)

Logging helpers

Index

Package Files

autosite.go blog.go logging.go

Variables

var BaseTemplate = "base" // name of top-level template to invoke for each page

type Glogger Uses

type Glogger struct{}

Glogger implements Logger using package glog.

Note that Glogger should not be used on appengine, since attempting to write to disk causes a panic.

func (Glogger) Criticalf Uses

func (Glogger) Criticalf(format string, args ...interface{})

Criticalf is like Debugf, but at Critical level.

func (Glogger) Debugf Uses

func (Glogger) Debugf(format string, args ...interface{})

Debugf formats its arguments according to the format, analogous to fmt.Printf, and records the text as a log message at Debug level.

func (Glogger) Errorf Uses

func (Glogger) Errorf(format string, args ...interface{})

Errorf is like Debugf, but at Error level.

func (Glogger) Infof Uses

func (Glogger) Infof(format string, args ...interface{})

Infof is like Debugf, but at Info level.

func (Glogger) Warningf Uses

func (Glogger) Warningf(format string, args ...interface{})

Warningf is like Debugf, but at Warning level.

type Logger Uses

type Logger interface {
    // Debugf formats its arguments according to the format, analogous to fmt.Printf,
    // and records the text as a log message at Debug level.
    Debugf(format string, args ...interface{})

    // Infof is like Debugf, but at Info level.
    Infof(format string, args ...interface{})

    // Warningf is like Debugf, but at Warning level.
    Warningf(format string, args ...interface{})

    // Errorf is like Debugf, but at Error level.
    Errorf(format string, args ...interface{})

    // Criticalf is like Debugf, but at Critical level.
    Criticalf(format string, args ...interface{})
}

Logger specifies logging functions.

The methods are chosen to match the logging methods from appengine.Context, without needing to depend on appengine.

type LoggerFunc Uses

type LoggerFunc func(*http.Request) Logger

LoggerFunc returns a logger from a http request.

type Site Uses

type Site interface {
    Register()                           // Registers the HTTP handlers for the site.
    ChangeURI(oldURI, newURI string)     // Changes an URI.
    AddRedirect(uri, redirectURI string) // Adds a redirect URI.
}

Site represents a website.

func New Uses

func New(title, glob, liveDomain string, templates []string, logger LoggerFunc, isLive bool, tmplFuncs template.FuncMap) Site

New creates a new autosite.

New panics on errors reading templates.

func NewBlog Uses

func NewBlog(title, glob, live string, articleTmpls []string, listingTmpls []string, logger LoggerFunc, isLive bool, tmplFuncs template.FuncMap) Site

NewBlog creates a new blog.

NewBlog panics on errors reading templates. TODO(hkjn): Convert to ...Options() funcs.

Package autosite imports 10 packages (graph). Updated 2016-08-02. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).