Moved regio43 to base HTML template

This commit is contained in:
2025-05-23 18:30:08 +02:00
parent 847fb6491d
commit 54986f6edf
6 changed files with 38 additions and 46 deletions

View File

@@ -1,13 +1,9 @@
package regio43
import (
"embed"
"net/http"
)
//go:embed templates/*
var content embed.FS
func InitHttpHandlers() {
http.HandleFunc("/regio43/", trains)
}

View File

@@ -1,56 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>prettysunflower - Regio 43</title>
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
</head>
<body class="page-radio-trains">
<div class="video-zone">
<video id="video-player" controls></video>
</div>
<h1>Regio 43</h1>
<main>
{{ range .PlaylistItems }}
<div class="playlist-item" data-videoid="{{ .VideoId }}">
<img src="{{ .ThumbnailUrl }}">
<p>
<a href="https://invidious.prettysunflower.moe/watch?v={{ .VideoId }}">
<strong>{{ .Title }}</strong><br>
{{ .Channel.Name }}
</a>
</p>
</div>
{{ end }}
</main>
<script>
const playlistItems = document.getElementsByClassName("playlist-item");
const videoBlock = document.querySelector(".video-zone video");
function loadVideo(videoId) {
videoBlock.src = `https://invidious.prettysunflower.moe/latest_version?local=true&id=${videoId}`;
videoBlock.currentTime = 0;
videoBlock.play();
}
let index = 0;
playlistItems[index].classList.add('active');
loadVideo(playlistItems[index].dataset.videoid);
videoBlock.addEventListener('ended', () => {
playlistItems[index].classList.remove('active');
index = index + 1;
if (index < playlistItems.length) {
playlistItems[index].classList.add('active');
loadVideo(playlistItems[index].dataset.videoid);
}
})
</script>
</body>
</html>

View File

@@ -1,9 +1,9 @@
package regio43
import (
"html/template"
"math/rand"
"net/http"
"prettysunflower-website/baseTemplates"
)
type TrainsTemplateData struct {
@@ -16,19 +16,7 @@ func trains(w http.ResponseWriter, r *http.Request) {
trainsPlaylist[i], trainsPlaylist[j] = trainsPlaylist[j], trainsPlaylist[i]
})
templateFile := "templates/regio43.tmpl"
files, err := template.New(templateFile).ParseFS(content, templateFile)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = files.ExecuteTemplate(w, "regio43.tmpl", TrainsTemplateData{
baseTemplates.WithBase(w, TrainsTemplateData{
PlaylistItems: trainsPlaylist,
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}, "templates/regio43.tmpl")
}