update
This commit is contained in:
@ -40,7 +40,7 @@ func (s *articleService) List(ctx context.Context, q dto.ArticleQuery) ([]dto.Pu
|
||||
for _, r := range rows {
|
||||
ids = append(ids, r.ID)
|
||||
list = append(list, dto.PublicArticle{
|
||||
UID: hashid.Encode(r.ID),
|
||||
UID: hashid.EncodeTyped(hashid.TypeRunway, r.ID),
|
||||
BrandUID: hashid.Encode(r.BrandID),
|
||||
Title: pickLocale(r.TitleEn, r.TitleCn, q.Locale),
|
||||
Cover: r.Cover,
|
||||
@ -69,6 +69,8 @@ func (s *articleService) attachImages(ctx context.Context, list []dto.PublicArti
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
// 缩略图条带剔除主图(cover),避免与卡片主图重复。cover 恒等于图片列表首张。
|
||||
imgs = excludeCover(imgs, list[i].Cover)
|
||||
if len(imgs) > limit {
|
||||
imgs = imgs[:limit]
|
||||
}
|
||||
@ -77,6 +79,21 @@ func (s *articleService) attachImages(ctx context.Context, list []dto.PublicArti
|
||||
return nil
|
||||
}
|
||||
|
||||
// excludeCover 从图片列表中去掉与主图(cover)同 URL 的元素,供列表缩略图条带使用。
|
||||
// 详情接口(完整图集)不走此函数,封面作为其中一张 look 需保留。
|
||||
func excludeCover(imgs []model.BrandRunwayImage, cover string) []model.BrandRunwayImage {
|
||||
if cover == "" {
|
||||
return imgs
|
||||
}
|
||||
kept := imgs[:0]
|
||||
for _, im := range imgs {
|
||||
if im.Image != cover {
|
||||
kept = append(kept, im)
|
||||
}
|
||||
}
|
||||
return kept
|
||||
}
|
||||
|
||||
// Detail 查询文章详情,含完整图片集。locale 决定标题/描述/品牌名的展示语言。
|
||||
func (s *articleService) Detail(ctx context.Context, id string, locale string) (*dto.PublicArticleDetail, error) {
|
||||
row, err := s.articles.FindByID(ctx, id)
|
||||
@ -93,7 +110,7 @@ func (s *articleService) Detail(ctx context.Context, id string, locale string) (
|
||||
}
|
||||
|
||||
return &dto.PublicArticleDetail{
|
||||
UID: hashid.Encode(row.ID),
|
||||
UID: hashid.EncodeTyped(hashid.TypeRunway, row.ID),
|
||||
BrandUID: hashid.Encode(row.BrandID),
|
||||
Title: pickLocale(row.TitleEn, row.TitleCn, locale),
|
||||
Description: pickLocale(row.DescriptionEn, row.DescriptionCn, locale),
|
||||
|
||||
Reference in New Issue
Block a user