implement tempaltes

This commit is contained in:
2025-08-23 17:40:58 +02:00
parent 9bda8a066b
commit 70960057c1
16 changed files with 261 additions and 30 deletions

BIN
Advertisement_Panel Executable file

Binary file not shown.

View File

@@ -1,9 +1,17 @@
# Advertisement_Panel
## How To Run This Project
```bash
go run main.go
```
### Make the screen not turn off by
```bash
xset -dpms
xset s off
xset s noblank
```
## How To Add To This Project
This project is written with go, and has hot realoding (rebuilding when sensing changes) for the main.go
@@ -23,7 +31,9 @@ $(go env GOPATH)/bin/air -c .air.toml
- [ ] ATB integration
- [ ] ASCII ART support
- [ ] show more spicy images after kl 22:00
- [ ] more images???
- [ ] Hide mouse cursor
- [ ] more images and memes???
# NB!!!!
Changes in the static directory will not rebuild the project, simple workaround is to just make a small change in main.go and save, for example adding a space

58
file_handlers.go Normal file
View File

@@ -0,0 +1,58 @@
package main
import (
"encoding/json"
"net/http"
"os"
"path/filepath"
"strings"
)
const staticDir = "static"
// move FileData and AsciiEntry here if you want, or leave in main.go
func file_handler(w http.ResponseWriter, r *http.Request) {
data := FileData{
ImageNames: []string{},
SpicyImageNames: []string{},
AsciiFiles: []AsciiEntry{},
}
dirs, err := os.ReadDir(staticDir)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
for _, dir := range dirs {
dirName := dir.Name()
if strings.EqualFold(dirName, "images") {
files, _ := os.ReadDir(filepath.Join(staticDir, dirName))
for _, file := range files {
fileName := file.Name()
data.ImageNames = append(data.ImageNames, filepath.Join(staticDir, dirName, fileName))
}
} else if strings.EqualFold(dirName, "spicy") {
files, _ := os.ReadDir(filepath.Join(staticDir, dirName))
for _, file := range files {
fileName := file.Name()
data.SpicyImageNames = append(data.SpicyImageNames, filepath.Join(staticDir, dirName, fileName))
}
} else if strings.EqualFold(dirName, "ascii_art") {
files, _ := os.ReadDir(filepath.Join(staticDir, dirName))
for _, file := range files {
fileName := file.Name()
data.AsciiFiles = append(data.AsciiFiles,
AsciiEntry{Name: filepath.Join(staticDir, dirName, fileName), FontSize: 12},
)
}
}
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
}

52
main.go
View File

@@ -1,48 +1,48 @@
package main
import (
"encoding/json"
"fmt"
"html/template"
"net/http"
"os"
"strings"
)
type FileData struct {
ImageNames []string
SpicyImageNames []string
AsciiFiles []AsciiEntry
}
type AsciiEntry struct {
Name string
FontSize int
}
var templ *template.Template
func main() {
fmt.Print("Now running server!")
templ, _ = template.ParseGlob("templates/*.html")
fmt.Print("Now running server!\n")
// Serves index
http.HandleFunc("/", index_handler)
// Serves json for html to find file names
http.HandleFunc("/files", files_handler)
http.HandleFunc("/files", file_handler)
// Serves ascii page
http.HandleFunc("/ascii", ascii_handler)
// Serves images
http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir("./static"))))
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
// Serves what ever the user is requesting based on above urls
// Serves what ever the user is requesting base on above urls
http.ListenAndServe(":8080", nil)
}
func index_handler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./static/index.html")
templ.ExecuteTemplate(w, "images.html", nil)
}
func files_handler(w http.ResponseWriter, r *http.Request) {
files, err := os.ReadDir("./static")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var names []string
for _, f := range files {
name := f.Name()
if strings.HasSuffix(name, ".jpg") ||
strings.HasSuffix(name, ".png") ||
strings.HasSuffix(name, ".gif") {
names = append(names, "/images/"+name)
}
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(names)
func ascii_handler(w http.ResponseWriter, r *http.Request) {
templ.ExecuteTemplate(w, "ascii.html", nil)
}

View File

@@ -0,0 +1,29 @@
Y8baadP""""""""Yba,_
aaadP"' `""Yb,
`Y8( `"Yb,
`Y, `Yba,
Y, (O) `Yba,
`Y, ""Yba,________,,aaddddbbbaa,,____,aa,_
`Y, ,aa `""""""""""'' ``""""'' "Y,
Y, d'8 "Ya `Y,
`b 8 8 `Y, Y,
Ya o ,8 8 b `b
Yb,_,dP 8 Y 8
`"""" Y 8 8
I, 8 8
`b P [
`b d' [
d ,P [
,d' ,PY, ,P"YaaaaaaP"Ybaaa,,_ d' [
d" ,P" Y, d' 8' `""db, d' 8
d' ,P" `Y, 8 I, d'"b, 8a P
d( ( `Y, P `b ,P `Y, 8`Ya___d'
"Y, "b, `Y, ,I 8 d' `8 8 `"""'
"Y, "b, __ `8, d' ,8 ,P 8 8
"Y, "bd88b `b 8 I' d' Y, 8
"Y, 888b 8 8 8 ,P `b 8
"Ya,,d888b8 P d' ,P' 8 Y,
`"""",d" ,I ,adPb__aP' Y `b
,a8P,__aP' d888888P' ,d 8
d8888888' 88888888 ,d888bbaaP
88888888 88888888'

View File

@@ -0,0 +1,45 @@
'''''''''''''''''''''''''''''''''''''
.1!!!!!!!!!!!1?ab?!!1aba?!!!!!!!!!!!1;
,!'''''''''=!!;+=.''.,=:!!;,'''''''',!
,! ,!!+' .:!:' ,!
,! :!+ .:!= ,!
,! ';;' ,!+ ,!
,! '??;!;;!!;;;;;;;;;;;;;+;;+!: ,!
,! ';a=:!,,;!,,,,,,=!!!!+?!==!=!+ +!
,! :;!'+; +: .1++;:!. ,!=!,.1:
,! =!.!'+; :: .! +:!. ::=!.1:
,! !='!'+; :: .!' +:!. +: ;:=!
,!+; '!'+; :: .!' +:!. +: .!=!
,!!= '!'+; :: .!' +:!. +: ;;!
,1!' '!'+; :: .!' +:!. +: ,1!
,a: '!'+; :: .!' +:!. +: '11
,b= '!.+;'':;'.....,1!!1:!. +: !?
,b. '!..;!!1?!!!!!!!!111!; +: :a
,?' '!.';!!!!!!!!!!!!!!!!;;;+ +: =?
,! '!.=!,================,=!'+: ,!
,! '!'+; '!'+: ,!
,! '!'+; '!'+: ,!
,?' '!'+; .,,' '' '''' '' '!'+: =?
,b. '!'+; d00e,ba d!ab c? '!'+: :a
,b= '!'+; fd10;ed g?cf fc '!'+: !?
,a: '!'+; fd10;bg;0:?0:01 '!'+: '11
,1!' '!'+; f$0e,+0ff ,gfg. '!'+: ,1!
,!!= '!'+; fb.' e@? c@b '!'+: ;;!
,!+; '!'+; d? 1f= ;g: '!'+: .!=!
,! !='!'+; ,. ', ',' '!'+: ;:,!
,! =!.!=:; '!=::=!',!
,! :;??a; '?1a;!, ,!
,! ';baa1=++===============+a?ba+ ,!
,! '?a!1!!!!!!!!!!!!!!!!!!!1!a; ,!
,! ';;' ,!+ ,!
,! :!+ .:!= ,!
,! ,!!+' .:!:' ,!
,!'''''''''=;?1+=.''.,=;?1;,'''''''',!
.1!!!!!!!!!!!1?bb?!!1aba11!!!!!!!!!!1;
''''''''''''' ''''''''' '''''''''''''

12
static/ascii_art/test.txt Normal file
View File

@@ -0,0 +1,12 @@
a@@@@a
a@@@@@@@@@@@@a
a@@@@@@by@@@@@@@@a
a@@@@@S@C@E@S@W@@@@@@a
@@@@@@@@@@@@@@@@@@@@@@
`@@@@@@`\\//'@@@@@@'
,, || ,, S.C.E.S.W.
/(-\ || /.)m
,---' /`-'||`-'\ `----,
/( )__)) || ((,==( )\
_ /_//___\\ __|| ___\\ __\\ ____
`` `` /MM\ '' ''

View File

Before

Width:  |  Height:  |  Size: 939 KiB

After

Width:  |  Height:  |  Size: 939 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 MiB

After

Width:  |  Height:  |  Size: 1.7 MiB

View File

Before

Width:  |  Height:  |  Size: 829 KiB

After

Width:  |  Height:  |  Size: 829 KiB

View File

Before

Width:  |  Height:  |  Size: 275 KiB

After

Width:  |  Height:  |  Size: 275 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 MiB

After

Width:  |  Height:  |  Size: 2.0 MiB

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 317 KiB

After

Width:  |  Height:  |  Size: 317 KiB

75
templates/ascii.html Normal file
View File

@@ -0,0 +1,75 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/x-icon" href="/static/images/pvv_logo.png">
<title>ASCII</title>
<style>
body {
margin: 0;
background: black;
display: flex;
justify-content: center;
align-items: center;
color: white;
height: 100vh;
}
pre {
white-space: pre;
font-family: monospace;
font-size: 14px;
line-height: 1.2;
}
</style>
</head>
<body>
<pre id="ascii">
a@@@@a
a@@@@@@@@@@@@a
a@@@@@@by@@@@@@@@a
a@@@@@S@C@E@S@W@@@@@@a
@@@@@@@@@@@@@@@@@@@@@@
`@@@@@@`\\//'@@@@@@'
,, || ,, S.C.E.S.W.
/(-\ || /.)m
,---' /`-'||`-'\ `----,
/( )__)) || ((,==( )\
_ /_//___\\ __|| ___\\ __\\ ____
`` `` /MM\ '' ''
</pre>
<script>
fetch("/files")
.then(res => res.json())
.then(files => {
const AsciiObj = files.AsciiFiles
let index = 0;
const preElement = document.getElementById("ascii");
const nextAscii = () => {
const filePath = AsciiObj[index].Name;
fetch(filePath)
.then(res => {return res.text();})
.then(fileContent => {preElement.textContent = fileContent;})
.catch(err => {
console.error("PANIC FETCH .txt FAILED PANIC!!")
preElement.textContent = fileContent;
})
index = (index + 1) % AsciiObj.length;
}
nextAscii();
setInterval(nextAscii, 1000);
}).catch(err => {
console.error("PANIC FETCH of file list FAILED!", err);
preElement.textContent = "Error loading file list.";
});
</script>
</body>
</html>

View File

@@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/x-icon" href="/static/images/pvv_logo.png">
<title>IMAGES</title>
<style>
body {
@@ -22,17 +23,18 @@
</head>
<body>
<img id="images" src="base.png" alt="images">
<img id="images" src="/static/images/pvv_logo.png" alt="images">
<script>
fetch("/files")
.then(res => res.json())
.then(files => {
const images = files
const images = files.ImageNames
console.log(images)
let index = 0;
setInterval(() => {
index = (index + 1) % images.length;
document.getElementById("images").src = images[index];
}, 10000);
}, 1000);
});
</script>
</body>