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() {
|
||||
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("<style>%s</style>", css), 1)
|
||||
app.html = strings.Replace(app.html, "{body}", body, 1)
|
||||
app.html = strings.Replace(app.html, "{head}", fmt.Sprintf("{head}<style>%s</style>", 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, "<title>akyoto.dev</title>", 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, "<title>akyoto.dev</title>", app.posts[post])
|
||||
})
|
||||
|
||||
s.Run(":8080")
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,22 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" href="/static/favicon.avif" type="image/avif" />
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" href="/static/favicon.avif" type="image/avif">
|
||||
{head}
|
||||
</head>
|
||||
<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>
|
||||
</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