summaryrefslogtreecommitdiff
path: root/bin
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 /bin
parent612877d9ed884f333cc407ef2046bbb2604db3c2 (diff)
move tags from filter onto a separate page
Diffstat (limited to 'bin')
-rw-r--r--bin/fetch.fnl3
-rw-r--r--bin/serve.fnl54
2 files changed, 34 insertions, 23 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