Diff between 46cbef78e85028d6eabe309f447755e82c34d3f2 and 409c87dd7fa3da2124025ca2292fc53f7f5764d3

Changed Files

File Additions Deletions Status
main.go +13 -4 modified
templates/category.tmpl +0 -5 deleted
web/static/styles.css +3 -0 added
web/templates/index.html +6 -1 renamed

Full Patch

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 @@
-<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
@@ -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/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
@@ -1,8 +1,13 @@
+{{ 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