Documentation ¶
Index ¶
- Constants
- func AddTrailingSlash(path string) string
- func BytesToHTML(b []byte) template.HTML
- func Deprecated(item, alternative string, err bool)
- func DirExists(path string, fs afero.Fs) (bool, error)
- func Emoji(key string) []byte
- func Emojify(source []byte) []byte
- func ExtractTOC(content []byte) (newcontent []byte, toc []byte)
- func FirstUpper(s string) string
- func GetCacheDir(fs afero.Fs, cfg config.Provider) (string, error)
- func GetDottedRelativePath(inPath string) string
- func GetTempDir(subPath string, fs afero.Fs) string
- func GetTitleFunc(style string) func(s string) string
- func HashString(elements ...any) string
- func MD5FromFileFast(r io.ReadSeeker) (string, error)
- func MD5String(f string) string
- func NewDistinctErrorLogger() loggers.Logger
- func OpenFileForWriting(fs afero.Fs, filename string) (afero.File, error)
- func OpenFilesForWriting(fs afero.Fs, filenames ...string) (io.WriteCloser, error)
- func ReaderToBytes(lines io.Reader) []byte
- func SymbolicWalk(fs afero.Fs, root string, walker hugofs.WalkFunc) error
- func ToSlashTrimLeading(s string) string
- func TotalWords(s string) int
- func UniqueStringsReuse(s []string) []string
- func UniqueStringsSorted(s []string) []string
- func WriteToDisk(inpath string, r io.Reader, fs afero.Fs) (err error)
- type ContentSpec
- type DistinctLogger
- type PathSpec
- func (p *PathSpec) MakePath(s string) string
- func (p *PathSpec) MakePathSanitized(s string) string
- func (p *PathSpec) MakePathsSanitized(paths []string)
- func (p *PathSpec) PermalinkForBaseURL(link, baseURL string) string
- func (p *PathSpec) PrependBasePath(rel string, isAbs bool) string
- func (p *PathSpec) URLEscape(uri string) string
- func (p *PathSpec) URLize(uri string) string
- func (p *PathSpec) URLizeFilename(filename string) string
- func (p *PathSpec) UnicodeSanitize(s string) string
Constants ¶
const FilePathSeparator = string(filepath.Separator)
FilePathSeparator as defined by os.Separator.
Variables ¶
This section is empty.
Functions ¶
func AddTrailingSlash ¶
AddTrailingSlash adds a trailing Unix styled slash (/) if not already there.
func BytesToHTML ¶
BytesToHTML converts bytes to type template.HTML.
func Deprecated ¶
Deprecated informs about a deprecation, but only once for a given set of arguments' values. If the err flag is enabled, it logs as an ERROR (will exit with -1) and the text will point at the next Hugo release. The idea is two remove an item in two Hugo releases to give users and theme authors plenty of time to fix their templates.
func Emojify ¶
Emojify "emojifies" the input source. Note that the input byte slice will be modified if needed. See http://www.emoji-cheat-sheet.com/
func ExtractTOC ¶
ExtractTOC extracts Table of Contents from content.
func FirstUpper ¶
FirstUpper returns a string with the first character as upper case.
func GetCacheDir ¶
GetCacheDir returns a cache dir from the given filesystem and config. The dir will be created if it does not exist.
func GetDottedRelativePath ¶
GetDottedRelativePath expects a relative path starting after the content directory. It returns a relative path with dots ("..") navigating up the path structure.
func GetTempDir ¶
GetTempDir returns a temporary directory with the given sub path.
func GetTitleFunc ¶
GetTitleFunc returns a func that can be used to transform a string to title case.
The supported styles are ¶
- "Go" (strings.Title) - "AP" (see https://www.apstylebook.com/) - "Chicago" (see http://www.chicagomanualofstyle.org/home.html)
If an unknown or empty style is provided, AP style is what you get.
func HashString ¶
HashString returns a hash from the given elements. It will panic if the hash cannot be calculated.
func MD5FromFileFast ¶
func MD5FromFileFast(r io.ReadSeeker) (string, error)
MD5FromFileFast creates a MD5 hash from the given file. It only reads parts of the file for speed, so don't use it if the files are very subtly different. It will not close the file.
func NewDistinctErrorLogger ¶
NewDistinctErrorLogger creates a new DistinctLogger that logs ERRORs
func OpenFileForWriting ¶
OpenFileForWriting opens or creates the given file. If the target directory does not exist, it gets created.
func OpenFilesForWriting ¶
OpenFilesForWriting opens all the given filenames for writing.
func ReaderToBytes ¶
ReaderToBytes takes an io.Reader argument, reads from it and returns bytes.
func SymbolicWalk ¶
SymbolicWalk is like filepath.Walk, but it follows symbolic links.
func ToSlashTrimLeading ¶
ToSlashTrimLeading is just a filepath.ToSlaas with an added / prefix trimmer.
func TotalWords ¶
TotalWords counts instance of one or more consecutive white space characters, as defined by unicode.IsSpace, in s. This is a cheaper way of word counting than the obvious len(strings.Fields(s)).
func UniqueStringsReuse ¶
UniqueStringsReuse returns a slice with any duplicates removed. It will modify the input slice.
func UniqueStringsSorted ¶
UniqueStringsSorted UniqueStringsReuse returns a sorted slice with any duplicates removed. It will modify the input slice.
Types ¶
type ContentSpec ¶
type ContentSpec struct { Converters markup.ConverterProvider Cfg config.Provider // contains filtered or unexported fields }
ContentSpec provides functionality to render markdown content.
func NewContentSpec ¶
NewContentSpec returns a ContentSpec initialized with the appropriate fields from the given config.Provider.
func (*ContentSpec) ResolveMarkup ¶
func (c *ContentSpec) ResolveMarkup(in string) string
func (*ContentSpec) TrimShortHTML ¶
func (c *ContentSpec) TrimShortHTML(input []byte) []byte
TrimShortHTML removes the <p>/</p> tags from HTML input in the situation where said tags are the only <p> tags in the input and enclose the content of the input (whitespace excluded).
func (*ContentSpec) TruncateWordsByRune ¶
func (c *ContentSpec) TruncateWordsByRune(in []string) (string, bool)
TruncateWordsByRune truncates words by runes.
func (*ContentSpec) TruncateWordsToWholeSentence ¶
func (c *ContentSpec) TruncateWordsToWholeSentence(s string) (string, bool)
TruncateWordsToWholeSentence takes content and truncates to whole sentence limited by max number of words. It also returns whether it is truncated.
type DistinctLogger ¶
type DistinctLogger struct { loggers.Logger sync.RWMutex // contains filtered or unexported fields }
DistinctLogger ignores duplicate log statements.
type PathSpec ¶
type PathSpec struct { *paths.Paths *filesystems.BaseFs // The file systems to use Fs *hugofs.Fs // The config provider to use Cfg config.Provider }
PathSpec holds methods that decides how paths in URLs and files in Hugo should look like.
func NewPathSpec ¶
NewPathSpec creates a new PathSpec from the given filesystems and language.
func NewPathSpecWithBaseBaseFsProvided ¶
func NewPathSpecWithBaseBaseFsProvided(fs *hugofs.Fs, cfg config.Provider, baseBaseFs *filesystems.BaseFs) (*PathSpec, error)
NewPathSpecWithBaseBaseFsProvided creats a new PathSpec from the given filesystems and language. If an existing BaseFs is provided, parts of that is reused.
func (*PathSpec) MakePath ¶
MakePath takes a string with any characters and replace it so the string could be used in a path. It does so by creating a Unicode-sanitized string, with the spaces replaced, whilst preserving the original casing of the string. E.g. Social Media -> Social-Media
func (*PathSpec) MakePathSanitized ¶
MakePathSanitized creates a Unicode-sanitized string, with the spaces replaced
func (*PathSpec) MakePathsSanitized ¶
MakePathsSanitized applies MakePathSanitized on every item in the slice
func (*PathSpec) PermalinkForBaseURL ¶
PermalinkForBaseURL creates a permalink from the given link and baseURL.
func (*PathSpec) PrependBasePath ¶
PrependBasePath prepends any baseURL sub-folder to the given resource
func (*PathSpec) URLize ¶
URLize is similar to MakePath, but with Unicode handling Example:
uri: Vim (text editor) urlize: vim-text-editor
func (*PathSpec) URLizeFilename ¶
URLizeFilename creates an URL from a filename by escaping unicode letters and turn any filepath separator into forward slashes.
func (*PathSpec) UnicodeSanitize ¶
UnicodeSanitize sanitizes string to be used in Hugo URL's, allowing only a predefined set of special Unicode characters. If RemovePathAccents configuration flag is enabled, Unicode accents are also removed. Hyphens in the original input are maintained. Spaces will be replaced with a single hyphen, and sequential replacement hyphens will be reduced to one.