diff options
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/fetch.fnl | 3 | ||||
| -rw-r--r-- | bin/serve.fnl | 54 |
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 |
