Simplified layout
This commit is contained in:
parent
48dbc0bbed
commit
f72ff5820d
25
App.go
25
App.go
@ -18,9 +18,7 @@ type App struct {
|
|||||||
func (app *App) Init() {
|
func (app *App) Init() {
|
||||||
app.html = mustLoadClean("public/app.html")
|
app.html = mustLoadClean("public/app.html")
|
||||||
css := mustLoadClean("public/app.css")
|
css := mustLoadClean("public/app.css")
|
||||||
body := mustLoadClean("public/body.html")
|
app.html = strings.Replace(app.html, "{head}", fmt.Sprintf("{head}<style>%s</style>", css), 1)
|
||||||
app.html = strings.Replace(app.html, "{head}", fmt.Sprintf("<style>%s</style>", css), 1)
|
|
||||||
app.html = strings.Replace(app.html, "{body}", body, 1)
|
|
||||||
app.posts = loadPosts("posts")
|
app.posts = loadPosts("posts")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,17 +37,30 @@ func (app *App) Run() {
|
|||||||
return ctx.Next()
|
return ctx.Next()
|
||||||
})
|
})
|
||||||
|
|
||||||
render := func(ctx web.Context, content string) error {
|
s.Use(func(ctx web.Context) error {
|
||||||
return send.HTML(ctx, strings.Replace(app.html, "{content}", content, 1))
|
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 {
|
s.Get("/", func(ctx web.Context) error {
|
||||||
return render(ctx, markdown.Render("# Frontpage"))
|
return render(ctx, "<title>akyoto.dev</title>", markdown.Render("# Frontpage"))
|
||||||
})
|
})
|
||||||
|
|
||||||
s.Get("/:post", func(ctx web.Context) error {
|
s.Get("/:post", func(ctx web.Context) error {
|
||||||
post := ctx.Request().Param("post")
|
post := ctx.Request().Param("post")
|
||||||
return render(ctx, app.posts[post])
|
return render(ctx, "<title>akyoto.dev</title>", app.posts[post])
|
||||||
})
|
})
|
||||||
|
|
||||||
s.Run(":8080")
|
s.Run(":8080")
|
||||||
|
@ -169,11 +169,11 @@ nav {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-item {
|
nav a {
|
||||||
color: var(--grey-color);
|
color: var(--grey-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-item:hover {
|
nav a:hover {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,22 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="icon" href="/static/favicon.avif" type="image/avif" />
|
<link rel="icon" href="/static/favicon.avif" type="image/avif">
|
||||||
{head}
|
{head}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{body}
|
<header>
|
||||||
|
<nav>
|
||||||
|
<a href="/" class="title">akyoto.dev</a>
|
||||||
|
<a href="/projects">projects</a>
|
||||||
|
<a href="/contact">contact</a>
|
||||||
|
<a href="/about">about</a>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
<main>
|
||||||
|
{body}
|
||||||
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -1,11 +0,0 @@
|
|||||||
<header>
|
|
||||||
<nav>
|
|
||||||
<a href="/" class="nav-item title">akyoto.dev</a>
|
|
||||||
<a href="/projects" class="nav-item">projects</a>
|
|
||||||
<a href="/contact" class="nav-item">contact</a>
|
|
||||||
<a href="/about" class="nav-item">about</a>
|
|
||||||
</nav>
|
|
||||||
</header>
|
|
||||||
<main>
|
|
||||||
{content}
|
|
||||||
</main>
|
|
Loading…
x
Reference in New Issue
Block a user