Date: Mon, 16 Jun 2025 20:32:46 +0100
Subject: [PATCH 4/9] homepage rework for socials and projects
---
controller/qr.go | 67 --------------
public/img/brand/bandcamp.svg | 10 +++
public/img/brand/bluesky.svg | 10 +++
public/img/brand/codeberg.svg | 164 ++++++++++++++++++++++++++++++++++
public/img/brand/discord.svg | 1 +
public/img/brand/twitch.svg | 21 +++++
public/img/brand/youtube.svg | 10 +++
public/script/index.js | 7 ++
public/script/main.js | 17 ++++
public/script/music.js | 12 +--
public/style/index.css | 88 ++++++++++++++++--
views/index.html | 162 ++++++++++++++++++++++-----------
12 files changed, 432 insertions(+), 137 deletions(-)
create mode 100644 public/img/brand/bandcamp.svg
create mode 100644 public/img/brand/bluesky.svg
create mode 100644 public/img/brand/codeberg.svg
create mode 100644 public/img/brand/discord.svg
create mode 100644 public/img/brand/twitch.svg
create mode 100644 public/img/brand/youtube.svg
diff --git a/controller/qr.go b/controller/qr.go
index 6b04e69..dd08637 100644
--- a/controller/qr.go
+++ b/controller/qr.go
@@ -1,13 +1,9 @@
package controller
import (
- "bytes"
"encoding/base64"
- "errors"
- "fmt"
"image"
"image/color"
- "image/png"
"github.com/skip2/go-qrcode"
)
@@ -33,69 +29,6 @@ const (
HIGH
)
-func noDepsGenerateQRCode() (string, error) {
- version := 1
-
- size := 0
- size = 21 + version * 4
- if version > 10 {
- return "", errors.New(fmt.Sprintf("QR version %d not supported", version))
- }
-
- img := image.NewGray(image.Rect(0, 0, size + margin * 2, size + margin * 2))
-
- // fill white
- for y := range size + margin * 2 {
- for x := range size + margin * 2 {
- img.Set(x, y, color.White)
- }
- }
-
- // draw alignment squares
- drawLargeAlignmentSquare(margin, margin, img)
- drawLargeAlignmentSquare(margin, margin + size - 7, img)
- drawLargeAlignmentSquare(margin + size - 7, margin, img)
- drawSmallAlignmentSquare(size - 5, size - 5, img)
- /*
- if version > 4 {
- space := version * 3 - 2
- end := size / space
- for y := range size / space + 1 {
- for x := range size / space + 1 {
- if x == 0 && y == 0 { continue }
- if x == 0 && y == end { continue }
- if x == end && y == 0 { continue }
- if x == end && y == end { continue }
- drawSmallAlignmentSquare(
- x * space + margin + 4,
- y * space + margin + 4,
- img,
- )
- }
- }
- }
- */
-
- // draw timing bits
- for i := margin + 6; i < size - 4; i++ {
- if (i % 2 == 0) {
- img.Set(i, margin + 6, color.Black)
- img.Set(margin + 6, i, color.Black)
- }
- }
- img.Set(margin + 8, size - 4, color.Black)
-
- var imgBuf bytes.Buffer
- err := png.Encode(&imgBuf, img)
- if err != nil {
- return "", err
- }
-
- base64Img := base64.StdEncoding.EncodeToString(imgBuf.Bytes())
-
- return "data:image/png;base64," + base64Img, nil
-}
-
func drawLargeAlignmentSquare(x int, y int, img *image.Gray) {
for yi := range 7 {
for xi := range 7 {
diff --git a/public/img/brand/bandcamp.svg b/public/img/brand/bandcamp.svg
new file mode 100644
index 0000000..9623ec2
--- /dev/null
+++ b/public/img/brand/bandcamp.svg
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/public/img/brand/bluesky.svg b/public/img/brand/bluesky.svg
new file mode 100644
index 0000000..d77fafe
--- /dev/null
+++ b/public/img/brand/bluesky.svg
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/public/img/brand/codeberg.svg b/public/img/brand/codeberg.svg
new file mode 100644
index 0000000..028b729
--- /dev/null
+++ b/public/img/brand/codeberg.svg
@@ -0,0 +1,164 @@
+
+
+ Codeberg logo
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ image/svg+xml
+
+ Codeberg logo
+
+
+
+ Robert Martinez
+
+
+
+
+ Codeberg and the Codeberg Logo are trademarks of Codeberg e.V.
+
+
+ 2020-04-09
+
+
+ Codeberg e.V.
+
+
+ codeberg.org
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/public/img/brand/discord.svg b/public/img/brand/discord.svg
new file mode 100644
index 0000000..b636d15
--- /dev/null
+++ b/public/img/brand/discord.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/public/img/brand/twitch.svg b/public/img/brand/twitch.svg
new file mode 100644
index 0000000..3120fea
--- /dev/null
+++ b/public/img/brand/twitch.svg
@@ -0,0 +1,21 @@
+
+
+
+
+Asset 2
+
+
+
+
+
+
+
+
+
+
+
diff --git a/public/img/brand/youtube.svg b/public/img/brand/youtube.svg
new file mode 100644
index 0000000..3286071
--- /dev/null
+++ b/public/img/brand/youtube.svg
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/public/script/index.js b/public/script/index.js
index 512ed8f..2197bd4 100644
--- a/public/script/index.js
+++ b/public/script/index.js
@@ -1,3 +1,5 @@
+import { hijackClickEvent } from "./main.js";
+
const hexPrimary = document.getElementById("hex-primary");
const hexSecondary = document.getElementById("hex-secondary");
const hexTertiary = document.getElementById("hex-tertiary");
@@ -14,3 +16,8 @@ updateHexColours();
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => {
updateHexColours();
});
+
+document.querySelectorAll("ul#projects li.project-item").forEach(projectItem => {
+ const link = projectItem.querySelector('a');
+ hijackClickEvent(projectItem, link);
+});
diff --git a/public/script/main.js b/public/script/main.js
index c1d5101..19eddc2 100644
--- a/public/script/main.js
+++ b/public/script/main.js
@@ -45,6 +45,23 @@ function fill_list(list) {
});
}
+export function hijackClickEvent(container, link) {
+ container.addEventListener('click', event => {
+ if (event.target.tagName.toLowerCase() === 'a') return;
+ event.preventDefault();
+ link.dispatchEvent(new MouseEvent('click', {
+ bubbles: true,
+ cancelable: true,
+ view: window,
+ ctrlKey: event.ctrlKey,
+ metaKey: event.metaKey,
+ shiftKey: event.shiftKey,
+ altKey: event.altKey,
+ button: event.button,
+ }));
+ });
+}
+
document.addEventListener("DOMContentLoaded", () => {
[...document.querySelectorAll(".typeout")]
.filter((e) => e.innerText != "")
diff --git a/public/script/music.js b/public/script/music.js
index 273ce2b..91f34ab 100644
--- a/public/script/music.js
+++ b/public/script/music.js
@@ -1,12 +1,6 @@
-import "./main.js";
+import { hijackClickEvent } from "./main.js";
document.querySelectorAll("div.music").forEach(container => {
- const link = container.querySelector(".music-title a").href
-
- container.addEventListener("click", event => {
- if (event.target.href) return;
-
- event.preventDefault();
- location = link;
- });
+ const link = container.querySelector(".music-title a")
+ hijackClickEvent(container, link);
});
diff --git a/public/style/index.css b/public/style/index.css
index f3cb761..6edb362 100644
--- a/public/style/index.css
+++ b/public/style/index.css
@@ -96,30 +96,36 @@ hr {
overflow: visible;
}
-ul.links {
+ul.platform-links {
+ padding-left: 1em;
display: flex;
- gap: 1em .5em;
+ gap: .5em;
flex-wrap: wrap;
}
-ul.links li {
+ul.platform-links li {
list-style: none;
}
-ul.links li a {
+ul.platform-links li a {
padding: .4em .5em;
+ display: flex;
+ flex-direction: row;
+ justify-content: center;
+ align-items: center;
+ gap: .5em;
border: 1px solid var(--links);
color: var(--links);
border-radius: 2px;
background-color: transparent;
- transition-property: color, border-color, background-color;
+ transition-property: color, border-color, background-color, box-shadow;
transition-duration: .2s;
animation-delay: 0s;
animation: list-item-fadein .2s forwards;
opacity: 0;
}
-ul.links li a:hover {
+ul.platform-links li a:hover {
color: #eee;
border-color: #eee;
background-color: var(--links) !important;
@@ -127,6 +133,75 @@ ul.links li a:hover {
box-shadow: 0 0 1em var(--links);
}
+ul.platform-links li a img {
+ height: 1em;
+ width: 1em;
+}
+
+ul#projects {
+ padding: 0;
+ list-style: none;
+}
+
+li.project-item {
+ padding: .5em;
+ border: 1px solid var(--links);
+ margin: 1em 0;
+ display: flex;
+ flex-direction: row;
+ gap: .5em;
+ border-radius: 2px;
+ transition-property: color, border-color, background-color, box-shadow;
+ transition-duration: .2s;
+ cursor: pointer;
+}
+li.project-item a {
+ transition: color .2s linear;
+}
+
+li.project-item:hover {
+ color: #eee;
+ border-color: #eee;
+ background-color: var(--links) !important;
+ text-decoration: none;
+ box-shadow: 0 0 1em var(--links);
+}
+li.project-item:hover a {
+ color: #eee;
+}
+
+li.project-item .project-info {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+}
+
+li.project-item img.project-icon {
+ width: 2.5em;
+ height: 2.5em;
+ object-fit: cover;
+ border-radius: 2px;
+}
+
+li.project-item span.project-icon {
+ font-size: 2em;
+ display: block;
+ width: 45px;
+ height: 45px;
+ text-align: center;
+ /* background: #0004; */
+ /* border: 1px solid var(--on-background); */
+ border-radius: 2px;
+}
+
+li.project-item a {
+ text-decoration: none;
+}
+
+li.project-item p {
+ margin: 0;
+}
+
div#web-buttons {
margin: 2rem 0;
}
@@ -147,4 +222,3 @@ div#web-buttons {
transform: translate(-2px, -2px);
box-shadow: 1px 1px 0 #eee, 2px 2px 0 #eee;
}
-
diff --git a/views/index.html b/views/index.html
index 070d648..f639c55 100644
--- a/views/index.html
+++ b/views/index.html
@@ -17,7 +17,7 @@
-
+
{{end}}
{{define "content"}}
@@ -33,7 +33,7 @@
- i'm a musician , developer ,
+ i'm a musician , developer ,
streamer , youtuber ,
and probably a bunch of other things i forgot to mention!
@@ -44,7 +44,7 @@
if you're looking to support me financially, that's so cool of you!!
if you like, you can buy some of my music over on
- bandcamp
+ bandcamp
so you can at least get something for your money.
thank you very much either way!! 💕
@@ -84,65 +84,119 @@
where to find me 🛰️
+
+
projects i've worked on 🛠️
-
-
-
- mcstatusface
-
+
@@ -156,40 +210,40 @@
-
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -205,16 +259,16 @@
-
+
-
+
-
+
From f7b3faf8e89b240ca1e65eb698734039fcae9ce3 Mon Sep 17 00:00:00 2001
From: ari melody
Date: Mon, 16 Jun 2025 22:41:54 +0100
Subject: [PATCH 5/9] move source link from header to footer
---
public/style/header.css | 5 ++---
views/footer.html | 7 ++++++-
views/header.html | 3 ---
3 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/public/style/header.css b/public/style/header.css
index 531649a..f399d4d 100644
--- a/public/style/header.css
+++ b/public/style/header.css
@@ -25,7 +25,6 @@ nav {
flex-grow: 1;
display: flex;
gap: .5em;
- cursor: pointer;
}
img#header-icon {
@@ -36,19 +35,19 @@ img#header-icon {
}
#header-text {
- width: 11em;
display: flex;
flex-direction: column;
justify-content: center;
- flex-grow: 1;
}
#header-text h1 {
+ width: fit-content;
margin: 0;
font-size: 1em;
}
#header-text h2 {
+ width: fit-content;
height: 1.2em;
line-height: 1.2em;
margin: 0;
diff --git a/views/footer.html b/views/footer.html
index 217c4b5..eccf125 100644
--- a/views/footer.html
+++ b/views/footer.html
@@ -2,7 +2,12 @@
diff --git a/views/header.html b/views/header.html
index 291b8ac..03a8384 100644
--- a/views/header.html
+++ b/views/header.html
@@ -23,9 +23,6 @@
music
-
- source
-
blog
From 9274796729a56290d788106e0ed5327643103e4a Mon Sep 17 00:00:00 2001
From: ari melody
Date: Tue, 17 Jun 2025 01:15:08 +0100
Subject: [PATCH 6/9] early implementation of ari melody LIVE tracker
---
controller/config.go | 4 ++
controller/twitch.go | 97 ++++++++++++++++++++++++++++++++++++++++
main.go | 47 ++++---------------
model/appstate.go | 8 ++++
model/twitch.go | 43 ++++++++++++++++++
public/style/colours.css | 1 +
public/style/index.css | 81 +++++++++++++++++++++++++++++++++
view/index.go | 45 +++++++++++++++++++
view/static.go | 31 +++++++++++++
views/index.html | 17 +++++++
10 files changed, 335 insertions(+), 39 deletions(-)
create mode 100644 controller/twitch.go
create mode 100644 model/twitch.go
create mode 100644 view/index.go
create mode 100644 view/static.go
diff --git a/controller/config.go b/controller/config.go
index 1d3cbbb..fdfa756 100644
--- a/controller/config.go
+++ b/controller/config.go
@@ -77,5 +77,9 @@ func handleConfigOverrides(config *model.Config) error {
if env, has := os.LookupEnv("ARIMELODY_DISCORD_CLIENT_ID"); has { config.Discord.ClientID = env }
if env, has := os.LookupEnv("ARIMELODY_DISCORD_SECRET"); has { config.Discord.Secret = env }
+ if env, has := os.LookupEnv("ARIMELODY_TWITCH_BROADCASTER"); has { config.Twitch.Broadcaster = env }
+ if env, has := os.LookupEnv("ARIMELODY_TWITCH_CLIENT_ID"); has { config.Twitch.ClientID = env }
+ if env, has := os.LookupEnv("ARIMELODY_TWITCH_SECRET"); has { config.Twitch.Secret = env }
+
return nil
}
diff --git a/controller/twitch.go b/controller/twitch.go
new file mode 100644
index 0000000..f7dc509
--- /dev/null
+++ b/controller/twitch.go
@@ -0,0 +1,97 @@
+package controller
+
+import (
+ "arimelody-web/model"
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/url"
+ "time"
+)
+
+const TWITCH_API_BASE = "https://api.twitch.tv/helix/"
+
+func TwitchSetup(app *model.AppState) error {
+ app.Twitch = &model.TwitchState{}
+ err := RefreshTwitchToken(app)
+ return err
+}
+
+func RefreshTwitchToken(app *model.AppState) error {
+ if app.Twitch != nil && app.Twitch.Token != nil && time.Now().UTC().After(app.Twitch.Token.ExpiresAt) {
+ return nil
+ }
+
+ requestUrl, _ := url.Parse("https://id.twitch.tv/oauth2/token")
+ req, _ := http.NewRequest(http.MethodPost, requestUrl.String(), bytes.NewBuffer([]byte(url.Values{
+ "client_id": []string{ app.Config.Twitch.ClientID },
+ "client_secret": []string{ app.Config.Twitch.Secret },
+ "grant_type": []string{ "client_credentials" },
+ }.Encode())))
+
+ res, err := http.DefaultClient.Do(req)
+ if err != nil {
+ return err
+ }
+
+ type TwitchOAuthToken struct {
+ AccessToken string `json:"access_token"`
+ ExpiresIn int `json:"expires_in"`
+ TokenType string `json:"token_type"`
+ }
+ oauthResponse := TwitchOAuthToken{}
+ err = json.NewDecoder(res.Body).Decode(&oauthResponse)
+ if err != nil {
+ return err
+ }
+
+ app.Twitch.Token = &model.TwitchOAuthToken{
+ AccessToken: oauthResponse.AccessToken,
+ ExpiresAt: time.Now().UTC().Add(time.Second * time.Duration(oauthResponse.ExpiresIn)).UTC(),
+ TokenType: oauthResponse.TokenType,
+ }
+
+ return nil
+}
+
+var lastStreamState *model.TwitchStreamInfo
+var lastStreamStateAt time.Time
+
+func GetTwitchStatus(app *model.AppState, broadcaster string) (*model.TwitchStreamInfo, error) {
+ if lastStreamState != nil && time.Now().UTC().Before(lastStreamStateAt.Add(time.Minute)) {
+ return lastStreamState, nil
+ }
+
+ fmt.Print("MAKING COSTLY REQUEST TO TWITCH.TV API...\n")
+
+ requestUrl, _ := url.Parse(TWITCH_API_BASE + "streams")
+ requestUrl.RawQuery = url.Values{
+ "user_login": []string{ broadcaster },
+ }.Encode()
+ req, _ := http.NewRequest(http.MethodGet, requestUrl.String(), nil)
+ req.Header.Set("Client-Id", app.Config.Twitch.ClientID)
+ req.Header.Set("Authorization", "Bearer " + app.Twitch.Token.AccessToken)
+
+ res, err := http.DefaultClient.Do(req)
+ if err != nil {
+ return nil, err
+ }
+
+ type StreamsResponse struct {
+ Data []model.TwitchStreamInfo `json:"data"`
+ }
+ streamInfo := StreamsResponse{}
+ err = json.NewDecoder(res.Body).Decode(&streamInfo)
+ if err != nil {
+ return nil, err
+ }
+
+ if len(streamInfo.Data) == 0 {
+ return nil, nil
+ }
+
+ lastStreamState = &streamInfo.Data[0]
+ lastStreamStateAt = time.Now().UTC()
+ return lastStreamState, nil
+}
diff --git a/main.go b/main.go
index 29539ac..8f37639 100644
--- a/main.go
+++ b/main.go
@@ -22,7 +22,6 @@ import (
"arimelody-web/cursor"
"arimelody-web/log"
"arimelody-web/model"
- "arimelody-web/templates"
"arimelody-web/view"
"github.com/jmoiron/sqlx"
@@ -40,6 +39,7 @@ func main() {
app := model.AppState{
Config: controller.GetConfig(),
+ Twitch: nil,
}
// initialise database connection
@@ -460,6 +460,11 @@ func main() {
// handle DB migrations
controller.CheckDBVersionAndMigrate(app.DB)
+ err = controller.TwitchSetup(&app)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "WARN: Failed to set up Twitch integration: %v\n", err)
+ }
+
// initial invite code
accountsCount := 0
err = app.DB.Get(&accountsCount, "SELECT count(*) FROM account")
@@ -511,49 +516,13 @@ func createServeMux(app *model.AppState) *http.ServeMux {
mux.Handle("/admin/", http.StripPrefix("/admin", admin.Handler(app)))
mux.Handle("/api/", http.StripPrefix("/api", api.Handler(app)))
mux.Handle("/music/", http.StripPrefix("/music", view.MusicHandler(app)))
- mux.Handle("/uploads/", http.StripPrefix("/uploads", staticHandler(filepath.Join(app.Config.DataDirectory, "uploads"))))
+ mux.Handle("/uploads/", http.StripPrefix("/uploads", view.StaticHandler(filepath.Join(app.Config.DataDirectory, "uploads"))))
mux.Handle("/cursor-ws", cursor.Handler(app))
- mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- if r.Method == http.MethodHead {
- w.WriteHeader(http.StatusOK)
- return
- }
-
- if r.URL.Path == "/" || r.URL.Path == "/index.html" {
- err := templates.IndexTemplate.Execute(w, nil)
- if err != nil {
- http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
- }
- return
- }
- staticHandler("public").ServeHTTP(w, r)
- }))
+ mux.Handle("/", view.IndexHandler(app))
return mux
}
-func staticHandler(directory string) http.Handler {
- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- info, err := os.Stat(filepath.Join(directory, filepath.Clean(r.URL.Path)))
-
- // does the file exist?
- if err != nil {
- if errors.Is(err, os.ErrNotExist) {
- http.NotFound(w, r)
- return
- }
- }
-
- // is thjs a directory? (forbidden)
- if info.IsDir() {
- http.NotFound(w, r)
- return
- }
-
- http.FileServer(http.Dir(directory)).ServeHTTP(w, r)
- })
-}
-
var PoweredByStrings = []string{
"nerd rage",
"estrogen",
diff --git a/model/appstate.go b/model/appstate.go
index a910a29..861a991 100644
--- a/model/appstate.go
+++ b/model/appstate.go
@@ -21,6 +21,12 @@ type (
Secret string `toml:"secret"`
}
+ TwitchConfig struct {
+ Broadcaster string `toml:"broadcaster"`
+ ClientID string `toml:"client_id"`
+ Secret string `toml:"secret"`
+ }
+
Config struct {
BaseUrl string `toml:"base_url" comment:"Used for OAuth redirects."`
Host string `toml:"host"`
@@ -29,11 +35,13 @@ type (
TrustedProxies []string `toml:"trusted_proxies"`
DB DBConfig `toml:"db"`
Discord DiscordConfig `toml:"discord"`
+ Twitch TwitchConfig `toml:"twitch"`
}
AppState struct {
DB *sqlx.DB
Config Config
Log log.Logger
+ Twitch *TwitchState
}
)
diff --git a/model/twitch.go b/model/twitch.go
new file mode 100644
index 0000000..6bca17d
--- /dev/null
+++ b/model/twitch.go
@@ -0,0 +1,43 @@
+package model
+
+import (
+ "fmt"
+ "strings"
+ "time"
+)
+
+type (
+ TwitchOAuthToken struct {
+ AccessToken string
+ ExpiresAt time.Time
+ TokenType string
+ }
+
+ TwitchState struct {
+ Token *TwitchOAuthToken
+ }
+
+ TwitchStreamInfo struct {
+ ID string `json:"id"`
+ UserID string `json:"user_id"`
+ UserLogin string `json:"user_login"`
+ UserName string `json:"user_name"`
+ GameID string `json:"game_id"`
+ GameName string `json:"game_name"`
+ Type string `json:"type"`
+ Title string `json:"title"`
+ ViewerCount int `json:"viewer_count"`
+ StartedAt string `json:"started_at"`
+ Language string `json:"language"`
+ ThumbnailURL string `json:"thumbnail_url"`
+ TagIDs []string `json:"tag_ids"`
+ Tags []string `json:"tags"`
+ IsMature bool `json:"is_mature"`
+ }
+)
+
+func (info *TwitchStreamInfo) Thumbnail(width int, height int) string {
+ res := strings.Replace(info.ThumbnailURL, "{width}", fmt.Sprintf("%d", width), 1)
+ res = strings.Replace(res, "{height}", fmt.Sprintf("%d", height), 1)
+ return res
+}
diff --git a/public/style/colours.css b/public/style/colours.css
index 2bf607d..de63198 100644
--- a/public/style/colours.css
+++ b/public/style/colours.css
@@ -6,6 +6,7 @@
--secondary: #f8e05b;
--tertiary: #f788fe;
--links: #5eb2ff;
+ --live: #fd3737;
}
@media (prefers-color-scheme: light) {
diff --git a/public/style/index.css b/public/style/index.css
index 6edb362..f60fdb7 100644
--- a/public/style/index.css
+++ b/public/style/index.css
@@ -222,3 +222,84 @@ div#web-buttons {
transform: translate(-2px, -2px);
box-shadow: 1px 1px 0 #eee, 2px 2px 0 #eee;
}
+
+#live-banner {
+ margin: 1em 0 2em 0;
+ padding: 1em;
+ border-radius: 4px;
+ border: 1px solid var(--primary);
+ box-shadow: 0 0 8px var(--primary);
+}
+
+#live-banner h2 {
+ margin: 0 0 .4em 0;
+ color: var(--on-background);
+}
+
+#live-banner p {
+ margin: 0;
+}
+
+.live-highlight {
+ color: var(--primary);
+}
+
+.live-preview {
+ display: flex;
+ flex-direction: row;
+ justify-content: center;
+ gap: 1em;
+}
+
+.live-preview div:first-of-type {
+ text-align: center;
+}
+
+.live-thumbnail {
+ border-radius: 4px;
+}
+
+.live-button {
+ margin: .2em;
+ padding: .4em .5em;
+ display: inline-block;
+ color: var(--primary);
+ border: 1px solid var(--primary);
+ border-radius: 4px;
+ transition: color .1s linear, background-color .1s linear, box-shadow .1s linear;
+}
+
+.live-button:hover {
+ color: var(--background);
+ background-color: var(--primary);
+ box-shadow: 0 0 8px var(--primary);
+ text-decoration: none;
+}
+
+.live-info {
+ display: flex;
+ flex-direction: column;
+ gap: .3em;
+ overflow-x: hidden;
+}
+
+.live-game {
+ overflow: hidden;
+ text-wrap: nowrap;
+ text-overflow: ellipsis;
+}
+
+.live-game .live-game-prefix {
+ opacity: .8;
+}
+
+.live-title {
+ display: -webkit-box;
+ -webkit-line-clamp: 2;
+ -webkit-box-orient: vertical;
+ overflow: hidden;
+}
+
+.live-viewers {
+ opacity: .5;
+}
diff --git a/view/index.go b/view/index.go
new file mode 100644
index 0000000..995de44
--- /dev/null
+++ b/view/index.go
@@ -0,0 +1,45 @@
+package view
+
+import (
+ "arimelody-web/controller"
+ "arimelody-web/model"
+ "arimelody-web/templates"
+ "fmt"
+ "net/http"
+ "os"
+)
+
+func IndexHandler(app *model.AppState) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.Method == http.MethodHead {
+ w.WriteHeader(http.StatusOK)
+ return
+ }
+
+ type IndexData struct {
+ TwitchStatus *model.TwitchStreamInfo
+ }
+
+ var err error
+ var twitchStatus *model.TwitchStreamInfo = nil
+ if len(app.Config.Twitch.Broadcaster) > 0 {
+ twitchStatus, err = controller.GetTwitchStatus(app, app.Config.Twitch.Broadcaster)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "WARN: Failed to get Twitch status for %s: %v\n", app.Config.Twitch.Broadcaster, err)
+ }
+ }
+
+ if r.URL.Path == "/" || r.URL.Path == "/index.html" {
+ err := templates.IndexTemplate.Execute(w, IndexData{
+ TwitchStatus: twitchStatus,
+ })
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "WARN: Failed to render index page: %v\n", err)
+ http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
+ }
+ return
+ }
+
+ StaticHandler("public").ServeHTTP(w, r)
+ })
+}
diff --git a/view/static.go b/view/static.go
new file mode 100644
index 0000000..52263a2
--- /dev/null
+++ b/view/static.go
@@ -0,0 +1,31 @@
+package view
+
+import (
+ "errors"
+ "net/http"
+ "os"
+ "path/filepath"
+)
+
+func StaticHandler(directory string) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ info, err := os.Stat(filepath.Join(directory, filepath.Clean(r.URL.Path)))
+
+ // does the file exist?
+ if err != nil {
+ if errors.Is(err, os.ErrNotExist) {
+ http.NotFound(w, r)
+ return
+ }
+ }
+
+ // is thjs a directory? (forbidden)
+ if info.IsDir() {
+ http.NotFound(w, r)
+ return
+ }
+
+ http.FileServer(http.Dir(directory)).ServeHTTP(w, r)
+ })
+}
+
diff --git a/views/index.html b/views/index.html
index f639c55..98a862c 100644
--- a/views/index.html
+++ b/views/index.html
@@ -22,6 +22,23 @@
{{define "content"}}
+ {{if .TwitchStatus}}
+
+
ari is LIVE right now!
+
+
+
+
streaming: {{.TwitchStatus.GameName}}
+
{{.TwitchStatus.Title}}
+
{{.TwitchStatus.ViewerCount}} viewers
+
+
+
+ {{end}}
+
# hello, world!
From 581273370de2029c8258564ab2a180eea93f0a0d Mon Sep 17 00:00:00 2001
From: ari melody
Date: Tue, 17 Jun 2025 02:01:06 +0100
Subject: [PATCH 7/9] improvements to LIVE tracker
---
controller/twitch.go | 3 ---
main.go | 8 +++++---
model/appstate.go | 4 ++--
public/style/index.css | 41 +++++++++++++++++++++++++++++++++++------
public/style/main.css | 1 +
view/index.go | 2 +-
views/index.html | 2 +-
7 files changed, 45 insertions(+), 16 deletions(-)
diff --git a/controller/twitch.go b/controller/twitch.go
index f7dc509..98d3b9a 100644
--- a/controller/twitch.go
+++ b/controller/twitch.go
@@ -4,7 +4,6 @@ import (
"arimelody-web/model"
"bytes"
"encoding/json"
- "fmt"
"net/http"
"net/url"
"time"
@@ -63,8 +62,6 @@ func GetTwitchStatus(app *model.AppState, broadcaster string) (*model.TwitchStre
return lastStreamState, nil
}
- fmt.Print("MAKING COSTLY REQUEST TO TWITCH.TV API...\n")
-
requestUrl, _ := url.Parse(TWITCH_API_BASE + "streams")
requestUrl.RawQuery = url.Values{
"user_login": []string{ broadcaster },
diff --git a/main.go b/main.go
index 8f37639..0234d79 100644
--- a/main.go
+++ b/main.go
@@ -460,9 +460,11 @@ func main() {
// handle DB migrations
controller.CheckDBVersionAndMigrate(app.DB)
- err = controller.TwitchSetup(&app)
- if err != nil {
- fmt.Fprintf(os.Stderr, "WARN: Failed to set up Twitch integration: %v\n", err)
+ if app.Config.Twitch != nil {
+ err = controller.TwitchSetup(&app)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "WARN: Failed to set up Twitch integration: %v\n", err)
+ }
}
// initial invite code
diff --git a/model/appstate.go b/model/appstate.go
index 861a991..3a1c230 100644
--- a/model/appstate.go
+++ b/model/appstate.go
@@ -34,8 +34,8 @@ type (
DataDirectory string `toml:"data_dir"`
TrustedProxies []string `toml:"trusted_proxies"`
DB DBConfig `toml:"db"`
- Discord DiscordConfig `toml:"discord"`
- Twitch TwitchConfig `toml:"twitch"`
+ Discord *DiscordConfig `toml:"discord"`
+ Twitch *TwitchConfig `toml:"twitch"`
}
AppState struct {
diff --git a/public/style/index.css b/public/style/index.css
index f60fdb7..6efe241 100644
--- a/public/style/index.css
+++ b/public/style/index.css
@@ -231,11 +231,6 @@ div#web-buttons {
box-shadow: 0 0 8px var(--primary);
}
-#live-banner h2 {
- margin: 0 0 .4em 0;
- color: var(--on-background);
-}
-
#live-banner p {
margin: 0;
}
@@ -252,7 +247,11 @@ div#web-buttons {
}
.live-preview div:first-of-type {
- text-align: center;
+ display: flex;
+ flex-direction: column;
+ justify-content: space-between;
+ align-items: center;
+ gap: .3em;
}
.live-thumbnail {
@@ -283,6 +282,36 @@ div#web-buttons {
overflow-x: hidden;
}
+#live-banner h2 {
+ margin: 0;
+ color: var(--on-background);
+ font-family: 'Inter', sans-serif;
+ font-weight: 800;
+ font-style: italic;
+}
+
+.live-pinger {
+ width: .5em;
+ height: .5em;
+ margin: .1em .2em;
+ display: inline-block;
+ border-radius: 100%;
+ background-color: var(--primary);
+ box-shadow: 0 0 4px var(--primary);
+ animation: live-pinger-pulse 1s infinite alternate ease-in-out;
+}
+
+@keyframes live-pinger-pulse {
+ from {
+ opacity: .8;
+ transform: scale(1.0);
+ }
+ to {
+ opacity: 1;
+ transform: scale(1.1);
+ }
+}
+
.live-game {
overflow: hidden;
text-wrap: nowrap;
diff --git a/public/style/main.css b/public/style/main.css
index 4e9e113..680ee2b 100644
--- a/public/style/main.css
+++ b/public/style/main.css
@@ -3,6 +3,7 @@
@import url("/style/footer.css");
@import url("/style/prideflag.css");
@import url("/style/cursor.css");
+@import url("/font/inter/inter.css");
@font-face {
font-family: "Monaspace Argon";
diff --git a/view/index.go b/view/index.go
index 995de44..b6e3891 100644
--- a/view/index.go
+++ b/view/index.go
@@ -22,7 +22,7 @@ func IndexHandler(app *model.AppState) http.Handler {
var err error
var twitchStatus *model.TwitchStreamInfo = nil
- if len(app.Config.Twitch.Broadcaster) > 0 {
+ if app.Twitch != nil && len(app.Config.Twitch.Broadcaster) > 0 {
twitchStatus, err = controller.GetTwitchStatus(app, app.Config.Twitch.Broadcaster)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to get Twitch status for %s: %v\n", app.Config.Twitch.Broadcaster, err)
diff --git a/views/index.html b/views/index.html
index 98a862c..6985f6c 100644
--- a/views/index.html
+++ b/views/index.html
@@ -24,13 +24,13 @@
{{if .TwitchStatus}}
-
ari is LIVE right now!
+
ari melody LIVE
streaming: {{.TwitchStatus.GameName}}
{{.TwitchStatus.Title}}
{{.TwitchStatus.ViewerCount}} viewers
From 375ae84ae33d352421dffcfbe44bbbdff32a3b11 Mon Sep 17 00:00:00 2001
From: ari melody
Date: Sun, 22 Jun 2025 18:00:08 +0100
Subject: [PATCH 8/9] update some arimelody.me references to .space
---
views/index.html | 30 ++++--------------------------
1 file changed, 4 insertions(+), 26 deletions(-)
diff --git a/views/index.html b/views/index.html
index 6985f6c..37bd2a3 100644
--- a/views/index.html
+++ b/views/index.html
@@ -6,8 +6,8 @@
-
-
+
+
@@ -101,28 +101,6 @@
where to find me 🛰️
-
-
+
pride flag
progressive pride flag widget for websites
From 7a354cddf520e5673f347f911c2951401a53da35 Mon Sep 17 00:00:00 2001
From: ari melody
Date: Sun, 22 Jun 2025 18:05:21 +0100
Subject: [PATCH 9/9] update some more links!
---
views/index.html | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/views/index.html b/views/index.html
index 37bd2a3..0e09475 100644
--- a/views/index.html
+++ b/views/index.html
@@ -133,7 +133,7 @@
-
+
discord
@@ -202,7 +202,7 @@