kontor-echo: setup project to show homepage
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 6s
Gitea Actions Demo / build-and-test (push) Failing after 11s

This commit is contained in:
Thomas Peetz
2026-11-09 17:02:59 +01:00
parent 074abd3c85
commit debdf3d0b0
63 changed files with 2411 additions and 485 deletions
+69
View File
@@ -0,0 +1,69 @@
package helpers
import (
"encoding/json"
"fmt"
"io/ioutil"
"log/slog"
"net/http"
"net/url"
)
func StripUrl(webLink string, keepParam string) string {
u, err := url.Parse(webLink)
if err != nil {
slog.Info("StripUrl", "error", err)
return webLink
}
values := u.Query()
for key := range values {
if key != keepParam {
values.Del(key)
}
}
u.RawQuery = values.Encode()
return u.String()
}
func GetParam(webLink string, param string) string {
u, err := url.Parse(webLink)
if err != nil {
slog.Info("StripUrl", "error", err)
return webLink
}
values := u.Query()
for key := range values {
if key == param {
return values.Get(key)
}
}
return ""
}
type OEmbedResponse struct {
Title string `json:"title"`
}
func GetVideoTitle(videoUrl string) (string, error) {
videoID := GetParam(videoUrl, "v")
// Construct the oEmbed URL
url := fmt.Sprintf("https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=%s&format=json", videoID)
resp, err := http.Get(url)
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
var data OEmbedResponse
if err := json.Unmarshal(body, &data); err != nil {
return "", err
}
return data.Title, nil
}