templ generate, add markdown syntax highlighting, fix stuff

This commit is contained in:
2025-08-17 14:15:46 +00:00
parent 59d82ae563
commit 749d68cdeb
23 changed files with 1106 additions and 135 deletions

View File

@@ -1,57 +1,65 @@
package templates
import "time"
import (
"fmt"
"git.valxntine.dev/valxntine/blog/models"
)
templ PostList(posts []models.Post, page, totalPages int) {
<div id="post-list">
<ul class="blog-posts">
for _, post := range posts {
@PostListItem(post)
}
</ul>
if totalPages > 1 {
@Pagination(page, totalPages)
}
</div>
<div id="post-list">
<ul class="blog-posts">
for _, post := range posts {
@PostListItem(post)
}
</ul>
if totalPages > 1 {
@Pagination(page, totalPages)
}
</div>
}
templ PostListItem(post models.Post) {
<li class="blog-post">
<div class="post-title">
<a href={ templ.URL("/posts/" + post.Slug) }
hx-get={ "/posts/" + post.Slug }
hx-target="main"
hx-push-url="true">
{ post.Title }
</a>
</div>
<div class="post-meta">
Posted: { post.PublishedAt.Format("2006-01-02") } |
Tags:
for i, tag := range post.Tags {
if i > 0 {
,
}
<a href={ templ.URL("/tags/" + tag) }
hx-get={ "/tags/" + tag }
hx-target="main"
hx-push-url="true">
{ tag }
</a>
}
| Words: { fmt.Sprintf("%d", post.WordCount) }
</div>
<div class="post-excerpt">
{ post.Excerpt }
</div>
<div class="read-more">
<a href={ templ.URL("/posts/" + post.Slug) }
hx-get={ "/posts/" + post.Slug }
hx-target="main"
hx-push-url=true>
[Read more...]
</a>
</div>
</li>
<li class="blog-post">
<div class="post-title">
<a
href={ templ.URL("/posts/" + post.Slug) }
hx-get={ "/posts/" + post.Slug }
hx-target="main"
hx-push-url="true"
>
{ post.Title }
</a>
</div>
<div class="post-meta">
Posted: { post.PublishedAt.Format("2006-01-02") } |
Tags:
for i, tag := range post.Tags {
if i > 0 {
,
}
<a
href={ templ.URL("/tags/" + tag) }
hx-get={ "/tags/" + tag }
hx-target="main"
hx-push-url="true"
>
{ tag }
</a>
}
| Words: { fmt.Sprintf("%d", post.WordCount) }
</div>
<div class="post-excerpt">
{ post.Excerpt }
</div>
<div class="read-more">
<a
href={ templ.URL("/posts/" + post.Slug) }
hx-get={ "/posts/" + post.Slug }
hx-target="main"
hx-push-url="true"
>
[Read more...]
</a>
</div>
</li>
}