From 90e7a95358368fe71bdde1201deaa2b556682f4f Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 30 Jul 2024 00:12:12 +0200 Subject: [PATCH] Improved frontpage --- App.go | 77 ++++++++++++++++++--------- Project.go | 31 +++++++++++ posts/about.md | 6 --- posts/arch-linux-on-raspberry-pi-5.md | 2 +- projects/1-q.md | 7 +++ projects/2-web.md | 7 +++ projects/3-notify.md | 6 +++ public/app.css | 9 +++- public/app.html | 5 +- 9 files changed, 112 insertions(+), 38 deletions(-) create mode 100644 Project.go create mode 100644 projects/1-q.md create mode 100644 projects/2-web.md create mode 100644 projects/3-notify.md diff --git a/App.go b/App.go index fcf2775..d9cdb14 100644 --- a/App.go +++ b/App.go @@ -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}", 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(`%s`, post.Title, strings.Join(post.Tags, ",")) + content := "" + + if slices.Contains(post.Tags, "article") { + content = fmt.Sprintf( + `

%s

%s
`, + post.Title, + post.Created, + post.Created[:len("YYYY-MM-DD")], + markdown.Render(post.Content), + ) + } else { + content = fmt.Sprintf( + `

%s

%s`, + post.Title, + markdown.Render(post.Content), + ) + } + + return render(ctx, head, content) + } + s.Get("/", func(ctx web.Context) error { + head := fmt.Sprintf(`%s`, "Projects", "projects") + + body := strings.Builder{} + body.WriteString(`

Projects

`) + + for i, markdown := range app.projects { + body.WriteString(markdown) + + if i != len(app.projects)-1 { + body.WriteString(`
`) + } + } + + return render(ctx, head, body.String()) + }) + + s.Get("/blog", func(ctx web.Context) error { html := bytes.Buffer{} html.WriteString(`

Blog