Skip to content

Commit 6795eca

Browse files
committed
feat: tags page
1 parent 0968c57 commit 6795eca

File tree

5 files changed

+66
-1
lines changed

5 files changed

+66
-1
lines changed

main

15 MB
Binary file not shown.

main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func FetchPosts(c *gin.Context) {
135135
}
136136

137137
c.HTML(http.StatusOK, "index.html", map[string]any{
138+
"Title": pageQuery.CategoryName,
138139
"Posts": discussions,
139140
"Navbars": config.Categories,
140141
"About": config.About,
@@ -167,6 +168,21 @@ func FetchPost(c *gin.Context) {
167168
})
168169
}
169170

171+
func TagPage(c *gin.Context) {
172+
labels, err := api.FetchAllLabels()
173+
if err != nil {
174+
c.HTML(http.StatusBadRequest, "error.html", map[string]any{
175+
"Message": err.Error(),
176+
})
177+
return
178+
}
179+
c.HTML(http.StatusOK, "tags.html", map[string]any{
180+
"Labels": labels,
181+
"Navbars": config.Categories,
182+
"About": config.About,
183+
})
184+
}
185+
170186
func AboutPage(c *gin.Context) {
171187
discussion, err := api.FetchPost(config.About)
172188
if err != nil {
@@ -226,6 +242,7 @@ func main() {
226242
r.GET("/", cache.CacheByRequestURI(memoryCache, 30*time.Second), FetchPosts)
227243
r.GET("/category/:category_id/:category_name", cache.CacheByRequestURI(memoryCache, 30*time.Second), FetchPosts)
228244
r.GET("/post/:id/:title", cache.CacheByRequestURI(memoryCache, 1*time.Hour), FetchPost)
245+
r.GET("/tags", cache.CacheByRequestURI(memoryCache, 24*time.Hour), TagPage)
229246
r.GET("/atom.xml", cache.CacheByRequestURI(memoryCache, 24*time.Hour), GenerateFeed)
230247
r.GET("/404", func(ctx *gin.Context) {
231248
ctx.HTML(http.StatusOK, "error.html", nil)

templates/base/navbar.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
<li><a class="relative block px-3 py-2 transition hover:text-teal-500 dark:hover:text-teal-400 item-menu"
1111
href="/category/{{.Id}}/{{.Name}}">{{.Name}}</a></li>
1212
{{ end }}
13-
13+
<li><a class="relative block px-3 py-2 transition hover:text-teal-500 dark:hover:text-teal-400 item-menu"
14+
href="/tags">Tags</a></li>
1415
{{ if .About }}
1516
<li><a class="relative block px-3 py-2 transition hover:text-teal-500 dark:hover:text-teal-400 item-menu"
1617
href="/about">About</a></li>

templates/pages/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<meta charset="UTF-8">
88
<meta name="viewport" content="width=device-width, initial-scale=1.0">
99
<script src="https://cdn.tailwindcss.com"></script>
10+
<title>{{ .Title }}</title>
11+
<meta property="description" content="{{ .Title }}" />
12+
<meta property="title" content="{{ .Title }}" />
1013
</head>
1114

1215
<body class="flex h-full flex-col bg-zinc-50 dark:bg-black">

templates/pages/tags.html

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!doctype html>
2+
<html class="h-full antialiased js-focus-visible"
3+
style="--header-position:sticky; --content-offset:116px; --header-height:180px; --header-mb:-116px; --header-top:0px; --avatar-top:0px; --avatar-image-transform:translate3d(0rem, 0, 0) scale(1); --avatar-border-transform:translate3d(-0.222222rem, 0, 0) scale(1.77778); --avatar-border-opacity:0;"
4+
data-color-mode="auto" data-light-theme="light" data-dark-theme="dark">
5+
6+
<head>
7+
<meta charset="UTF-8">
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
9+
<title>Tags</title>
10+
<script src="https://cdn.tailwindcss.com"></script>
11+
<meta property="description" content="tags" />
12+
<meta property="title" content="Tags" />
13+
</head>
14+
15+
<body class="flex h-full flex-col bg-zinc-50 dark:bg-black justify-between">
16+
<div class="inset-0 flex justify-center sm:px-8">
17+
{{template "navbar.html" .}}
18+
</div>
19+
20+
<main>
21+
<div class="sm:px-8 mt-16">
22+
<div class="mx-auto max-w-7xl lg:px-8">
23+
<div class="relative px-4 sm:px-8 lg:px-12">
24+
<div class="mx-auto max-w-2xl lg:max-w-5xl">
25+
<div class="mx-auto grid max-w-xl grid-cols-1 gap-y-36 lg:max-w-none lg:grid-cols-1">
26+
<div class="flex flex-col gap-16">
27+
<div class="justify-content-start w-100 mb-4 text-start">
28+
{{ range .Labels }}
29+
<a class="ml-8 bg-green-200 my-2 inline-block rounded-full px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-teal-500 shadow-md transition duration-150 ease-in-out hover:bg-green-300 hover:shadow-lg focus:bg-green-300 focus:shadow-lg focus:outline-none focus:ring-0 active:bg-green-400 active:shadow-lg dark:bg-green-600 dark:text-teal-200 dark:hover:bg-green-500 dark:focus:bg-green-500 dark:active:bg-green-400"
30+
href="/search?label={{.Name}}"> #{{.Name}} </a>
31+
{{ end }}
32+
</div>
33+
</div>
34+
</div>
35+
</div>
36+
</div>
37+
</div>
38+
</div>
39+
</main>
40+
41+
{{template "footer.html"}}
42+
</body>
43+
44+
</html>

0 commit comments

Comments
 (0)