Skip to content

Commit 29754f4

Browse files
committed
Better title handling.
1 parent aa12b45 commit 29754f4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

phpbb2rss.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ func FetchAndGenerateRSS(forumURL string) (string, error) {
4646
return "", fmt.Errorf("failed to parse page content: %w", err)
4747
}
4848

49+
pageTitle := ""
50+
doc.Find("a.nav:contains('Forum Index')").Each(func(i int, s *goquery.Selection) {
51+
// Extract text from the link and trim "Forum Index" if present
52+
pageTitle = strings.TrimSpace(s.Text())
53+
if strings.HasSuffix(pageTitle, "Forum Index") {
54+
pageTitle = strings.TrimSuffix(pageTitle, " Forum Index")
55+
}
56+
})
57+
58+
if pageTitle == "" {
59+
pageTitle = doc.Find("title").Text()
60+
}
61+
62+
if pageTitle == "" {
63+
pageTitle = "PHPBB2 Forum Topics" // Fallback title if none found
64+
}
65+
4966
var items []Item
5067
doc.Find(".forumline tr").Each(func(i int, s *goquery.Selection) {
5168
topic := s.Find(".topictitle a").First()
@@ -90,7 +107,7 @@ func FetchAndGenerateRSS(forumURL string) (string, error) {
90107
rss := RSS{
91108
Version: "2.0",
92109
Channel: Channel{
93-
Title: "PHPBB2 Forum Topics",
110+
Title: pageTitle, // Dynamically set page title
94111
Link: forumURL,
95112
Description: "RSS feed for topics from a PHPBB2 forum page",
96113
Items: items,

0 commit comments

Comments
 (0)