🏷️ Added Description property for page
This commit is contained in:
parent
79b9d5174d
commit
88e0dd02e9
|
@ -3,9 +3,10 @@ package domain
|
|||
import "golang.org/x/text/language"
|
||||
|
||||
type Page struct {
|
||||
Language language.Tag
|
||||
Params map[string]any
|
||||
Title string
|
||||
Content []byte
|
||||
Resources Resources
|
||||
Language language.Tag
|
||||
Params map[string]any
|
||||
Description string
|
||||
Title string
|
||||
Content []byte
|
||||
Resources Resources
|
||||
}
|
||||
|
|
|
@ -15,9 +15,10 @@ import (
|
|||
|
||||
type (
|
||||
Page struct {
|
||||
Title string `yaml:"title"`
|
||||
Params map[string]any `yaml:",inline"`
|
||||
Content []byte `yaml:"-"`
|
||||
Title string `yaml:"title"`
|
||||
Description string `yaml:"description"`
|
||||
Params map[string]any `yaml:",inline"`
|
||||
Content []byte `yaml:"-"`
|
||||
}
|
||||
|
||||
fileSystemPageRepository struct {
|
||||
|
@ -51,16 +52,19 @@ func (repo *fileSystemPageRepository) Get(ctx context.Context, lang language.Tag
|
|||
}
|
||||
defer f.Close()
|
||||
|
||||
data := new(Page)
|
||||
data := &Page{
|
||||
Params: make(map[string]any),
|
||||
}
|
||||
if data.Content, err = frontmatter.Parse(f, data, FrontMatterFormats...); err != nil {
|
||||
return nil, fmt.Errorf("cannot parse page content as FrontMatter: %w", err)
|
||||
}
|
||||
|
||||
return &domain.Page{
|
||||
Language: lang,
|
||||
Title: data.Title,
|
||||
Content: data.Content,
|
||||
Params: data.Params,
|
||||
Resources: make([]*domain.Resource, 0),
|
||||
Language: lang,
|
||||
Title: data.Title,
|
||||
Content: data.Content,
|
||||
Description: data.Description,
|
||||
Params: data.Params,
|
||||
Resources: make([]*domain.Resource, 0),
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -32,24 +32,44 @@ func TestGet(t *testing.T) {
|
|||
input string
|
||||
}{
|
||||
"index": {
|
||||
input: path.Join("index"),
|
||||
expect: &domain.Page{Content: []byte("index.md"), Resources: make([]*domain.Resource, 0)},
|
||||
input: path.Join("index"),
|
||||
expect: &domain.Page{
|
||||
Content: []byte("index.md"),
|
||||
Params: make(map[string]any),
|
||||
Resources: make([]*domain.Resource, 0),
|
||||
},
|
||||
},
|
||||
"file": {
|
||||
input: path.Join("file"),
|
||||
expect: &domain.Page{Content: []byte("file.md"), Resources: make([]*domain.Resource, 0)},
|
||||
input: path.Join("file"),
|
||||
expect: &domain.Page{
|
||||
Content: []byte("file.md"),
|
||||
Params: make(map[string]any),
|
||||
Resources: make([]*domain.Resource, 0),
|
||||
},
|
||||
},
|
||||
"folder": {
|
||||
input: path.Join("folder", "index"),
|
||||
expect: &domain.Page{Content: []byte("folder/index.md"), Resources: make([]*domain.Resource, 0)},
|
||||
input: path.Join("folder", "index"),
|
||||
expect: &domain.Page{
|
||||
Content: []byte("folder/index.md"),
|
||||
Params: make(map[string]any),
|
||||
Resources: make([]*domain.Resource, 0),
|
||||
},
|
||||
},
|
||||
"both-file": {
|
||||
input: path.Join("both"),
|
||||
expect: &domain.Page{Content: []byte("both.md"), Resources: make([]*domain.Resource, 0)},
|
||||
input: path.Join("both"),
|
||||
expect: &domain.Page{
|
||||
Content: []byte("both.md"),
|
||||
Params: make(map[string]any),
|
||||
Resources: make([]*domain.Resource, 0),
|
||||
},
|
||||
},
|
||||
"both-folder": {
|
||||
input: path.Join("both", "index"),
|
||||
expect: &domain.Page{Content: []byte("both/index.md"), Resources: make([]*domain.Resource, 0)},
|
||||
input: path.Join("both", "index"),
|
||||
expect: &domain.Page{
|
||||
Content: []byte("both/index.md"),
|
||||
Params: make(map[string]any),
|
||||
Resources: make([]*domain.Resource, 0),
|
||||
},
|
||||
},
|
||||
} {
|
||||
name, tc := name, tc
|
||||
|
|
Loading…
Reference in New Issue