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, "