add badges to article view

This commit is contained in:
2025-01-06 18:45:44 +01:00
parent d63ee8dcf2
commit f3125561eb
2 changed files with 20 additions and 2 deletions

View File

@@ -2,6 +2,8 @@ package model
import (
"time"
//"strings"
"net/url"
)
@@ -22,6 +24,7 @@ type ArticleViewModel struct {
Author string
PublishDate string
SourceUrl string
ShortSource string
Summary string
}
@@ -33,11 +36,23 @@ func (a *Article) ViewModel() *ArticleViewModel {
summary = summary[:300]
}
short_url := ""
parsedURL, err := url.Parse(a.SourceUrl)
if err == nil {
short_url = parsedURL.Hostname()
//hostParts := strings.Split(short_url, ".")
//if len(hostParts) >= 2 {
// short_url = strings.Join(hostParts[len(hostParts)-2:], ".")
//}
}
return &ArticleViewModel{
Title: a.Title,
Author: a.Author,
PublishDate: a.PublishDate.Local().Format("02.01.2006 15:04"),
PublishDate: a.PublishDate.Local().Format("02.01.2006"),
SourceUrl: a.SourceUrl,
ShortSource: short_url,
Summary: summary,
}
}