diff --git a/assets/templates/article.html b/assets/templates/article.html index 5b399df..0e9d0dc 100644 --- a/assets/templates/article.html +++ b/assets/templates/article.html @@ -5,7 +5,10 @@
{{ .Title }}
-
{{ .Author }} - {{ .PublishDate }}
+
+ {{ .ShortSource }} + {{ .PublishDate }} +

{{ .Summary }}

Link
diff --git a/internal/model/article.go b/internal/model/article.go index 33d5aca..b26fc8e 100644 --- a/internal/model/article.go +++ b/internal/model/article.go @@ -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, } }