render

package
v0.0.0-...-d78814b Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UserRoot     *string
	DocumentRoot *string
)

Blog configuration bindings.

View Source
var Funcs = template.FuncMap{
	"StringsJoin": strings.Join,
	"NewlinesToSpace": func(text string) string {
		return strings.Replace(
			strings.Replace(text, "\n", " ", -1),
			"\r", "", -1,
		)
	},
	"Now": time.Now,
	"TrustedMarkdown": func(text string) template.HTML {
		return template.HTML(markdown.RenderTrustedMarkdown(text))
	},
}

Funcs is a global funcmap that the blog can hook its internal methods onto.

Functions

func HasHTMLSuffix

func HasHTMLSuffix(path string) bool

HasHTMLSuffix returns whether the file path will be renderable as HTML for the front-end. Basically, whether it ends with a .gohtml, .html or .md suffix and/or is an index page.

func Template

func Template(w io.Writer, r *http.Request, path string, data interface{}) error

Template responds with an HTML template.

The vars will be massaged a bit to load the global defaults (such as the website title and user login status), the user's session may be updated with new CSRF token, and other such things. If you just want to render a template without all that nonsense, use RenderPartialTemplate.

func URLFromPath

func URLFromPath(path string) string

URLFromPath returns an HTTP path that matches the file path on disk.

For example, given the file path "folder/page.md" it would return the string "/folder/page"

Types

type Filepath

type Filepath struct {
	// Canonicalized URI version of the file resolved on disk,
	// possible with a file extension injected.
	// (i.e. "/about" -> "about.html")
	URI      string
	Basename string
	Relative string // Relative path including document root (i.e. "root/about.html")
	Absolute string // Absolute path on disk (i.e. "/opt/blog/root/about.html")
}

Filepath represents a file discovered in the document roots, and maintains both its relative and absolute components.

func ResolvePath

func ResolvePath(path string) (Filepath, error)

ResolvePath matches a filesystem path to a relative request URI.

This checks the UserRoot first and then the DocumentRoot. This way the user may override templates from the core app's document root.

func (Filepath) String

func (f Filepath) String() string

Jump to

Keyboard shortcuts

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