Skip to content

Commit 6bbdd4c

Browse files
committed
URL change
1 parent 29754f4 commit 6bbdd4c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

phpbb2rss.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"github.com/PuerkitoBio/goquery"
77
"net/http"
8+
"net/url"
89
"strings"
910
"time"
1011
)
@@ -63,6 +64,11 @@ func FetchAndGenerateRSS(forumURL string) (string, error) {
6364
pageTitle = "PHPBB2 Forum Topics" // Fallback title if none found
6465
}
6566

67+
baseURL, err := url.Parse(forumURL)
68+
if err != nil {
69+
return "", fmt.Errorf("failed to parse base URL: %w", err)
70+
}
71+
6672
var items []Item
6773
doc.Find(".forumline tr").Each(func(i int, s *goquery.Selection) {
6874
topic := s.Find(".topictitle a").First()
@@ -73,9 +79,21 @@ func FetchAndGenerateRSS(forumURL string) (string, error) {
7379
return
7480
}
7581

76-
link := fmt.Sprintf("%s/%s", forumURL, topicLink)
82+
// Use url.Parse to ensure proper handling of relative URLs
83+
topicURL, err := baseURL.Parse(topicLink)
84+
if err != nil {
85+
return
86+
}
87+
88+
link := topicURL.String() // Full URL for the topic
89+
90+
// If the latest post exists, use that link instead
7791
if latestPostExists {
78-
link = fmt.Sprintf("%s/%s", forumURL, latestPostLink)
92+
latestPostURL, err := baseURL.Parse(latestPostLink)
93+
if err != nil {
94+
return
95+
}
96+
link = latestPostURL.String() // Full URL for the latest post
7997
}
8098

8199
pubDateRaw := strings.TrimSpace(s.Find(".postdetails").Last().Text())

0 commit comments

Comments
 (0)