utils

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2017 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyToHTMLText

func ApplyToHTMLText(doc []byte, fn func(string) string) []byte

ApplyToHTMLText applies a filter only to the text within an HTML document.

func CopyFileContents

func CopyFileContents(dst, src string, perm os.FileMode) error

CopyFileContents copies the file contents from src to dst. It's not atomic and doesn't copy permissions or metadata.

func FilenameDate

func FilenameDate(s string) (t time.Time, title string, found bool)

FilenameDate returns the date for a filename that uses Jekyll post convention. It also returns a bool indicating whether a date was found.

func FollowDots

func FollowDots(data interface{}, props []string) (interface{}, error)

FollowDots applied to a property list ["a", "b", "c"] is equivalent to the Liquid data expression "data.a.b.c", except without special treatment of "first", "last", and "size".

func IsNotEmpty

func IsNotEmpty(err error) bool

IsNotEmpty returns a boolean indicating whether the error is known to report that a directory is not empty.

func LeftPad

func LeftPad(s string, n int) string

LeftPad left-pads s with spaces to n wide. It's an alternative to http://left-pad.io.

func MatchList

func MatchList(patterns []string, name string) bool

MatchList implement Jekyll include: and exclude: configurations. It reports whether any glob pattern matches the path. It panics with ErrBadPattern if any pattern is malformed. To match Jekyll, a string "dir/" matches that begins with this prefix.

func MergeStringMaps

func MergeStringMaps(ms ...map[string]interface{}) map[string]interface{}

MergeStringMaps creates a new variable map that merges its arguments, from first to last.

func MustAbs

func MustAbs(path string) string

MustAbs is like filepath.Abs, but panics instead of returning an error.

func MustRel

func MustRel(basepath, targpath string) string

MustRel is like filepath.Rel, but panics if the path cannot be relativized.

func NewPathError

func NewPathError(op, name, text string) *os.PathError

NewPathError returns an os.PathError that formats as the given text.

func PostfixWalk

func PostfixWalk(root string, walkFn filepath.WalkFunc) error

PostfixWalk is like filepath.Walk, but visits each directory after visiting its children instead of before. It does not implement SkipDir.

func ReadFileMagic

func ReadFileMagic(filename string) ([]byte, error)

ReadFileMagic returns the first four bytes of the file, with final '\r' replaced by '\n'.

func RemoveEmptyDirectories

func RemoveEmptyDirectories(root string) error

RemoveEmptyDirectories recursively removes empty directories.

func SafeReplaceAllStringFunc

func SafeReplaceAllStringFunc(re *regexp.Regexp, src string, repl func(m string) (string, error)) (out string, err error)

SafeReplaceAllStringFunc is like regexp.ReplaceAllStringFunc but passes an an error back from the replacement function.

func SearchStrings

func SearchStrings(array []string, s string) bool

SearchStrings returns a bool indicating whether array contains the string. Unlike sort.SearchStrings, it does not require a sorted array. This is useful when the array length is low; else consider sorting it and using sort.SearchStrings, or creating a map[string]bool.

func Slugify

func Slugify(s string) string

Slugify replaces each sequence of non-alphanumerics by a single hyphen

func StringArrayToMap

func StringArrayToMap(a []string) map[string]bool

StringArrayToMap creates a map for use as a set.

func StringSet

func StringSet(array []string) map[string]bool

StringSet creates a characteristic function map that tests for presence in an array.

func TrimExt

func TrimExt(name string) string

TrimExt returns a path without its extension, if any

func URLJoin

func URLJoin(paths ...string) string

URLJoin interpolates paths with "/", skipping empty paths and avoiding "//".

func URLPathClean

func URLPathClean(url string) string

URLPathClean removes internal // etc. Unlike path.Clean, it leaves the final "/" intact.

func UnmarshalYAMLInterface

func UnmarshalYAMLInterface(b []byte, i *interface{}) error

UnmarshalYAMLInterface is a wrapper for yaml.Unmarshall that knows how to unmarshal maps and lists.

func VisitCreatedFile

func VisitCreatedFile(filename string, w func(io.Writer) error) (err error)

VisitCreatedFile calls os.Create to create a file, and applies w to it.

func WrapPathError

func WrapPathError(err error, path string) error

WrapPathError returns an error that will print with a path.\ It wraps its argument if it is not nil and does not already provide a path.

Types

type PathError

type PathError interface {
	error
	Path() string
}

A PathError is an error with a source path.

An os.PathError is unfortunately not a PathError, but this is still useful for deciding whether to wrap other errors.

Jump to

Keyboard shortcuts

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