Documentation
¶
Overview ¶
Package utils contains utility functions.
Index ¶
- func AbsPaths(urlPrefix, html string) string
- func AddIndexIfNeeded(filename string) string
- func CleanPermalink(s string) string
- func DirExist(path string) bool
- func HasFileExt(filename string, extensions []string) bool
- func Hash(data []byte) []byte
- func NoVowelsHexEncode(b []byte) string
- func OpenEditor(filename string) error
- func OpenURL(addr string) error
- func ParseAnyDate(s string) (d time.Time, err error)
- func ReplaceFileExt(filename string, ext string) string
- func SplitTags(tags string) []string
- func StripEndSlash(s string) string
- func StripHTMLTags(s string) (output string)
- func TemplatedHash(template string, input []byte) string
- func ToSlug(title string) string
- func UnmarshallYAMLFile(filename string, data interface{}) error
- type Pool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AbsPaths ¶
AbsPaths adds urlPrefix to paths of src and href attributes in html starting with a slash (/).
func AddIndexIfNeeded ¶
AddIndexIfNeeded adds "index.html" to the filename if it ends with a slash. Otherwise returns the original filename.
func CleanPermalink ¶
CleanPermalink returns a cleaned version of permalink: without index.htm[l] ending and starting with slash.
func HasFileExt ¶
Returns true if filename has one of the given extension. Extensions must start with dot.
func NoVowelsHexEncode ¶
NoVowelsHexEncode returns bytes encoded in a hex-like encoding which doesn't use vowels.
This is useful to avoid producing substrings, such as "ad", that may be blocked by ad-blockers.
func OpenEditor ¶
OpenEditor launches editor for editing the given file.
func ParseAnyDate ¶
ParseAnyDate parses date in any of the few allowed formats.
func ReplaceFileExt ¶
ReplaceExtension replaces file extension with the given string. Extension must start with dot.
func StripEndSlash ¶
StripEndSlash returns a string with ending slash removed, or if there was no slash, returns the original string.
func StripHTMLTags ¶
func TemplatedHash ¶
TemplatedHash replaces ":hash" in template with hexadecimal characters of the hash of the input string and returns the result.
func ToSlug ¶
ToSlug creates a slug from a title, for example "Hello, world!" becomes "hello-world". Only supports Latin characters, others are replaced with dashes.
func UnmarshallYAMLFile ¶
UnmarshallYAMLFile reads YAML file and unmarshalls it into data.
Types ¶
type Pool ¶
Pool is a worker pool for parallel job processing.
func NewPool ¶
func NewPool() *Pool
NewPool creates a new pool which calls fn for each added item and stores the first returned error.
func (*Pool) Add ¶
Add adds a new job to pool. Function passed to Add will be called for each job in a worker goroutine.
If Add returns false, which happens if one of the previously added jobs returned an error, the job will not be added to the pool.
After finishing adding items, Wait must be called on the pool to wait for unfinished jobs to complete and get the first error.