🐛 Fixed resource paths support
This commit is contained in:
parent
e18e265d1a
commit
c7ecb8dbaf
|
@ -41,11 +41,15 @@ func NewPath(path string) Path {
|
||||||
parts := strings.Split(out.baseFileName, ".")
|
parts := strings.Split(out.baseFileName, ".")
|
||||||
out.Language = NewLanguage(parts[len(parts)-1])
|
out.Language = NewLanguage(parts[len(parts)-1])
|
||||||
out.translationBaseName = strings.Join(parts[:len(parts)-1], ".")
|
out.translationBaseName = strings.Join(parts[:len(parts)-1], ".")
|
||||||
out.contentBaseName = out.translationBaseName
|
|
||||||
|
if len(parts) == 1 {
|
||||||
|
out.translationBaseName = parts[0]
|
||||||
|
out.contentBaseName = filepath.Base(out.dir)
|
||||||
|
} else {
|
||||||
|
out.contentBaseName = out.translationBaseName
|
||||||
|
}
|
||||||
|
|
||||||
switch out.translationBaseName {
|
switch out.translationBaseName {
|
||||||
default:
|
|
||||||
out.contentBaseName = out.translationBaseName
|
|
||||||
case "_index", "index":
|
case "_index", "index":
|
||||||
out.contentBaseName = filepath.Base(out.dir)
|
out.contentBaseName = filepath.Base(out.dir)
|
||||||
}
|
}
|
||||||
|
@ -62,6 +66,7 @@ func NewPath(path string) Path {
|
||||||
// /news/a.en.md => a.en
|
// /news/a.en.md => a.en
|
||||||
// /news/b/index.en.md => index.en
|
// /news/b/index.en.md => index.en
|
||||||
// /news/_index.en.md => _index.en
|
// /news/_index.en.md => _index.en
|
||||||
|
// /news/b/photo.jpg => photo
|
||||||
func (p Path) BaseFileName() string {
|
func (p Path) BaseFileName() string {
|
||||||
return p.baseFileName
|
return p.baseFileName
|
||||||
}
|
}
|
||||||
|
@ -71,6 +76,7 @@ func (p Path) BaseFileName() string {
|
||||||
// /news/a.en.md => a
|
// /news/a.en.md => a
|
||||||
// /news/b/index.en.md => b
|
// /news/b/index.en.md => b
|
||||||
// /news/_index.en.md => news
|
// /news/_index.en.md => news
|
||||||
|
// /news/b/photo.jpg => b
|
||||||
func (p Path) ContentBaseName() string {
|
func (p Path) ContentBaseName() string {
|
||||||
return p.contentBaseName
|
return p.contentBaseName
|
||||||
}
|
}
|
||||||
|
@ -80,6 +86,7 @@ func (p Path) ContentBaseName() string {
|
||||||
// /news/a.en.md => news/
|
// /news/a.en.md => news/
|
||||||
// /news/b/index.en.md => news/b/
|
// /news/b/index.en.md => news/b/
|
||||||
// /news/_index.en.md => news/
|
// /news/_index.en.md => news/
|
||||||
|
// /news/b/photo.jpg => news/b/
|
||||||
func (p Path) Dir() string {
|
func (p Path) Dir() string {
|
||||||
return p.dir
|
return p.dir
|
||||||
}
|
}
|
||||||
|
@ -87,6 +94,7 @@ func (p Path) Dir() string {
|
||||||
// Ext returns file extention:
|
// Ext returns file extention:
|
||||||
//
|
//
|
||||||
// /news/b/index.en.md => md
|
// /news/b/index.en.md => md
|
||||||
|
// /news/b/photo.jpg => jpg
|
||||||
func (p Path) Ext() string {
|
func (p Path) Ext() string {
|
||||||
return p.ext
|
return p.ext
|
||||||
}
|
}
|
||||||
|
@ -95,11 +103,12 @@ func (p Path) Filename() string {
|
||||||
return p.filename
|
return p.filename
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogicalName returns fille file name in directory:
|
// LogicalName returns file name in directory:
|
||||||
//
|
//
|
||||||
// /news/a.en.md => a.en.md
|
// /news/a.en.md => a.en.md
|
||||||
// /news/b/index.en.md => index.en.md
|
// /news/b/index.en.md => index.en.md
|
||||||
// /news/_index.en.md => _index.en.md
|
// /news/_index.en.md => _index.en.md
|
||||||
|
// /news/b/photo.jpg => photo.jpg
|
||||||
func (p Path) LogicalName() string {
|
func (p Path) LogicalName() string {
|
||||||
return p.logicalName
|
return p.logicalName
|
||||||
}
|
}
|
||||||
|
@ -113,6 +122,7 @@ func (p Path) Path() string {
|
||||||
// /news/a.en.md => a
|
// /news/a.en.md => a
|
||||||
// /news/b/index.en.md => index
|
// /news/b/index.en.md => index
|
||||||
// /news/_index.en.md => _index
|
// /news/_index.en.md => _index
|
||||||
|
// /news/b/photo.jpg => photo
|
||||||
func (p Path) TranslationBaseName() string {
|
func (p Path) TranslationBaseName() string {
|
||||||
return p.translationBaseName
|
return p.translationBaseName
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ var (
|
||||||
testRegularPath string = filepath.Join("news", "a.en.md")
|
testRegularPath string = filepath.Join("news", "a.en.md")
|
||||||
testLeafPath string = filepath.Join("news", "b", "index.en.md")
|
testLeafPath string = filepath.Join("news", "b", "index.en.md")
|
||||||
testBranchPath string = filepath.Join("news", "_index.en.md")
|
testBranchPath string = filepath.Join("news", "_index.en.md")
|
||||||
|
testResource string = filepath.Join("news", "b", "photo.jpg")
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPath_BaseFileName(t *testing.T) {
|
func TestPath_BaseFileName(t *testing.T) {
|
||||||
|
@ -19,9 +20,10 @@ func TestPath_BaseFileName(t *testing.T) {
|
||||||
for name, tc := range map[string]struct {
|
for name, tc := range map[string]struct {
|
||||||
input, expect string
|
input, expect string
|
||||||
}{
|
}{
|
||||||
"regular": {testRegularPath, "a.en"},
|
"regular": {testRegularPath, "a.en"},
|
||||||
"leaf": {testLeafPath, "index.en"},
|
"leaf": {testLeafPath, "index.en"},
|
||||||
"branch": {testBranchPath, "_index.en"},
|
"branch": {testBranchPath, "_index.en"},
|
||||||
|
"resource": {testResource, "photo"},
|
||||||
} {
|
} {
|
||||||
name, tc := name, tc
|
name, tc := name, tc
|
||||||
|
|
||||||
|
@ -41,9 +43,10 @@ func TestPath_ContentBaseName(t *testing.T) {
|
||||||
for name, tc := range map[string]struct {
|
for name, tc := range map[string]struct {
|
||||||
input, expect string
|
input, expect string
|
||||||
}{
|
}{
|
||||||
"regular": {testRegularPath, "a"},
|
"regular": {testRegularPath, "a"},
|
||||||
"leaf": {testLeafPath, "b"},
|
"leaf": {testLeafPath, "b"},
|
||||||
"branch": {testBranchPath, "news"},
|
"branch": {testBranchPath, "news"},
|
||||||
|
"resource": {testResource, "b"},
|
||||||
} {
|
} {
|
||||||
name, tc := name, tc
|
name, tc := name, tc
|
||||||
|
|
||||||
|
@ -63,9 +66,10 @@ func TestPath_Dir(t *testing.T) {
|
||||||
for name, tc := range map[string]struct {
|
for name, tc := range map[string]struct {
|
||||||
input, expect string
|
input, expect string
|
||||||
}{
|
}{
|
||||||
"regular": {testRegularPath, "news/"},
|
"regular": {testRegularPath, "news/"},
|
||||||
"leaf": {testLeafPath, "news/b/"},
|
"leaf": {testLeafPath, "news/b/"},
|
||||||
"branch": {testBranchPath, "news/"},
|
"branch": {testBranchPath, "news/"},
|
||||||
|
"resource": {testResource, "news/b/"},
|
||||||
} {
|
} {
|
||||||
name, tc := name, tc
|
name, tc := name, tc
|
||||||
|
|
||||||
|
@ -84,18 +88,21 @@ func TestPath_Ext(t *testing.T) {
|
||||||
|
|
||||||
const expect string = "md"
|
const expect string = "md"
|
||||||
|
|
||||||
for name, input := range map[string]string{
|
for name, tc := range map[string]struct {
|
||||||
"regular": testRegularPath,
|
input, expect string
|
||||||
"leaf": testLeafPath,
|
}{
|
||||||
"branch": testBranchPath,
|
"regular": {testRegularPath, "md"},
|
||||||
|
"leaf": {testLeafPath, "md"},
|
||||||
|
"branch": {testBranchPath, "md"},
|
||||||
|
"resource": {testResource, "jpg"},
|
||||||
} {
|
} {
|
||||||
name, input := name, input
|
name, tc := name, tc
|
||||||
|
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
if actual := domain.NewPath(input).Ext(); actual != expect {
|
if actual := domain.NewPath(tc.input).Ext(); actual != tc.expect {
|
||||||
t.Errorf("Ext() = '%s', want '%s'", actual, expect)
|
t.Errorf("Ext() = '%s', want '%s'", actual, tc.expect)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -129,9 +136,10 @@ func TestPath_LogicalName(t *testing.T) {
|
||||||
for name, tc := range map[string]struct {
|
for name, tc := range map[string]struct {
|
||||||
input, expect string
|
input, expect string
|
||||||
}{
|
}{
|
||||||
"regular": {testRegularPath, "a.en.md"},
|
"regular": {testRegularPath, "a.en.md"},
|
||||||
"leaf": {testLeafPath, "index.en.md"},
|
"leaf": {testLeafPath, "index.en.md"},
|
||||||
"branch": {testBranchPath, "_index.en.md"},
|
"branch": {testBranchPath, "_index.en.md"},
|
||||||
|
"resource": {testResource, "photo.jpg"},
|
||||||
} {
|
} {
|
||||||
name, tc := name, tc
|
name, tc := name, tc
|
||||||
|
|
||||||
|
@ -151,9 +159,10 @@ func TestPath_TranslationBaseName(t *testing.T) {
|
||||||
for name, tc := range map[string]struct {
|
for name, tc := range map[string]struct {
|
||||||
input, expect string
|
input, expect string
|
||||||
}{
|
}{
|
||||||
"regular": {testRegularPath, "a"},
|
"regular": {testRegularPath, "a"},
|
||||||
"leaf": {testLeafPath, "index"},
|
"leaf": {testLeafPath, "index"},
|
||||||
"branch": {testBranchPath, "_index"},
|
"branch": {testBranchPath, "_index"},
|
||||||
|
"resource": {testResource, "photo"},
|
||||||
} {
|
} {
|
||||||
name, tc := name, tc
|
name, tc := name, tc
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue