Expand the path for a specified style file

This commit is contained in:
Nicolas Martin 2020-12-16 16:23:58 +01:00 committed by Nicolas M
commit d9242c9a72
3 changed files with 32 additions and 4 deletions

View file

@ -1,6 +1,11 @@
package utils
import "regexp"
import (
"os"
"regexp"
"github.com/mitchellh/go-homedir"
)
func RemoveFrontmatter(content []byte) []byte {
if frontmatterBoundaries := detectFrontmatter(content); frontmatterBoundaries[0] == 0 {
@ -17,3 +22,12 @@ func detectFrontmatter(c []byte) []int {
}
return []int{-1, -1}
}
// Expands tilde and all environment variables from the given path.
func ExpandPath(path string) string {
s, err := homedir.Expand(path)
if err == nil {
return os.ExpandEnv(s)
}
return os.ExpandEnv(path)
}