remove author column from articles

This commit is contained in:
2025-01-07 11:59:10 +01:00
parent b16ebb9572
commit ce10e1e62b
4 changed files with 74 additions and 57 deletions

View File

@@ -1,58 +1,47 @@
package model
import (
"time"
//"strings"
"net/url"
"net/url"
"time"
)
// TODO docstring
type Article struct {
Identifier int
SourceUrl string
PublishDate time.Time
FetchDate time.Time
Title string
Content string
Author string
Identifier int
SourceUrl string
PublishDate time.Time
FetchDate time.Time
Title string
Content string
}
// TODO docstring
type ArticleViewModel struct {
Title string
Author string
PublishDate string
SourceUrl string
ShortSource string
Summary string
Title string
PublishDate string
SourceUrl string
ShortSource string
Summary string
}
// TODO docstring
func (a *Article) ViewModel() *ArticleViewModel {
summary := a.Content
if len(a.Content) > 300 {
summary = summary[:300]
}
summary := a.Content
if len(a.Content) > 300 {
summary = summary[:300]
}
short_url := ""
short_url := ""
parsedURL, err := url.Parse(a.SourceUrl)
if err == nil {
short_url = parsedURL.Hostname()
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"),
SourceUrl: a.SourceUrl,
ShortSource: short_url,
Summary: summary,
}
return &ArticleViewModel{
Title: a.Title,
PublishDate: a.PublishDate.Local().Format("02.01.2006"),
SourceUrl: a.SourceUrl,
ShortSource: short_url,
Summary: summary,
}
}