diff --git a/main.go b/main.go
index 1337bee..5f884e3 100644
--- a/main.go
+++ b/main.go
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)
return
}
- c.HTML(200, "index.tmpl", gin.H{
+ c.HTML(200, "index.html", gin.H{
"Articles": articles,
"Categories": categories,
})
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
-<html>
- {{range .Articles}}
- {{ .}}<br />
- {{end}}
-</html>
\ 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
+* {
+ 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/templates/index.tmpl b/web/templates/index.html
similarity index 76%
rename from templates/index.tmpl
rename to web/templates/index.html
index a306960..10abebc 100644
--- a/templates/index.tmpl
+++ b/web/templates/index.html
+{{ define "index.html" }}
<html>
+ <head>
+ <link rel="stylesheet" href="/static/styles.css">
+ </head>
{{range .Articles}}
{{ .}}<br />
{{end}}
{{range .Categories}}
{{ .Name }}<br />
{{end}}
-</html>
\ No newline at end of file
+</html>
+{{ end }}
\ No newline at end of file