feat: public API, SEO and existing surfaces
This commit is contained in:
1 parent
45fbbc33b1
commit
c390fcfe8d
103 files changed
+4476
-231
No files matched your search
@@ -2,6 +2,8 @@ package useCases
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/article"
|
||||
"RenewCMS/internal/domain/language"
|
||||
"RenewCMS/internal/domain/localization"
|
||||
"RenewCMS/internal/domain/site"
|
||||
"time"
|
||||
)
|
||||
@@ -9,16 +11,18 @@ import (
|
||||
type ListSitemapUseCase struct {
|
||||
articleRepository article.Repository
|
||||
sites site.Repository
|
||||
localization localization.Repository
|
||||
}
|
||||
|
||||
func NewListSitemapUseCase(articleRepository article.Repository, sites site.Repository) *ListSitemapUseCase {
|
||||
return &ListSitemapUseCase{articleRepository: articleRepository, sites: sites}
|
||||
func NewListSitemapUseCase(articleRepository article.Repository, sites site.Repository, localizationRepository localization.Repository) *ListSitemapUseCase {
|
||||
return &ListSitemapUseCase{articleRepository: articleRepository, sites: sites, localization: localizationRepository}
|
||||
}
|
||||
|
||||
type SitemapEntry struct {
|
||||
URL string
|
||||
ModifiedAt time.Time
|
||||
Noindex bool
|
||||
Lang string
|
||||
}
|
||||
|
||||
type SitemapPage struct {
|
||||
@@ -31,10 +35,21 @@ func (u *ListSitemapUseCase) List(siteKey string, page int, size int) (SitemapPa
|
||||
if err != nil {
|
||||
return SitemapPage{}, err
|
||||
}
|
||||
rows, err := u.localization.Rows(owner.ID)
|
||||
if err != nil {
|
||||
return SitemapPage{}, err
|
||||
}
|
||||
langs := []string{language.Unassigned}
|
||||
for _, row := range rows {
|
||||
if row.Enabled {
|
||||
langs = append(langs, row.Tag)
|
||||
}
|
||||
}
|
||||
online := true
|
||||
found, err := u.articleRepository.FindPage(article.Filters{
|
||||
IsOnline: &online,
|
||||
SiteID: &owner.ID,
|
||||
Langs: &langs,
|
||||
Page: page,
|
||||
Size: size,
|
||||
Sort: article.Sort{Field: article.SortByID, Direction: article.SortAsc},
|
||||
@@ -44,7 +59,12 @@ func (u *ListSitemapUseCase) List(siteKey string, page int, size int) (SitemapPa
|
||||
}
|
||||
entries := make([]SitemapEntry, 0, len(found.Items))
|
||||
for _, item := range found.Items {
|
||||
entries = append(entries, SitemapEntry{URL: articleURL(owner, item.Slug), ModifiedAt: item.UpdatedAt, Noindex: item.Noindex})
|
||||
entries = append(entries, SitemapEntry{URL: sitemapURL(owner, item), ModifiedAt: item.UpdatedAt, Noindex: item.Noindex, Lang: item.Lang})
|
||||
}
|
||||
return SitemapPage{Entries: entries, Total: found.Total}, nil
|
||||
}
|
||||
|
||||
func sitemapURL(owner site.Site, item article.Article) string {
|
||||
url, _ := owner.ArticleURL(item.Lang, item.Slug)
|
||||
return url
|
||||
}
|
||||
Reference in new issue
Block a user