Big refactor of how source files are used. Also added default destination extension option.

This commit is contained in:
spf13 2014-10-16 20:20:09 -04:00
parent 24bbfe7d32
commit 5dfc1dedb8
24 changed files with 646 additions and 465 deletions

View file

@ -166,16 +166,52 @@ func FileAndExt(in string) (name string, ext string) {
return
}
func GetRelativePath(path, base string) (final string, err error) {
if filepath.IsAbs(path) && base == "" {
return "", errors.New("source: missing base directory")
}
name := filepath.Clean(path)
base = filepath.Clean(base)
name, err = filepath.Rel(base, name)
if err != nil {
return "", err
}
name = filepath.ToSlash(name)
return name, nil
}
// Given a source path, determine the section
func GuessSection(in string) string {
x := strings.Split(in, "/")
x = x[:len(x)-1]
if len(x) == 0 {
parts := strings.Split(in, "/")
if len(parts) == 0 {
return ""
}
if x[0] == "content" {
x = x[1:]
// trim filename
if !strings.HasSuffix(in, "/") {
parts = parts[:len(parts)-1]
}
return path.Join(x...)
if len(parts) == 0 {
return ""
}
// if first directory is "content", return second directory
section := ""
if parts[0] == "content" && len(parts) > 1 {
section = parts[1]
} else {
section = parts[0]
}
if section == "." {
return ""
}
return section
}
func PathPrep(ugly bool, in string) string {