From f72ff5820dbd29d5c329efdc1884e85bdf9254a0 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 2 Apr 2024 16:20:44 +0200 Subject: [PATCH] Simplified layout --- App.go | 25 ++++++++++++++++++------- public/app.css | 4 ++-- public/app.html | 18 ++++++++++++++---- public/body.html | 11 ----------- 4 files changed, 34 insertions(+), 24 deletions(-) delete mode 100644 public/body.html diff --git a/App.go b/App.go index 99fe173..feae23e 100644 --- a/App.go +++ b/App.go @@ -18,9 +18,7 @@ type App struct { func (app *App) Init() { app.html = mustLoadClean("public/app.html") css := mustLoadClean("public/app.css") - body := mustLoadClean("public/body.html") - app.html = strings.Replace(app.html, "{head}", fmt.Sprintf("", css), 1) - app.html = strings.Replace(app.html, "{body}", body, 1) + app.html = strings.Replace(app.html, "{head}", fmt.Sprintf("{head}", css), 1) app.posts = loadPosts("posts") } @@ -39,17 +37,30 @@ func (app *App) Run() { return ctx.Next() }) - render := func(ctx web.Context, content string) error { - return send.HTML(ctx, strings.Replace(app.html, "{content}", content, 1)) + s.Use(func(ctx web.Context) error { + path := ctx.Request().Path() + + if len(path) > 1 && strings.HasSuffix(path, "/") { + return ctx.Redirect(301, strings.TrimSuffix(path, "/")) + } + + return ctx.Next() + }) + + render := func(ctx web.Context, head string, body string) error { + html := app.html + html = strings.Replace(html, "{head}", head, 1) + html = strings.Replace(html, "{body}", body, 1) + return send.HTML(ctx, html) } s.Get("/", func(ctx web.Context) error { - return render(ctx, markdown.Render("# Frontpage")) + return render(ctx, "akyoto.dev", markdown.Render("# Frontpage")) }) s.Get("/:post", func(ctx web.Context) error { post := ctx.Request().Param("post") - return render(ctx, app.posts[post]) + return render(ctx, "akyoto.dev", app.posts[post]) }) s.Run(":8080") diff --git a/public/app.css b/public/app.css index a4bb874..9f36718 100644 --- a/public/app.css +++ b/public/app.css @@ -169,11 +169,11 @@ nav { align-items: center; } -.nav-item { +nav a { color: var(--grey-color); } -.nav-item:hover { +nav a:hover { text-decoration: none; } diff --git a/public/app.html b/public/app.html index cf4796c..b16f1f8 100644 --- a/public/app.html +++ b/public/app.html @@ -1,12 +1,22 @@ - - - + + + {head} - {body} +
+ +
+
+ {body} +
\ No newline at end of file diff --git a/public/body.html b/public/body.html deleted file mode 100644 index bff51e6..0000000 --- a/public/body.html +++ /dev/null @@ -1,11 +0,0 @@ -
- -
-
- {content} -
\ No newline at end of file