2021-12-26 10:03:25 +00:00
|
|
|
package website
|
|
|
|
|
|
|
|
import (
|
2024-05-25 02:09:28 +00:00
|
|
|
"encoding/json"
|
2021-12-26 10:03:25 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.handmade.network/hmn/hmn/src/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ParsedLink struct {
|
2024-05-25 02:09:28 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
Url string `json:"url"`
|
2021-12-26 10:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ParseLinks(text string) []ParsedLink {
|
2024-05-25 02:09:28 +00:00
|
|
|
var links []ParsedLink
|
|
|
|
err := json.Unmarshal([]byte(text), &links)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
2021-12-26 10:03:25 +00:00
|
|
|
}
|
2024-05-25 02:09:28 +00:00
|
|
|
return links
|
2021-12-26 10:03:25 +00:00
|
|
|
}
|
|
|
|
|
2024-05-25 02:09:28 +00:00
|
|
|
// TODO: Clean up use in user profiles I guess
|
2022-04-16 17:49:29 +00:00
|
|
|
func LinksToText(links []*models.Link) string {
|
2021-12-26 10:03:25 +00:00
|
|
|
linksText := ""
|
2022-04-16 17:49:29 +00:00
|
|
|
for _, link := range links {
|
2021-12-26 10:03:25 +00:00
|
|
|
linksText += fmt.Sprintf("%s %s\n", link.URL, link.Name)
|
|
|
|
}
|
|
|
|
return linksText
|
|
|
|
}
|