Improved frontpage

This commit is contained in:
Eduard Urbach 2024-07-30 00:12:12 +02:00
parent fd32c002c0
commit 90e7a95358
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
9 changed files with 112 additions and 38 deletions

77
App.go
View File

@ -14,19 +14,23 @@ import (
)
type App struct {
html string
posts map[string]*Post
html string
posts map[string]*Post
projects []string
}
func New() *App {
html := loadClean("public/app.html")
css := loadClean("public/app.css")
html = strings.Replace(html, "{head}", fmt.Sprintf("{head}<style>%s</style>", css), 1)
html = strings.ReplaceAll(html, "{avatar}", "https://gravatar.com/avatar/35f2c481f711f0a36bc0e930c4c15eb0bcc794aaeef405a060fe3e28d1c7b7e5.png?s=64")
posts := loadPosts("posts")
projects := loadProjects("projects")
return &App{
html: html,
posts: posts,
html: html,
posts: posts,
projects: projects,
}
}
@ -62,7 +66,48 @@ func (app *App) Run() {
return send.HTML(ctx, html)
}
renderPost := func(ctx web.Context, id string) error {
post := app.posts[id]
head := fmt.Sprintf(`<title>%s</title><meta name="keywords" content="%s">`, post.Title, strings.Join(post.Tags, ","))
content := ""
if slices.Contains(post.Tags, "article") {
content = fmt.Sprintf(
`<article><header><h1>%s</h1><time datetime="%s">%s</time></header>%s</article>`,
post.Title,
post.Created,
post.Created[:len("YYYY-MM-DD")],
markdown.Render(post.Content),
)
} else {
content = fmt.Sprintf(
`<h2>%s</h2>%s`,
post.Title,
markdown.Render(post.Content),
)
}
return render(ctx, head, content)
}
s.Get("/", func(ctx web.Context) error {
head := fmt.Sprintf(`<title>%s</title><meta name="keywords" content="%s">`, "Projects", "projects")
body := strings.Builder{}
body.WriteString(`<h2>Projects</h2>`)
for i, markdown := range app.projects {
body.WriteString(markdown)
if i != len(app.projects)-1 {
body.WriteString(`<hr>`)
}
}
return render(ctx, head, body.String())
})
s.Get("/blog", func(ctx web.Context) error {
html := bytes.Buffer{}
html.WriteString(`<h2>Blog</h2><ul class="blog">`)
articles := []*Post{}
@ -88,28 +133,8 @@ func (app *App) Run() {
})
s.Get("/:post", func(ctx web.Context) error {
slug := ctx.Request().Param("post")
post := app.posts[slug]
head := fmt.Sprintf(`<title>%s</title><meta name="keywords" content="%s">`, post.Title, strings.Join(post.Tags, ","))
content := ""
if slices.Contains(post.Tags, "article") {
content = fmt.Sprintf(
`<article><header><h1>%s</h1><time datetime="%s">%s</time></header>%s</article>`,
post.Title,
post.Created,
post.Created[:len("YYYY-MM-DD")],
markdown.Render(post.Content),
)
} else {
content = fmt.Sprintf(
`<h2>%s</h2>%s`,
post.Title,
markdown.Render(post.Content),
)
}
return render(ctx, head, content)
id := ctx.Request().Param("post")
return renderPost(ctx, id)
})
address := os.Getenv("LISTEN")

31
Project.go Normal file
View File

@ -0,0 +1,31 @@
package main
import (
"os"
"strings"
"git.akyoto.dev/go/markdown"
)
func loadProjects(directory string) []string {
entries, err := os.ReadDir(directory)
if err != nil {
panic(err)
}
projects := []string{}
for _, entry := range entries {
fileName := entry.Name()
if !strings.HasSuffix(fileName, ".md") {
continue
}
content := load("projects/" + fileName)
projects = append(projects, markdown.Render(content))
}
return projects
}

View File

@ -51,9 +51,3 @@ I speak the following languages to varying degrees:
In case you want to contribute to any projects, join [#community:akyoto.dev](https://matrix.to/#/#community:akyoto.dev) with a client you like.
I recommend [Cinny](https://cinny.in/) because it has a beautiful design and closely resembles Discord.
## Donations
- [Kofi](https://ko-fi.com/akyoto)
- [PayPal](https://www.paypal.com/donate/?hosted_button_id=EUBC5TT82APK6)
- [Stripe](https://donate.stripe.com/28o9Dn2xlehb6Zi8ww)

View File

@ -1,6 +1,6 @@
---
title: Arch Linux on Raspberry Pi 5
tags: article arch linux arm raspberry pi5 nvme
tags: article guide arch linux arm raspberry pi5 nvme
created: 2024-04-05T18:26:55Z
published: true
---

7
projects/1-q.md Normal file
View File

@ -0,0 +1,7 @@
### 🌱 q
A programming language that is best described as a modern `C` with a focus on simplicity.
The compiler is quick, the executables are tiny and fast.
Currently under heavy development and Linux only.
[git](https://git.akyoto.dev/cli/q) | [donate](https://buy.stripe.com/4gw7vf5Jxflf83m7st)

7
projects/2-web.md Normal file
View File

@ -0,0 +1,7 @@
### 🚀 web
The fastest and most scalable HTTP router for Go.
Intended to be used behind a reverse proxy like `caddy`.
This website is running it on the backend.
[git](https://git.akyoto.dev/go/web) | [donate](https://buy.stripe.com/7sIdTD9ZN6OJ3N6bIK) | [benchmarks](https://web-frameworks-benchmark.netlify.app/result)

6
projects/3-notify.md Normal file
View File

@ -0,0 +1,6 @@
### 💃 notify.moe
An anime tracker, database and community.
The website is very lightweight using less than 50 KB at its core and I still keep my promise to never show ads since 2016.
[git](https://git.akyoto.dev/web/notify.moe) | [donate](https://buy.stripe.com/bIYcPzeg35KF0AUeUX)

View File

@ -116,7 +116,7 @@ h2 {
h3 {
color: var(--header-color);
font-size: 1.3rem;
font-size: 1.4rem;
font-weight: normal;
}
@ -160,7 +160,7 @@ nav {
display: flex;
gap: 1rem;
list-style-type: none;
align-items: center;
justify-content: center;
}
nav a {
@ -180,6 +180,11 @@ article header time {
color: var(--grey-color);
}
img {
width: 100%;
border-radius: 3px;
}
.blog li {
display: flex;
}

View File

@ -3,16 +3,15 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="https://gravatar.com/avatar/35f2c481f711f0a36bc0e930c4c15eb0bcc794aaeef405a060fe3e28d1c7b7e5.png?s=64" type="image/png">
<link rel="icon" href="{avatar}" type="image/png">
{head}
</head>
<body>
<header>
<nav>
<a href="/" class="title">akyoto.dev</a>
<a href="/projects">projects</a>
<a href="/blog">blog</a>
<a href="/contact">contact</a>
<a href="/about">about</a>
</nav>
</header>
<main>