Documentation ¶
Index ¶
- Constants
- func AddTrailingFileSeparator(s string) string
- func BytesToHTML(b []byte) template.HTML
- func DirExists(path string, fs afero.Fs) (bool, error)
- func Emojify(source []byte) []byte
- func Exists(path string, fs afero.Fs) (bool, error)
- func ExtractRootPaths(paths []string) []string
- func FindCWD() (string, error)
- func FirstUpper(s string) string
- func FormatByteCount(bc uint64) string
- func GetDottedRelativePath(inPath string) string
- func GetTempDir(subPath string, fs afero.Fs) string
- func GetTitleFunc(style string) func(s string) string
- func HasStringsPrefix(s, prefix []string) bool
- func HasStringsSuffix(s, suffix []string) bool
- func IsDir(path string, fs afero.Fs) (bool, error)
- func IsEmpty(path string, fs afero.Fs) (bool, error)
- func IsWhitespace(r rune) bool
- func MD5FromReader(r io.Reader) (string, error)
- func MD5FromReaderFast(r io.ReadSeeker) (string, int64, error)
- func MD5String(f string) string
- func MakePathRelative(inPath string, possibleDirectories ...string) (string, error)
- func MakeTitle(inpath string) string
- func OpenFileForWriting(fs afero.Fs, filename string) (afero.File, error)
- func OpenFilesForWriting(fs afero.Fs, filenames ...string) (io.WriteCloser, error)
- func PrintFs(fs afero.Fs, path string, w io.Writer)
- func ReaderContains(r io.Reader, subslice []byte) bool
- func ReaderToBytes(lines io.Reader) []byte
- func ReaderToString(lines io.Reader) string
- func SafeWriteToDisk(inpath string, r io.Reader, fs afero.Fs) (err error)
- func SliceToLower(s []string) []string
- func StripHTML(s string) string
- func TCPListen() (net.Listener, *net.TCPAddr, error)
- func UniqueStrings(s []string) []string
- func UniqueStringsReuse(s []string) []string
- func UniqueStringsSorted(s []string) []string
- func WriteToDisk(inpath string, r io.Reader, fs afero.Fs) (err error)
- type NamedSlice
Constants ¶
const FilePathSeparator = string(filepath.Separator)
FilePathSeparator as defined by os.Separator.
Variables ¶
This section is empty.
Functions ¶
func BytesToHTML ¶
BytesToHTML converts bytes to type template.HTML.
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 ExtractRootPaths ¶
ExtractRootPaths extracts the root paths from the supplied list of paths. The resulting root path will not contain any file separators, but there may be duplicates. So "/content/section/" becomes "content"
func FirstUpper ¶
FirstUpper returns a string with the first character as upper case.
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 https://www.chicagomanualofstyle.org/home.html) - "FirstUpper" (only the first character is upper case) - "None" (no transformation)
If an unknown or empty style is provided, AP style is what you get.
func HasStringsPrefix ¶
HasStringsPrefix tests whether the string slice s begins with prefix slice s.
func HasStringsSuffix ¶
HasStringsSuffix tests whether the string slice s ends with suffix slice s.
func IsEmpty ¶
IsEmpty checks if a given path is empty, meaning it doesn't contain any regular files.
func IsWhitespace ¶
IsWhitespace determines if the given rune is whitespace.
func MD5FromReader ¶
MD5FromReader creates a MD5 hash from the given reader.
func MD5FromReaderFast ¶
func MD5FromReaderFast(r io.ReadSeeker) (string, int64, error)
MD5FromReaderFast 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. It will return the MD5 hash and the size of r in bytes.
func MakePathRelative ¶
MakeTitleInPath converts the path given to a suitable title, trimming whitespace
func MakeTitle ¶
MakeTitle converts the path given to a suitable title, trimming whitespace and replacing hyphens with whitespace.
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 PrintFs ¶
PrintFs prints the given filesystem to the given writer starting from the given path. This is useful for debugging.
func ReaderContains ¶
ReaderContains reports whether subslice is within r.
func ReaderToBytes ¶
ReaderToBytes takes an io.Reader argument, reads from it and returns bytes.
func ReaderToString ¶
ReaderToString is the same as ReaderToBytes, but returns a string.
func SafeWriteToDisk ¶
SafeWriteToDisk is the same as WriteToDisk but it also checks to see if file/directory already exists.
func SliceToLower ¶
SliceToLower goes through the source slice and lowers all values.
func UniqueStrings ¶
UniqueStrings returns a new slice with any duplicates removed.
func UniqueStringsReuse ¶
UniqueStringsReuse returns a slice with any duplicates removed. It will modify the input slice.
func UniqueStringsSorted ¶
UniqueStringsSorted returns a sorted slice with any duplicates removed. It will modify the input slice.
Types ¶
type NamedSlice ¶
func ExtractAndGroupRootPaths ¶
func ExtractAndGroupRootPaths(paths []string) []NamedSlice
func (NamedSlice) String ¶
func (n NamedSlice) String() string