🔥 Simplify resources importing in Site and Page use cases
This commit is contained in:
parent
e35053f2d0
commit
4dc271dfc3
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"path"
|
||||
"slices"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
|
||||
|
@ -50,19 +49,7 @@ func (ucase *pageUseCase) Do(ctx context.Context, lang language.Tag, p string) (
|
|||
continue
|
||||
}
|
||||
|
||||
if out.Resources, _, err = ucase.statics.Fetch(ctx, path.Dir(targets[i])); err != nil {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
for j := 0; j < len(out.Resources); j++ {
|
||||
if ext := out.Resources[j].Ext(); ext != "html" && ext != "md" {
|
||||
continue
|
||||
}
|
||||
|
||||
out.Resources = slices.Delete(out.Resources, j, j+1)
|
||||
|
||||
j--
|
||||
}
|
||||
out.Resources, _, _ = ucase.statics.Fetch(ctx, path.Dir(targets[i]))
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package usecase
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
|
||||
|
@ -30,17 +29,7 @@ func (ucase *siteUseCase) Do(ctx context.Context, lang language.Tag) (*domain.Si
|
|||
return nil, fmt.Errorf("cannot find base site data: %w", err)
|
||||
}
|
||||
|
||||
if out.Resources, _, err = ucase.statics.Fetch(ctx, "."); err == nil {
|
||||
for i := 0; i < len(out.Resources); i++ {
|
||||
if ext := out.Resources[i].Ext(); ext != "html" && ext != "md" {
|
||||
continue
|
||||
}
|
||||
|
||||
out.Resources = slices.Delete(out.Resources, i, i+1)
|
||||
|
||||
i--
|
||||
}
|
||||
}
|
||||
out.Resources, _, _ = ucase.statics.Fetch(ctx, ".")
|
||||
|
||||
sub, err := ucase.sites.Get(ctx, lang)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue