🏷️ Added Description property for page

This commit is contained in:
Maxim Lebedev 2023-11-10 09:26:09 +06:00
parent 79b9d5174d
commit 88e0dd02e9
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
3 changed files with 49 additions and 24 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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