summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2025-06-16 22:16:40 +0600
committerunwox <me@unwox.com>2025-06-16 22:16:40 +0600
commit43a3ad32f9a17b23f211f61c28e37296ac4447f9 (patch)
tree07a589e96654f81d4745609df61a635e9d724df2
parent612877d9ed884f333cc407ef2046bbb2604db3c2 (diff)
move tags from filter onto a separate page
-rw-r--r--bin/fetch.fnl3
-rw-r--r--bin/serve.fnl54
-rw-r--r--static/style.css25
-rw-r--r--texts.fnl5
4 files changed, 56 insertions, 31 deletions
diff --git a/bin/fetch.fnl b/bin/fetch.fnl
index 583b48a..bc7a827 100644
--- a/bin/fetch.fnl
+++ b/bin/fetch.fnl
@@ -60,10 +60,11 @@
CREATE TABLE IF NOT EXISTS product_tags(
product TEXT NOT NULL REFERENCES products(url),
- tag DATETIME NOT NULL REFERENCES tags(title)
+ tag TEXT NOT NULL REFERENCES tags(title)
);
CREATE UNIQUE INDEX IF NOT EXISTS product_tags_idx ON product_tags(product, tag);
+ CREATE INDEX IF NOT EXISTS product_tags_tag_idx ON product_tags(tag);
CREATE TABLE IF NOT EXISTS tags(
title TEXT NOT NULL PRIMARY KEY,
diff --git a/bin/serve.fnl b/bin/serve.fnl
index 67359fd..2959e57 100644
--- a/bin/serve.fnl
+++ b/bin/serve.fnl
@@ -185,16 +185,6 @@
(fn tracked-url [url]
(.. "/track?url=" (must (luna.http.encode-url url))))
-(fn all-tags []
- (map
- (fn [_ v] (. v 1))
- (must
- (luna.db.query
- db
- "SELECT DISTINCT tags.title FROM tags
- INNER JOIN product_tags ON product_tags.tag = tags.title
- ORDER BY creation_time" []))))
-
(fn shops-count []
(# (must (luna.db.query db
"SELECT DISTINCT site
@@ -413,7 +403,8 @@
(item "/green-tea" "Зеленый чай")
(item "/white-tea" "Белый чай")
(item "/yellow-tea" "Желтый чай")
- (item "/teaware" "Посуда")])
+ (item "/teaware" "Посуда")
+ (item "/tags" "Все категории")])
(fn aside-template [form path aside-content]
(local teaware? (array.contains form.tags "Посуда"))
@@ -433,17 +424,6 @@
;; and that doesn't work well with _G.reload
:autofocus (if luna.debug nil true)
:placeholder "Поисковый запрос"}]
- [:div {}
- [:select {:name "tags"}
- [:option {:value ""} "~ Тег ~"]
- (table.unpack
- (map
- (fn [_ tag]
- [:option {:value tag
- :selected (if (array.contains form.tags tag)
- "selected" nil)}
- tag])
- (all-tags)))]]
[:div {:class "form-range"}
[:input {:type :number :name "min-price" :min "1"
:placeholder "От ₽" :value (tostring form.min-price)}]
@@ -501,10 +481,35 @@
[:div {:class "list"}
(table.unpack (map #(item-template $2) (teas-of-the-day 10)))]])])
+(fn all-tags []
+ (must
+ (luna.db.query-assoc
+ db "SELECT count(*) AS count,
+ tag AS title
+ FROM product_tags
+ INNER JOIN products ON product_tags.product = products.url
+ WHERE products.archived = false
+ GROUP BY tag
+ ORDER BY tag ASC"
+ [])))
+
+(fn tags-template []
+ [:div {}
+ [:article {:class "description"}
+ [:h1 {} "Все категории"]]
+ [:ul {:class "tags-list"}
+ (table.unpack
+ (map (fn [_ tag]
+ [:li {}
+ [:a {:href (.. "/?tags=" tag.title)}
+ (.. tag.title " (" (tostring tag.count) ")")]])
+ (all-tags)))]])
+
(fn base-template [form path content aside-content]
(local title (if (libstr.empty? form.query)
texts.meta-title
(.. form.query " | " texts.meta-title)))
+
(local canonical-url (libstr.trim (.. "https://everytea.ru" path) "/"))
[:html {:lang "ru-RU"}
@@ -610,6 +615,11 @@
["white-tea"] (render-listing form "Белый чай")
["yellow-tea"] (render-listing form "Желтый чай")
["teaware"] (render-listing form "Посуда")
+ ["tags"] (values
+ 200 {:content-type "text/html"}
+ (.. "<!DOCTYPE html>\n"
+ (html.render (base-template form path (tags-template))
+ true)))
(where t (= 0 (# t)))
(if (form-empty? form)
(values
diff --git a/static/style.css b/static/style.css
index 771af7f..024a727 100644
--- a/static/style.css
+++ b/static/style.css
@@ -9,6 +9,16 @@ body {
line-height: 1.4;
}
+.tags-list {
+ padding-left: 0;
+ columns: 3;
+ list-style: none;
+}
+
+.tags-list {
+ list-decoration: none;
+}
+
h1, h2, h3, h4, h5, h6 {
font-weight: 900;
margin-bottom: 1rem;
@@ -189,6 +199,12 @@ footer {
margin-top: 1rem;
}
+@media screen and (max-width: 55rem) {
+ .tags-list {
+ columns: 2;
+ }
+}
+
@media screen and (max-width: 44.9rem) {
body {
margin: 1rem;
@@ -200,6 +216,7 @@ footer {
.menu-mobile {
display: flex;
+ justify-content: center;
}
.content {
@@ -288,10 +305,6 @@ footer {
.description {
margin-top: 1rem;
}
-
- ol {
- padding-left: 1.125rem;
- }
}
@media screen and (max-width: 30rem) {
@@ -300,6 +313,10 @@ footer {
height: 10rem;
width: 10rem;
}
+
+ .tags-list {
+ columns: 1;
+ }
}
@media (prefers-color-scheme: dark) {
diff --git a/texts.fnl b/texts.fnl
index 8b592cd..f9a9f9a 100644
--- a/texts.fnl
+++ b/texts.fnl
@@ -165,7 +165,4 @@
и <a href=\"/teaware?query=инструмент\">инструменты</a>
помогут красиво и аккуратно приготовить чай,
а <a href=\"/teaware?query=фигурка\">чайные фигурки</a> создадут нужную атмосферу.
- </p>")
-
- :tags-text
- (improve-typography "Все категории товаров.")}
+ </p>")}