Skip to content

A self-hosted dashboard that puts all your feeds in one place

Allow specifying a custom lobsters URL or instance

Svilen Markovb327e59ab11d
diff --git a/docs/configuration.md b/docs/configuration.md
index 1e07bf2..7946606 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -573,11 +573,23 @@ Preview:
#### Properties
| Name | Type | Required | Default |
| ---- | ---- | -------- | ------- |
+| instance-url | string | no | https://lobste.rs/ |
+| custom-url | string | no | |
| limit | integer | no | 15 |
| collapse-after | integer | no | 5 |
| sort-by | string | no | hot |
| tags | array | no | |
+##### `instance-url`
+The base URL for a lobsters instance hosted somewhere other than on lobste.rs. Example:
+
+```yaml
+instance-url: https://www.journalduhacker.net/
+```
+
+##### `custom-url`
+A custom URL to retrieve lobsters posts from. If this is specified, the `instance-url`, `sort-by` and `tags` properties are ignored.
+
##### `limit`
The maximum number of posts to show.
diff --git a/internal/feed/lobsters.go b/internal/feed/lobsters.go
index e103f56..1bb5420 100644
--- a/internal/feed/lobsters.go
+++ b/internal/feed/lobsters.go
@@ -55,20 +55,30 @@ func getLobstersPostsFromFeed(feedUrl string) (ForumPosts, error) {
return posts, nil
}
-func FetchLobstersPosts(sortBy string, tags []string) (ForumPosts, error) {
+func FetchLobstersPosts(customURL string, instanceURL string, sortBy string, tags []string) (ForumPosts, error) {
var feedUrl string
- if sortBy == "hot" {
- sortBy = "hottest"
- } else if sortBy == "new" {
- sortBy = "newest"
- }
-
- if len(tags) == 0 {
- feedUrl = "https://lobste.rs/" + sortBy + ".json"
+ if customURL != "" {
+ feedUrl = customURL
} else {
- tags := strings.Join(tags, ",")
- feedUrl = "https://lobste.rs/t/" + tags + ".json"
+ if instanceURL != "" {
+ instanceURL = strings.TrimRight(instanceURL, "/") + "/"
+ } else {
+ instanceURL = "https://lobste.rs/"
+ }
+
+ if sortBy == "hot" {
+ sortBy = "hottest"
+ } else if sortBy == "new" {
+ sortBy = "newest"
+ }
+
+ if len(tags) == 0 {
+ feedUrl = instanceURL + sortBy + ".json"
+ } else {
+ tags := strings.Join(tags, ",")
+ feedUrl = instanceURL + "t/" + tags + ".json"
+ }
}
posts, err := getLobstersPostsFromFeed(feedUrl)
diff --git a/internal/widget/lobsters.go b/internal/widget/lobsters.go
index d402db4..61f8261 100644
--- a/internal/widget/lobsters.go
+++ b/internal/widget/lobsters.go
@@ -12,6 +12,8 @@ import (
type Lobsters struct {
widgetBase `yaml:",inline"`
Posts feed.ForumPosts `yaml:"-"`
+ InstanceURL string `yaml:"instance-url"`
+ CustomURL string `yaml:"custom-url"`
Limit int `yaml:"limit"`
CollapseAfter int `yaml:"collapse-after"`
SortBy string `yaml:"sort-by"`
@@ -38,7 +40,7 @@ func (widget *Lobsters) Initialize() error {
}
func (widget *Lobsters) Update(ctx context.Context) {
- posts, err := feed.FetchLobstersPosts(widget.SortBy, widget.Tags)
+ posts, err := feed.FetchLobstersPosts(widget.CustomURL, widget.InstanceURL, widget.SortBy, widget.Tags)
if !widget.canContinueUpdateAfterHandlingErr(err) {
return