🎨 Formatted FileSystem Page repository due Files property changes

This commit is contained in:
Maxim Lebedev 2023-11-09 06:50:57 +06:00
parent 6ae785ebc9
commit 7d8246e901
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
2 changed files with 10 additions and 9 deletions

View File

@ -36,17 +36,17 @@ func NewFileSystemPageRepository(rootDir fs.FS) page.Repository {
}
}
func (repo *fileSystemPageRepository) Get(ctx context.Context, lang language.Tag, path string) (*domain.Page, error) {
func (repo *fileSystemPageRepository) Get(ctx context.Context, lang language.Tag, p string) (*domain.Page, error) {
ext := ".md"
if lang != language.Und {
ext = "." + lang.String() + ext
}
target := path + ext
index := p + ext
f, err := repo.dir.Open(target)
f, err := repo.dir.Open(index)
if err != nil {
return nil, fmt.Errorf("cannot open '%s' page file: %w", target, err)
return nil, fmt.Errorf("cannot open '%s' page file: %w", index, err)
}
defer f.Close()
@ -60,5 +60,6 @@ func (repo *fileSystemPageRepository) Get(ctx context.Context, lang language.Tag
Title: data.Title,
Content: data.Content,
Params: data.Params,
Files: make([]*domain.File, 0),
}, nil
}

View File

@ -33,23 +33,23 @@ func TestGet(t *testing.T) {
}{
"index": {
input: path.Join("index"),
expect: &domain.Page{Content: []byte("index.md")},
expect: &domain.Page{Content: []byte("index.md"), Files: make([]*domain.File, 0)},
},
"file": {
input: path.Join("file"),
expect: &domain.Page{Content: []byte("file.md")},
expect: &domain.Page{Content: []byte("file.md"), Files: make([]*domain.File, 0)},
},
"folder": {
input: path.Join("folder", "index"),
expect: &domain.Page{Content: []byte("folder/index.md")},
expect: &domain.Page{Content: []byte("folder/index.md"), Files: make([]*domain.File, 0)},
},
"both-file": {
input: path.Join("both"),
expect: &domain.Page{Content: []byte("both.md")},
expect: &domain.Page{Content: []byte("both.md"), Files: make([]*domain.File, 0)},
},
"both-folder": {
input: path.Join("both", "index"),
expect: &domain.Page{Content: []byte("both/index.md")},
expect: &domain.Page{Content: []byte("both/index.md"), Files: make([]*domain.File, 0)},
},
} {
name, tc := name, tc