diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-12-30 09:20:58 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-01-04 18:01:26 +0100 |
commit | e402d91ee199afcace8ae75da6c3587bb8089ace (patch) | |
tree | a0f51de9707ed03aa1a3d7a9195fd9d0fceab108 /tpl/path | |
parent | 3c51625c7152abca7e035fae15fc6807ca21cc86 (diff) | |
download | hugo-e402d91ee199afcace8ae75da6c3587bb8089ace.tar.gz hugo-e402d91ee199afcace8ae75da6c3587bb8089ace.zip |
Misc doc, code refactoring to improve documentation
Diffstat (limited to 'tpl/path')
-rw-r--r-- | tpl/path/path.go | 19 | ||||
-rw-r--r-- | tpl/path/path_test.go | 11 |
2 files changed, 10 insertions, 20 deletions
diff --git a/tpl/path/path.go b/tpl/path/path.go index 378b97e03..59add2152 100644 --- a/tpl/path/path.go +++ b/tpl/path/path.go @@ -15,11 +15,11 @@ package path import ( - "fmt" _path "path" "path/filepath" "strings" + "github.com/gohugoio/hugo/common/paths" "github.com/gohugoio/hugo/deps" "github.com/spf13/cast" ) @@ -36,17 +36,6 @@ type Namespace struct { deps *deps.Deps } -// DirFile holds the result from path.Split. -type DirFile struct { - Dir string - File string -} - -// Used in test. -func (df DirFile) String() string { - return fmt.Sprintf("%s|%s", df.Dir, df.File) -} - // Ext returns the file name extension used by path. // The extension is the suffix beginning at the final dot // in the final slash-separated element of path; @@ -117,15 +106,15 @@ func (ns *Namespace) BaseName(path any) (string, error) { // The input path is passed into filepath.ToSlash converting any Windows slashes // to forward slashes. // The returned values have the property that path = dir+file. -func (ns *Namespace) Split(path any) (DirFile, error) { +func (ns *Namespace) Split(path any) (paths.DirFile, error) { spath, err := cast.ToStringE(path) if err != nil { - return DirFile{}, err + return paths.DirFile{}, err } spath = filepath.ToSlash(spath) dir, file := _path.Split(spath) - return DirFile{Dir: dir, File: file}, nil + return paths.DirFile{Dir: dir, File: file}, nil } // Join joins any number of path elements into a single path, adding a diff --git a/tpl/path/path_test.go b/tpl/path/path_test.go index 599d8367a..cc49bf28c 100644 --- a/tpl/path/path_test.go +++ b/tpl/path/path_test.go @@ -18,6 +18,7 @@ import ( "testing" qt "github.com/frankban/quicktest" + "github.com/gohugoio/hugo/common/paths" "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/deps" ) @@ -157,7 +158,7 @@ func TestJoin(t *testing.T) { `baz/foo/bar.txt`, }, { - []any{"", "baz", DirFile{"big", "john"}, filepath.FromSlash(`foo/bar.txt`)}, + []any{"", "baz", paths.DirFile{Dir: "big", File: "john"}, filepath.FromSlash(`foo/bar.txt`)}, `baz/big|john/foo/bar.txt`, }, {nil, ""}, @@ -186,10 +187,10 @@ func TestSplit(t *testing.T) { path any expect any }{ - {filepath.FromSlash(`foo/bar.txt`), DirFile{`foo/`, `bar.txt`}}, - {filepath.FromSlash(`foo/bar/txt `), DirFile{`foo/bar/`, `txt `}}, - {`foo.bar.txt`, DirFile{``, `foo.bar.txt`}}, - {``, DirFile{``, ``}}, + {filepath.FromSlash(`foo/bar.txt`), paths.DirFile{Dir: `foo/`, File: `bar.txt`}}, + {filepath.FromSlash(`foo/bar/txt `), paths.DirFile{Dir: `foo/bar/`, File: `txt `}}, + {`foo.bar.txt`, paths.DirFile{Dir: ``, File: `foo.bar.txt`}}, + {``, paths.DirFile{Dir: ``, File: ``}}, // errors {tstNoStringer{}, false}, } { |