diff options
| author | unwox <me@unwox.com> | 2025-03-05 19:53:39 +0600 |
|---|---|---|
| committer | unwox <me@unwox.com> | 2025-03-05 20:26:57 +0600 |
| commit | 685f9d7ec664a3e7638f878707496db58ee1665b (patch) | |
| tree | 2c2d77addbf26375af4837a9ad927ed18b122fe0 /bin | |
| parent | 8eb33976570748b67c5e45846b21d063a3bfc355 (diff) | |
str->libstr
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/serve.fnl | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/bin/serve.fnl b/bin/serve.fnl index 18909a9..8b43d81 100644 --- a/bin/serve.fnl +++ b/bin/serve.fnl @@ -10,7 +10,7 @@ (local libhtml (require :lib.html)) (local math (require :math)) (local spellfix (require :lib.spellfix)) -(local str (require :lib.string)) +(local libstr (require :lib.string)) (local synonyms (require :lib.synonyms)) (local texts (require :texts)) (local {: must} (require :lib.utils)) @@ -41,7 +41,7 @@ (fn sanitize-input [input] (if input - (str.trim (input:gsub "[=()<>']" "") " ") + (libstr.trim (input:gsub "[=()<>']" "") " ") nil)) (fn query-string [query key] @@ -94,7 +94,7 @@ (fn form->path [page form] (.. "?page=" (tostring page) - (if (not (str.empty? form.query)) + (if (not (libstr.empty? form.query)) (.. "&query=" form.query) "") (if (< 0 (# form.tags)) @@ -105,7 +105,7 @@ form.tags)) "&")) "") - (if (not (str.empty? form.site)) + (if (not (libstr.empty? form.site)) (.. "&site=" form.site) "") (if (and form.min-price (< 0 form.min-price)) @@ -231,7 +231,7 @@ (when (and query (< 0 (# query))) (table.insert where-conds "search.title MATCH ?") (table.insert query-args (synonyms.replace query))) - (when (not (str.empty? site)) + (when (not (libstr.empty? site)) (table.insert where-conds "products.site = ?") (table.insert query-args site)) (when (and min-price (< 0 min-price)) @@ -319,8 +319,8 @@ LIMIT 24 OFFSET ?" where-sql sort-sql) (array.concat query-args [(* (- page 1) 24)]))) :total (if (< 0 (# total)) - (. total 1 1) - 0)}) + (. total 1 1) + 0)}) (fn site-name-template [name] (local module (require (.. "parser." name))) @@ -341,14 +341,14 @@ (libhtml.unescape product.title) "</div>")]] [:div {:class "price"} - (if product.price (.. (str.format-price product.price) "₽") "") + (if product.price (.. (libstr.format-price product.price) "₽") "") (if (< 0 product.weight) [:NO-ESCAPE (.. "за " product.weight " гр.")] "") (if (and (< 1 product.weight) product.price-per (< 0 product.price-per)) - [:NO-ESCAPE (.. "<br> (" (str.format-price product.price-per) + [:NO-ESCAPE (.. "<br> (" (libstr.format-price product.price-per) "₽ за 1 гр.)")] "")]]) @@ -396,7 +396,7 @@ [:a {:href item-path :class (if (= path item-path) "active" "")} title])) - [:nav {:class (.. "menu" (if (str.empty? extra-class) + [:nav {:class (.. "menu" (if (libstr.empty? extra-class) "" (.. " " extra-class)))} (item "/red-tea" "Красный чай") @@ -495,10 +495,10 @@ (table.unpack (map #(item-template $2) (teas-of-the-day 10)))]])]) (fn base-template [form path content aside-content] - (local title (if (str.empty? form.query) + (local title (if (libstr.empty? form.query) texts.meta-title (.. form.query " | " texts.meta-title))) - (local canonical-url (str.trim (.. "https://everytea.ru" path) "/")) + (local canonical-url (libstr.trim (.. "https://everytea.ru" path) "/")) [:html {:lang "ru-RU"} [:head {} @@ -555,13 +555,13 @@ (local {: results : total} (query-products form form.page)) (local spellfix-suggestion - (if (and (not (str.empty? form.query)) results (= 0 (# results))) + (if (and (not (libstr.empty? form.query)) results (= 0 (# results))) (cache.wrap db (.. "spellfix:" form.query) #(spellfix.guess form.query)) nil)) - (local description-key (.. (str.trim path "/") "-description")) + (local description-key (.. (libstr.trim path "/") "-description")) (local page (base-template form path [:div {} @@ -594,7 +594,7 @@ (values 200 {:content-type "text/html"} cached) (do (local form (collect-form query)) - (match (str.split path "/") + (match (libstr.split path "/") ["red-tea"] (render-listing form "Красный чай") ["sheng-puer"] (render-listing form "Шен пуэр") ["shou-puer"] (render-listing form "Шу пуэр") |
