🚚 Renamed Page domain back to Entry
This commit is contained in:
parent
6aae1ffa48
commit
4b9ce7b192
|
@ -3,5 +3,5 @@ package domain
|
|||
// Context represent a all-in-one theme template context.
|
||||
type Context struct {
|
||||
Site *Site
|
||||
*Page
|
||||
Page *Entry
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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)
|
||||
}
|
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
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
|
||||
// parsing its contents.
|
||||
|
|
|
@ -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"
|
||||
if lang != domain.LanguageUnd {
|
||||
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 &domain.Page{
|
||||
return &domain.Entry{
|
||||
File: domain.NewPath(target),
|
||||
Language: lang,
|
||||
Title: data.Title,
|
||||
|
@ -65,7 +65,7 @@ func (repo *fileSystemPageRepository) Get(ctx context.Context, lang domain.Langu
|
|||
Description: data.Description,
|
||||
Params: data.Params,
|
||||
Resources: make([]*domain.Resource, 0),
|
||||
Translations: make([]*domain.Page, 0),
|
||||
Translations: make([]*domain.Entry, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -27,52 +27,52 @@ func TestGet(t *testing.T) {
|
|||
repo := repository.NewFileSystemPageRepository(testData)
|
||||
|
||||
for name, tc := range map[string]struct {
|
||||
expect *domain.Page
|
||||
expect *domain.Entry
|
||||
input string
|
||||
}{
|
||||
"index": {
|
||||
input: path.Join("index"),
|
||||
expect: &domain.Page{
|
||||
expect: &domain.Entry{
|
||||
Content: []byte("index.md"),
|
||||
Params: make(map[string]any),
|
||||
Resources: make([]*domain.Resource, 0),
|
||||
Translations: make([]*domain.Page, 0),
|
||||
Translations: make([]*domain.Entry, 0),
|
||||
},
|
||||
},
|
||||
"file": {
|
||||
input: path.Join("file"),
|
||||
expect: &domain.Page{
|
||||
expect: &domain.Entry{
|
||||
Content: []byte("file.md"),
|
||||
Params: make(map[string]any),
|
||||
Resources: make([]*domain.Resource, 0),
|
||||
Translations: make([]*domain.Page, 0),
|
||||
Translations: make([]*domain.Entry, 0),
|
||||
},
|
||||
},
|
||||
"folder": {
|
||||
input: path.Join("folder", "index"),
|
||||
expect: &domain.Page{
|
||||
expect: &domain.Entry{
|
||||
Content: []byte("folder/index.md"),
|
||||
Params: make(map[string]any),
|
||||
Resources: make([]*domain.Resource, 0),
|
||||
Translations: make([]*domain.Page, 0),
|
||||
Translations: make([]*domain.Entry, 0),
|
||||
},
|
||||
},
|
||||
"both-file": {
|
||||
input: path.Join("both"),
|
||||
expect: &domain.Page{
|
||||
expect: &domain.Entry{
|
||||
Content: []byte("both.md"),
|
||||
Params: make(map[string]any),
|
||||
Resources: make([]*domain.Resource, 0),
|
||||
Translations: make([]*domain.Page, 0),
|
||||
Translations: make([]*domain.Entry, 0),
|
||||
},
|
||||
},
|
||||
"both-folder": {
|
||||
input: path.Join("both", "index"),
|
||||
expect: &domain.Page{
|
||||
expect: &domain.Entry{
|
||||
Content: []byte("both/index.md"),
|
||||
Params: make(map[string]any),
|
||||
Resources: make([]*domain.Resource, 0),
|
||||
Translations: make([]*domain.Page, 0),
|
||||
Translations: make([]*domain.Entry, 0),
|
||||
},
|
||||
},
|
||||
} {
|
||||
|
|
|
@ -7,5 +7,5 @@ import (
|
|||
)
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
hasExt := path.Ext(p) != ""
|
||||
head, tail := urlutil.ShiftPath(p)
|
||||
|
|
|
@ -11,6 +11,6 @@ type (
|
|||
Writer func(w io.Writer) error
|
||||
|
||||
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)
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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) {
|
||||
out, err := ucase.themes.Get(ctx, templateutil.New(ucase.partials, site))
|
||||
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, s))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot find theme: %w", err)
|
||||
}
|
||||
|
||||
return func(w io.Writer) error {
|
||||
return out.Lookup("baseof.html").Execute(w, &domain.Context{
|
||||
Site: site,
|
||||
Page: page,
|
||||
Site: s,
|
||||
Page: e,
|
||||
})
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue