🚚 Renamed Page domain back to Entry

This commit is contained in:
Maxim Lebedev 2024-02-04 22:33:06 +06:00
parent 6aae1ffa48
commit 4b9ce7b192
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
10 changed files with 43 additions and 43 deletions

View File

@ -3,5 +3,5 @@ package domain
// Context represent a all-in-one theme template context. // Context represent a all-in-one theme template context.
type Context struct { type Context struct {
Site *Site Site *Site
*Page Page *Entry
} }

20
internal/domain/entry.go Normal file
View File

@ -0,0 +1,20 @@
package domain
type Entry struct {
Language Language
Params map[string]any
File Path
Description string
Title string
Content []byte
Resources Resources
Translations []*Entry
}
func (e Entry) IsHome() bool {
return e.File.dir == "./" && e.File.translationBaseName == "index"
}
func (e Entry) IsTranslated() bool {
return 1 < len(e.Translations)
}

View File

@ -1,20 +0,0 @@
package domain
type Page struct {
Language Language
Params map[string]any
File Path
Description string
Title string
Content []byte
Resources Resources
Translations []*Page
}
func (p Page) IsHome() bool {
return p.File.dir == "./" && p.File.translationBaseName == "index"
}
func (p Page) IsTranslated() bool {
return 1 < len(p.Translations)
}

View File

@ -8,7 +8,7 @@ import (
) )
type Repository interface { type Repository interface {
Get(ctx context.Context, lang domain.Language, path string) (*domain.Page, error) Get(ctx context.Context, lang domain.Language, path string) (*domain.Entry, error)
// Stat checks for the existence of a page on the specified path without // Stat checks for the existence of a page on the specified path without
// parsing its contents. // parsing its contents.

View File

@ -36,7 +36,7 @@ func NewFileSystemPageRepository(dir fs.FS) entry.Repository {
} }
} }
func (repo *fileSystemPageRepository) Get(ctx context.Context, lang domain.Language, p string) (*domain.Page, error) { func (repo *fileSystemPageRepository) Get(ctx context.Context, lang domain.Language, p string) (*domain.Entry, error) {
ext := ".md" ext := ".md"
if lang != domain.LanguageUnd { if lang != domain.LanguageUnd {
ext = "." + lang.Lang() + ext ext = "." + lang.Lang() + ext
@ -57,7 +57,7 @@ func (repo *fileSystemPageRepository) Get(ctx context.Context, lang domain.Langu
return nil, fmt.Errorf("cannot parse entry content as FrontMatter: %w", err) return nil, fmt.Errorf("cannot parse entry content as FrontMatter: %w", err)
} }
return &domain.Page{ return &domain.Entry{
File: domain.NewPath(target), File: domain.NewPath(target),
Language: lang, Language: lang,
Title: data.Title, Title: data.Title,
@ -65,7 +65,7 @@ func (repo *fileSystemPageRepository) Get(ctx context.Context, lang domain.Langu
Description: data.Description, Description: data.Description,
Params: data.Params, Params: data.Params,
Resources: make([]*domain.Resource, 0), Resources: make([]*domain.Resource, 0),
Translations: make([]*domain.Page, 0), Translations: make([]*domain.Entry, 0),
}, nil }, nil
} }

View File

@ -27,52 +27,52 @@ func TestGet(t *testing.T) {
repo := repository.NewFileSystemPageRepository(testData) repo := repository.NewFileSystemPageRepository(testData)
for name, tc := range map[string]struct { for name, tc := range map[string]struct {
expect *domain.Page expect *domain.Entry
input string input string
}{ }{
"index": { "index": {
input: path.Join("index"), input: path.Join("index"),
expect: &domain.Page{ expect: &domain.Entry{
Content: []byte("index.md"), Content: []byte("index.md"),
Params: make(map[string]any), Params: make(map[string]any),
Resources: make([]*domain.Resource, 0), Resources: make([]*domain.Resource, 0),
Translations: make([]*domain.Page, 0), Translations: make([]*domain.Entry, 0),
}, },
}, },
"file": { "file": {
input: path.Join("file"), input: path.Join("file"),
expect: &domain.Page{ expect: &domain.Entry{
Content: []byte("file.md"), Content: []byte("file.md"),
Params: make(map[string]any), Params: make(map[string]any),
Resources: make([]*domain.Resource, 0), Resources: make([]*domain.Resource, 0),
Translations: make([]*domain.Page, 0), Translations: make([]*domain.Entry, 0),
}, },
}, },
"folder": { "folder": {
input: path.Join("folder", "index"), input: path.Join("folder", "index"),
expect: &domain.Page{ expect: &domain.Entry{
Content: []byte("folder/index.md"), Content: []byte("folder/index.md"),
Params: make(map[string]any), Params: make(map[string]any),
Resources: make([]*domain.Resource, 0), Resources: make([]*domain.Resource, 0),
Translations: make([]*domain.Page, 0), Translations: make([]*domain.Entry, 0),
}, },
}, },
"both-file": { "both-file": {
input: path.Join("both"), input: path.Join("both"),
expect: &domain.Page{ expect: &domain.Entry{
Content: []byte("both.md"), Content: []byte("both.md"),
Params: make(map[string]any), Params: make(map[string]any),
Resources: make([]*domain.Resource, 0), Resources: make([]*domain.Resource, 0),
Translations: make([]*domain.Page, 0), Translations: make([]*domain.Entry, 0),
}, },
}, },
"both-folder": { "both-folder": {
input: path.Join("both", "index"), input: path.Join("both", "index"),
expect: &domain.Page{ expect: &domain.Entry{
Content: []byte("both/index.md"), Content: []byte("both/index.md"),
Params: make(map[string]any), Params: make(map[string]any),
Resources: make([]*domain.Resource, 0), Resources: make([]*domain.Resource, 0),
Translations: make([]*domain.Page, 0), Translations: make([]*domain.Entry, 0),
}, },
}, },
} { } {

View File

@ -7,5 +7,5 @@ import (
) )
type UseCase interface { type UseCase interface {
Do(ctx context.Context, lang domain.Language, path string) (*domain.Page, error) Do(ctx context.Context, lang domain.Language, path string) (*domain.Entry, error)
} }

View File

@ -24,7 +24,7 @@ func NewEntryUseCase(entries entry.Repository, resources resource.Repository) en
} }
} }
func (ucase *entryUseCase) Do(ctx context.Context, lang domain.Language, p string) (*domain.Page, error) { func (ucase *entryUseCase) Do(ctx context.Context, lang domain.Language, p string) (*domain.Entry, error) {
targets := make([]string, 0) targets := make([]string, 0)
hasExt := path.Ext(p) != "" hasExt := path.Ext(p) != ""
head, tail := urlutil.ShiftPath(p) head, tail := urlutil.ShiftPath(p)

View File

@ -11,6 +11,6 @@ type (
Writer func(w io.Writer) error Writer func(w io.Writer) error
UseCase interface { UseCase interface {
Do(ctx context.Context, site *domain.Site, page *domain.Page) (Writer, error) Do(ctx context.Context, site *domain.Site, page *domain.Entry) (Writer, error)
} }
) )

View File

@ -23,16 +23,16 @@ func NewThemeUseCase(partials fs.FS, themes theme.Repository) theme.UseCase {
} }
} }
func (ucase *themeUseCase) Do(ctx context.Context, site *domain.Site, page *domain.Page) (theme.Writer, error) { func (ucase *themeUseCase) Do(ctx context.Context, s *domain.Site, e *domain.Entry) (theme.Writer, error) {
out, err := ucase.themes.Get(ctx, templateutil.New(ucase.partials, site)) out, err := ucase.themes.Get(ctx, templateutil.New(ucase.partials, s))
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot find theme: %w", err) return nil, fmt.Errorf("cannot find theme: %w", err)
} }
return func(w io.Writer) error { return func(w io.Writer) error {
return out.Lookup("baseof.html").Execute(w, &domain.Context{ return out.Lookup("baseof.html").Execute(w, &domain.Context{
Site: site, Site: s,
Page: page, Page: e,
}) })
}, nil }, nil
} }