diff options
| author | maxim nikonov <maxim.nikonov@hqo.co> | 2025-09-20 01:12:44 +0500 |
|---|---|---|
| committer | maxim nikonov <maxim.nikonov@hqo.co> | 2025-09-20 01:12:44 +0500 |
| commit | 172ebc2cefcc3887b4b2a364eca93cbf8aa4e0c4 (patch) | |
| tree | 60af3651b3bce781f71267789d7e6d92dbf15d59 | |
| parent | 1ff2667b40a6956ffefbff20bdc87d2692e4ddd3 (diff) | |
feat
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | src/pages/posts/antarctida.html | 2 | ||||
| -rw-r--r-- | src/pages/posts/dungeons-and-zombies-minecraft-geology.html | 4 | ||||
| -rw-r--r-- | src/pages/posts/electricity-in-geology.html | 4 | ||||
| -rw-r--r-- | src/pages/posts/emiliania-huxleyi.html | 2 | ||||
| -rw-r--r-- | src/pages/posts/how-ores-are-born.html | 4 | ||||
| -rw-r--r-- | src/pages/templates/tags.html | 36 | ||||
| -rw-r--r-- | src/partials/sidebar.html | 6 | ||||
| -rw-r--r-- | src/templates/tags.html | 12 | ||||
| -rw-r--r-- | tags.go | 88 |
10 files changed, 137 insertions, 24 deletions
@@ -1,4 +1,5 @@ jelly-cms build/ tailwindcss-linux-x64 -tailwindcss-macos-arm64
\ No newline at end of file +tailwindcss-macos-arm64 +*.cgi
\ No newline at end of file diff --git a/src/pages/posts/antarctida.html b/src/pages/posts/antarctida.html index f57bf79..6356070 100644 --- a/src/pages/posts/antarctida.html +++ b/src/pages/posts/antarctida.html @@ -36,7 +36,7 @@ <path fill-rule="evenodd" d="M7.086 9.975a.75.75 0 0 1-1.06 0 3.5 3.5 0 0 1 0-4.95l2-2a3.5 3.5 0 0 1 5.396 4.402.75.75 0 0 1-1.251-.827 2 2 0 0 0-3.085-2.514l-2 2a2 2 0 0 0 0 2.828.75.75 0 0 1 0 1.06Z" clip-rule="evenodd" /> </svg> </a> - <a href="#" class="flex items-center justify-center bg-zinc-200 rounded-lg px-1.5 text-zinc-600 first-letter:capitalize hover:underline text-xs">геология</a> + <a data-tag="геология" href="/cgi/tags.cgi?tag=геология" class="flex items-center justify-center bg-zinc-200 rounded-lg px-1.5 text-zinc-600 first-letter:capitalize hover:underline text-xs">геология</a> </div> </header> <main class="space-y-2 mt-4"> diff --git a/src/pages/posts/dungeons-and-zombies-minecraft-geology.html b/src/pages/posts/dungeons-and-zombies-minecraft-geology.html index eeccf87..a4df58a 100644 --- a/src/pages/posts/dungeons-and-zombies-minecraft-geology.html +++ b/src/pages/posts/dungeons-and-zombies-minecraft-geology.html @@ -37,8 +37,8 @@ <path fill-rule="evenodd" d="M7.086 9.975a.75.75 0 0 1-1.06 0 3.5 3.5 0 0 1 0-4.95l2-2a3.5 3.5 0 0 1 5.396 4.402.75.75 0 0 1-1.251-.827 2 2 0 0 0-3.085-2.514l-2 2a2 2 0 0 0 0 2.828.75.75 0 0 1 0 1.06Z" clip-rule="evenodd" /> </svg> </a> - <a href="#" class="flex items-center justify-center bg-zinc-200 rounded-lg px-1.5 text-zinc-600 first-letter:capitalize hover:underline text-xs">геология</a> - <a href="#" class="flex items-center justify-center bg-green-200 rounded-lg px-1.5 text-green-600 first-letter:capitalize hover:underline text-xs">minecraft</a> + <a data-tag="геология" href="/cgi/tags.cgi?tag=геология" class="flex items-center justify-center bg-zinc-200 rounded-lg px-1.5 text-zinc-600 first-letter:capitalize hover:underline text-xs">геология</a> + <a data-tag="minecraft" href="/cgi/tags.cgi?tag=minecraft" class="flex items-center justify-center bg-green-200 rounded-lg px-1.5 text-green-600 first-letter:capitalize hover:underline text-xs">minecraft</a> </div> </header> <main class="space-y-2 mt-4"> diff --git a/src/pages/posts/electricity-in-geology.html b/src/pages/posts/electricity-in-geology.html index efcc05e..7774d25 100644 --- a/src/pages/posts/electricity-in-geology.html +++ b/src/pages/posts/electricity-in-geology.html @@ -36,8 +36,8 @@ <path fill-rule="evenodd" d="M7.086 9.975a.75.75 0 0 1-1.06 0 3.5 3.5 0 0 1 0-4.95l2-2a3.5 3.5 0 0 1 5.396 4.402.75.75 0 0 1-1.251-.827 2 2 0 0 0-3.085-2.514l-2 2a2 2 0 0 0 0 2.828.75.75 0 0 1 0 1.06Z" clip-rule="evenodd" /> </svg> </a> - <a href="#" class="flex items-center justify-center bg-zinc-200 rounded-lg px-1.5 text-zinc-600 first-letter:capitalize hover:underline text-xs">геология</a> - <a href="#" class="flex items-center justify-center bg-blue-200 rounded-lg px-1.5 text-blue-600 first-letter:capitalize hover:underline text-xs">электричество</a> + <a data-tag="геология" href="/cgi/tags.cgi?tag=геология" class="flex items-center justify-center bg-zinc-200 rounded-lg px-1.5 text-zinc-600 first-letter:capitalize hover:underline text-xs">геология</a> + <a data-tag="электричество" href="/cgi/tags.cgi?tag=электричество" class="flex items-center justify-center bg-blue-200 rounded-lg px-1.5 text-blue-600 first-letter:capitalize hover:underline text-xs">электричество</a> </div> </header> <main class="space-y-2 mt-4"> diff --git a/src/pages/posts/emiliania-huxleyi.html b/src/pages/posts/emiliania-huxleyi.html index 0cd69e2..247cb49 100644 --- a/src/pages/posts/emiliania-huxleyi.html +++ b/src/pages/posts/emiliania-huxleyi.html @@ -36,7 +36,7 @@ <path fill-rule="evenodd" d="M7.086 9.975a.75.75 0 0 1-1.06 0 3.5 3.5 0 0 1 0-4.95l2-2a3.5 3.5 0 0 1 5.396 4.402.75.75 0 0 1-1.251-.827 2 2 0 0 0-3.085-2.514l-2 2a2 2 0 0 0 0 2.828.75.75 0 0 1 0 1.06Z" clip-rule="evenodd" /> </svg> </a> - <a href="#" class="flex items-center justify-center bg-zinc-200 rounded-lg px-1.5 text-zinc-600 first-letter:capitalize hover:underline text-xs">геология</a> + <a data-tag="геология" href="/cgi/tags.cgi?tag=геология" class="flex items-center justify-center bg-zinc-200 rounded-lg px-1.5 text-zinc-600 first-letter:capitalize hover:underline text-xs">геология</a> </div> </header> <main class="space-y-2 mt-4"> diff --git a/src/pages/posts/how-ores-are-born.html b/src/pages/posts/how-ores-are-born.html index 8ee7d80..4e29b99 100644 --- a/src/pages/posts/how-ores-are-born.html +++ b/src/pages/posts/how-ores-are-born.html @@ -37,8 +37,8 @@ <path fill-rule="evenodd" d="M7.086 9.975a.75.75 0 0 1-1.06 0 3.5 3.5 0 0 1 0-4.95l2-2a3.5 3.5 0 0 1 5.396 4.402.75.75 0 0 1-1.251-.827 2 2 0 0 0-3.085-2.514l-2 2a2 2 0 0 0 0 2.828.75.75 0 0 1 0 1.06Z" clip-rule="evenodd" /> </svg> </a> - <a href="#" class="flex items-center justify-center bg-zinc-200 rounded-lg px-1.5 text-zinc-600 first-letter:capitalize hover:underline text-xs">геология</a> - <a href="#" class="flex items-center justify-center bg-green-200 rounded-lg px-1.5 text-green-600 first-letter:capitalize hover:underline text-xs">minecraft</a> + <a data-tag="геология" href="/cgi/tags.cgi?tag=геология" class="flex items-center justify-center bg-zinc-200 rounded-lg px-1.5 text-zinc-600 first-letter:capitalize hover:underline text-xs">геология</a> + <a data-tag="minecraft" href="/cgi/tags.cgi?tag=minecraft" class="flex items-center justify-center bg-green-200 rounded-lg px-1.5 text-green-600 first-letter:capitalize hover:underline text-xs">minecraft</a> </div> </header> <main class="space-y-2 mt-4"> diff --git a/src/pages/templates/tags.html b/src/pages/templates/tags.html new file mode 100644 index 0000000..f7e69da --- /dev/null +++ b/src/pages/templates/tags.html @@ -0,0 +1,36 @@ +<!DOCTYPE html> +<html class="h-full" lang="ru"> + +<head> + <title>Категории. Анна, хватит!</title> + <link rel="icon" href="/assets/icons/favicon.svg" type="image/svg+xml"> + <!-- OG --> + <meta property="og:title" content="Категории. Анна, хватит!" /> + <meta property="og:description" content="TODO" /> + <meta property="og:image" content="https://anna-hvatit.mlibren.com/og-images/common.jpg" /> + <meta property="og:url" content="https://anna-hvatit.mlibren.com" /> + <meta property="og:type" content="website" /> + <!-- OG --> + <meta charset="UTF-8"> + <link href="/main.css" rel="stylesheet"> + <meta name="viewport" content="width=device-width, initial-scale=1"> +</head> + +<body class="relative"> + <div class="fixed top-0 translate-x-12 translate-y-10 z-40 right-0"> + <span class="font-bold text-black rotate-45 w-[200px] text-center block bg-yellow-400">В разработке</span> + </div> + <!-- %include.header% --> + <main> + <div class="mx-auto flex flex-col-reverse py-12 md:grid gap-4 grid-cols-12 container max-sm:px-5"> + <section class="col-span-9"> + <h1 class="text-2xl font-serif first-letter:capitalize">Категория <!-- %cgi.tag% --></h1> + <!-- %cgi.list% --> + </section> + <!-- %include.sidebar% --> + </div> + </main> + <!-- %include.footer% --> +</body> + +</html>
\ No newline at end of file diff --git a/src/partials/sidebar.html b/src/partials/sidebar.html index e6b4666..2d7ae1c 100644 --- a/src/partials/sidebar.html +++ b/src/partials/sidebar.html @@ -17,9 +17,9 @@ <nav class="pt-6"> <span class="inline-block first-letter:capitalize">категории</span> <ul id="tags-aside" class="flex flex-wrap gap-2 mt-2"> - <li><a href="#" class="flex items-center justify-center bg-zinc-200 rounded-lg px-1.5 text-zinc-600 first-letter:capitalize text-xs hover:underline w-fit">геология</a></li> - <li><a href="#" class="flex items-center justify-center bg-green-200 rounded-lg px-1.5 text-green-600 first-letter:capitalize text-xs hover:underline w-fit">minecraft</a></li> - <li><a href="#" class="flex items-center justify-center bg-blue-200 rounded-lg px-1.5 text-blue-600 first-letter:capitalize text-xs hover:underline w-fit">электричество</a></li> + <li><a href="/cgi/tags.cgi?tag=геология" class="flex items-center justify-center bg-zinc-200 rounded-lg px-1.5 text-zinc-600 first-letter:capitalize text-xs hover:underline w-fit">геология</a></li> + <li><a href="/cgi/tags.cgi?tag=minecraft" class="flex items-center justify-center bg-green-200 rounded-lg px-1.5 text-green-600 first-letter:capitalize text-xs hover:underline w-fit">minecraft</a></li> + <li><a href="/cgi/tags.cgi?tag=электричество" class="flex items-center justify-center bg-blue-200 rounded-lg px-1.5 text-blue-600 first-letter:capitalize text-xs hover:underline w-fit">электричество</a></li> </ul> </nav> <nav class="pt-6 max-sm:hidden"> diff --git a/src/templates/tags.html b/src/templates/tags.html deleted file mode 100644 index 86c0626..0000000 --- a/src/templates/tags.html +++ /dev/null @@ -1,12 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="UTF-8"> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>Категории</title> -</head> -<body> - Категории - {%tags%} -</body> -</html>
\ No newline at end of file @@ -0,0 +1,88 @@ +// Should be compiled to binary to be used as CGI script +package main + +import ( + "fmt" + "html" + "io/fs" + "net/url" + "os" + "path/filepath" + "regexp" + "strings" +) + +func extractTitle(content string) string { + titleRegex := regexp.MustCompile(`(?i)<title>(.*?)</title>`) + matches := titleRegex.FindStringSubmatch(content) + if len(matches) > 1 { + return matches[1] + } + return "Без названия" +} + +func main() { + // CGI header + fmt.Println("Content-Type: text/html; charset=utf-8") + fmt.Println() + + // Получаем query string из окружения + rawQuery := os.Getenv("QUERY_STRING") + values, _ := url.ParseQuery(rawQuery) + tag := values.Get("tag") + if tag == "" { + fmt.Println("<p>Error: no tag specified</p>") + return + } + + postsDir := "../posts" + tagRegex := regexp.MustCompile(`data-tag="` + regexp.QuoteMeta(tag) + `"`) + + type Post struct { + Path string + Title string + } + + var matches []Post + + filepath.WalkDir(postsDir, func(path string, d fs.DirEntry, err error) error { + if err != nil { + return nil + } + if !d.IsDir() { + contentBytes, err := os.ReadFile(path) + if err == nil && tagRegex.Match(contentBytes) { + content := string(contentBytes) + title := extractTitle(content) + relPath := "/posts/" + filepath.Base(path) + matches = append(matches, Post{Path: relPath, Title: title}) + } + } + return nil + }) + + // Составляем <ul> + var b strings.Builder + b.WriteString("<ul>\n") + for _, post := range matches { + fmt.Fprintf(&b, "<li><a class=\"text-sm underline\" href=\"%s\">%s</a></li>\n", + html.EscapeString(post.Path), + html.EscapeString(post.Title)) + } + b.WriteString("</ul>") + + // Читаем шаблон + templateBytes, err := os.ReadFile("../templates/tags.html") + if err != nil { + fmt.Println("<p>Error: template not found</p>") + return + } + template := string(templateBytes) + + // Заменяем маркеры + output := strings.Replace(template, "<!-- %cgi.list% -->", b.String(), 1) + output = strings.Replace(output, "<!-- %cgi.tag% -->", html.EscapeString(tag), 1) + + // Отдаём результат + fmt.Print(output) +}
\ No newline at end of file |
