Fixing links for blog entries.

This commit is contained in:
2023-08-29 14:49:48 -07:00
parent 5e0a725deb
commit 6f29ac4b03
2 changed files with 32 additions and 14 deletions

View File

@@ -12,14 +12,18 @@ import (
"github.com/anaskhan96/soup"
)
func nomadLink(src Source) string {
u, err := url.Parse(src.ID())
if err != nil {
log.Errf("nomadLink: %s", err)
return fmt.Sprintf("[%s](%s)", src.ID(), src.ID())
func nomadLink(item Item) string {
if item.Title != "" {
return fmt.Sprintf("[%s](%s)", item.Title, item.URL.ID())
}
return fmt.Sprintf("[%s](%s)", u.Host, src.ID())
u, err := url.Parse(item.URL.ID())
if err != nil {
log.Errf("nomadLink: %s", err)
return fmt.Sprintf("[%s](%s)", item.URL.ID(), item.URL.ID())
}
return fmt.Sprintf("[%s](%s)", u.Host, item.URL.ID())
}
type sel struct {
@@ -66,16 +70,18 @@ func find(root soup.Root, attr string, selectors ...sel) (string, bool) {
}
type Post struct {
Title string
Image Source
Body string
URL Source
}
func NewPost(item Item) Post {
return Post{
Body: nomadLink(item.URL),
post := Post{
Body: nomadLink(item),
URL: item.URL,
}
return post
}
func (p *Post) Fetch() error {