From 301011869547327ba554a9f5ef6fb16daf56c7e2 Mon Sep 17 00:00:00 2001 From: Hazel Noack Date: Thu, 3 Jul 2025 14:29:30 +0200 Subject: [PATCH] added rendering of index --- frontend/index.html | 6 +++--- go.mod | 13 +++++++++++++ go.sum | 21 +++++++++++++++++++++ internal/rendering/template.go | 19 +++++++++++++++++++ main.go | 26 +++++++++++++++++--------- 5 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 go.sum create mode 100644 internal/rendering/template.go diff --git a/frontend/index.html b/frontend/index.html index 66757bb..a68b16d 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -3,7 +3,7 @@ - NewTab + {{ .PageTitle }} @@ -11,7 +11,7 @@
@@ -28,7 +28,7 @@ ] Array.from(document.querySelectorAll(".phrases")).forEach(element => { - element.textContent = phrases[Math.floor(Math.random()*phrases.length)]; + // element.textContent = phrases[Math.floor(Math.random()*phrases.length)]; }) document.addEventListener('DOMContentLoaded', function() { diff --git a/go.mod b/go.mod index ba02f2f..f0b8eac 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,16 @@ module gitea.elara.ws/Hazel/transfem-startpage go 1.24.2 + +require ( + github.com/labstack/echo/v4 v4.13.4 // indirect + github.com/labstack/gommon v0.4.2 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect + github.com/valyala/fasttemplate v1.2.2 // indirect + golang.org/x/crypto v0.38.0 // indirect + golang.org/x/net v0.40.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/text v0.25.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..de42c50 --- /dev/null +++ b/go.sum @@ -0,0 +1,21 @@ +github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA= +github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ= +github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= +github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= +github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= +golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= +golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= +golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= +golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= +golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= diff --git a/internal/rendering/template.go b/internal/rendering/template.go new file mode 100644 index 0000000..1820481 --- /dev/null +++ b/internal/rendering/template.go @@ -0,0 +1,19 @@ +package rendering + +import ( + "html/template" + "log" + "os" +) + +func getFileContent() string { + content, err := os.ReadFile("frontend/index.html") + + if err != nil { + log.Fatal(err) + } + + return string(content) +} + +var IndexTemplate = template.Must(template.New("index").Parse(getFileContent())) diff --git a/main.go b/main.go index 410e6d7..b4dba25 100644 --- a/main.go +++ b/main.go @@ -1,21 +1,29 @@ package main import ( + "bytes" "fmt" + "net/http" - "gitea.elara.ws/Hazel/transfem-startpage/internal/diyhrt" + "gitea.elara.ws/Hazel/transfem-startpage/internal/rendering" + "github.com/labstack/echo/v4" ) +var CurrentRenderingConfig = rendering.DefaultRenderingConfig() + +func getIndex(c echo.Context) error { + var tpl bytes.Buffer + rendering.IndexTemplate.Execute(&tpl, CurrentRenderingConfig) + + return c.HTML(http.StatusOK, tpl.String()) +} + func main() { fmt.Println("running transfem startpage") - listings, err := diyhrt.GetListings() - if err != nil { - fmt.Println(err) - return - } + e := echo.New() + e.Static("/assets", "frontend/assets") + e.GET("/", getIndex) - for _, l := range listings { - fmt.Println(l) - } + e.Logger.Fatal(e.Start(":5500")) }