From 409c87dd7fa3da2124025ca2292fc53f7f5764d3 Mon Sep 17 00:00:00 2001 From: Luka Hietala Date: Tue, 18 Nov 2025 08:59:18 +0200 Subject: [PATCH] lataa static tiedostot --- main.go | 17 +++++++++++++---- templates/category.tmpl | 5 ----- templates/index.tmpl | 8 -------- web/static/styles.css | 3 +++ web/templates/index.html | 13 +++++++++++++ 5 files changed, 29 insertions(+), 17 deletions(-) delete mode 100644 templates/category.tmpl delete mode 100644 templates/index.tmpl create mode 100644 web/static/styles.css create mode 100644 web/templates/index.html diff --git a/main.go b/main.go index 1337bee..5f884e3 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,8 @@ func main() { defer db.Close() router := gin.Default() - router.LoadHTMLGlob("templates/*") + router.Static("/static", "web/static/") + router.LoadHTMLGlob("web/templates/*") router.GET("/", func(c *gin.Context) { articles, err := database.GetArticles(db) @@ -31,7 +32,7 @@ func main() { return } - c.HTML(200, "index.tmpl", gin.H{ + c.HTML(200, "index.html", gin.H{ "Articles": articles, "Categories": categories, }) @@ -46,8 +47,16 @@ func main() { return } - c.HTML(200, "category.tmpl", gin.H{ - "Articles": articles, + categories, err := database.GetCategories(db) + + if err != nil { + c.JSON(500, gin.H{"error": err.Error()}) + return + } + + c.HTML(200, "index.html", gin.H{ + "Articles": articles, + "Categories": categories, }) }) diff --git a/templates/category.tmpl b/templates/category.tmpl deleted file mode 100644 index ec30db0..0000000 --- a/templates/category.tmpl +++ /dev/null @@ -1,5 +0,0 @@ - - {{range .Articles}} - {{ .}}
- {{end}} - \ No newline at end of file diff --git a/templates/index.tmpl b/templates/index.tmpl deleted file mode 100644 index a306960..0000000 --- a/templates/index.tmpl +++ /dev/null @@ -1,8 +0,0 @@ - - {{range .Articles}} - {{ .}}
- {{end}} - {{range .Categories}} - {{ .Name }}
- {{end}} - \ No newline at end of file diff --git a/web/static/styles.css b/web/static/styles.css new file mode 100644 index 0000000..6ca6800 --- /dev/null +++ b/web/static/styles.css @@ -0,0 +1,3 @@ +* { + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; +} \ No newline at end of file diff --git a/web/templates/index.html b/web/templates/index.html new file mode 100644 index 0000000..10abebc --- /dev/null +++ b/web/templates/index.html @@ -0,0 +1,13 @@ +{{ define "index.html" }} + + + + + {{range .Articles}} + {{ .}}
+ {{end}} + {{range .Categories}} + {{ .Name }}
+ {{end}} + +{{ end }} \ No newline at end of file -- 2.47.3