startpage/bookmark.go

124 lines
3.1 KiB
Go
Raw Normal View History

2022-05-08 14:32:13 +02:00
package main
2022-05-12 21:15:55 +02:00
import (
"sort"
"strings"
)
2022-05-08 14:32:13 +02:00
2022-09-05 14:17:07 +02:00
func DefaultBookmarks() []Bookmark {
2022-09-05 14:55:21 +02:00
bookmarks := []Bookmark{
2022-05-08 14:32:13 +02:00
{
Title: "DuckDuckGo",
Image: "https://duckduckgo.com/assets/logo_homepage.alt.v108.svg",
Link: "https://duckduckgo.com/",
Color: "#e37151",
2022-05-08 14:32:13 +02:00
},
2022-05-08 21:43:47 +02:00
{
2022-09-05 14:17:07 +02:00
Title: "Google Dark",
Image: "https://www.google.com/images/branding/googlelogo/2x/googlelogo_light_color_272x92dp.png",
Link: "https://google.com/",
Color: "#202124",
2022-05-08 21:43:47 +02:00
},
2022-05-13 14:01:39 +02:00
{
2022-09-05 14:17:07 +02:00
Title: "Google Light",
Image: "https://www.google.de/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
Link: "https://google.com/",
Color: "#ffffff",
},
{
2022-09-05 14:17:07 +02:00
Title: "Wikipedia",
Image: "https://upload.wikimedia.org/wikipedia/commons/8/80/Wikipedia-logo-v2.svg",
Color: "#ffffff",
2022-09-05 14:17:07 +02:00
Link: "https://www.wikipedia.org/",
2022-05-08 14:32:13 +02:00
},
2022-05-08 16:17:57 +02:00
{
2022-09-05 14:17:07 +02:00
Title: "Reddit",
Image: "https://www.redditinc.com/assets/images/site/reddit-logo.png",
Link: "https://www.reddit.com/",
Color: "#ff4300",
2022-05-08 16:17:57 +02:00
ImageSize: "cover",
IconPadding: "0em",
},
2022-05-08 14:32:13 +02:00
{
2022-05-08 16:24:00 +02:00
Title: "YouTube",
Image: "https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/YouTube_light_icon_%282017%29.svg/1280px-YouTube_light_icon_%282017%29.svg.png",
Link: "https://www.youtube.com/",
2022-09-05 14:17:07 +02:00
Color: "#ff0000",
2022-05-08 16:24:00 +02:00
IconPadding: "1.5em",
2022-05-08 14:32:13 +02:00
},
2022-05-08 21:43:47 +02:00
{
Title: "Netflix",
Image: "https://1000logos.net/wp-content/uploads/2017/05/emblem-Netflix.jpg",
Link: "https://www.netflix.com/",
2022-09-05 14:17:07 +02:00
Color: "#000000",
2022-05-08 14:32:13 +02:00
},
{
Title: "Übersetzer",
Image: "https://tools.avans.nl/tools/image/wZkdyaMblN.jpg",
Link: "https://www.deepl.com/translator",
Color: "#042b48",
ImageSize: "cover",
IconPadding: "0em",
2022-05-08 14:32:13 +02:00
},
{
2022-09-05 14:17:07 +02:00
Title: "Cloud",
Image: "https://cloud.tordarus.net/svg/core/logo/logo?color=ffffff\u0026v=1",
Link: "https://cloud.tordarus.net/",
Color: "#007ec2",
2022-05-08 14:32:13 +02:00
},
{
Title: "Passwörter",
Image: "https://raw.githubusercontent.com/dani-garcia/vaultwarden/main/resources/vaultwarden-logo-white.svg",
Link: "https://pw.tordarus.net",
Color: "#175ddc",
},
}
2022-09-05 14:55:21 +02:00
Reorder(bookmarks)
return bookmarks
2022-09-05 14:17:07 +02:00
}
2022-05-08 14:32:13 +02:00
type Bookmark struct {
2022-09-06 11:22:28 +02:00
SessionID string `json:"-"`
Title string `json:"title"`
2022-09-05 14:17:07 +02:00
Image string `json:"image"`
ImageSize string `json:"image_size"`
IconPadding string `json:"icon_padding"`
Color string `json:"color"`
Link string `json:"link"`
HideBorder bool `json:"hide_border"`
Order int `json:"order"`
2022-05-08 14:32:13 +02:00
}
2022-09-05 14:17:07 +02:00
func (b *Bookmark) GetColor() string {
if b.Color == "" {
b.Color = "transparent"
2022-05-08 14:32:13 +02:00
}
2022-09-05 14:17:07 +02:00
return b.Color
}
2022-05-08 14:32:13 +02:00
2022-09-05 14:17:07 +02:00
func (b *Bookmark) GetImageSize() string {
if b.ImageSize == "" {
b.ImageSize = "contain"
}
return b.ImageSize
2022-05-08 14:32:13 +02:00
}
2022-05-12 21:15:55 +02:00
func (b *Bookmark) SmallLink() string {
lnk := b.Link
lnk = strings.TrimPrefix(lnk, "https://")
lnk = strings.TrimPrefix(lnk, "http://")
lnk = strings.TrimSuffix(lnk, "/")
return lnk
}
2022-09-05 14:17:07 +02:00
func Reorder(bookmarks []Bookmark) {
sort.SliceStable(bookmarks, func(i, j int) bool {
return bookmarks[i].Order < bookmarks[j].Order
})
for index := range bookmarks {
2022-09-05 19:41:22 +02:00
bookmarks[index].Order = (index + 1) * 10
2022-09-05 14:17:07 +02:00
}
}