summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2025-03-05 19:53:39 +0600
committerunwox <me@unwox.com>2025-03-05 20:26:57 +0600
commit685f9d7ec664a3e7638f878707496db58ee1665b (patch)
tree2c2d77addbf26375af4837a9ad927ed18b122fe0
parent8eb33976570748b67c5e45846b21d063a3bfc355 (diff)
str->libstr
-rw-r--r--bin/serve.fnl30
-rw-r--r--lib/spellfix.fnl4
-rw-r--r--lib/synonyms.fnl4
3 files changed, 19 insertions, 19 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 (.. "за&nbsp;" product.weight "&nbsp;гр.")]
"")
(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)
"₽ за&nbsp;1&nbsp;гр.)")]
"")]])
@@ -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 "Шу пуэр")
diff --git a/lib/spellfix.fnl b/lib/spellfix.fnl
index 42d84a4..b075993 100644
--- a/lib/spellfix.fnl
+++ b/lib/spellfix.fnl
@@ -1,6 +1,6 @@
(import-macros {: map : filter} :lib.macro)
(local array (require :lib.array))
-(local str (require :lib.string))
+(local libstr (require :lib.string))
(local {: must} (require :lib.utils))
(local vocabulary ["агар" "агарвуд" "агат" "али" "антиквариат" "ань" "аравана"
@@ -132,7 +132,7 @@
(if (< most-similar.distance 3)
most-similar.word
token))
- (str.split string " "))
+ (libstr.split string " "))
" "))
(if (~= result string)
result
diff --git a/lib/synonyms.fnl b/lib/synonyms.fnl
index d3f314f..92530d2 100644
--- a/lib/synonyms.fnl
+++ b/lib/synonyms.fnl
@@ -1,6 +1,6 @@
(import-macros {: map} :lib.macro)
-(local str (require :lib.string))
+(local libstr (require :lib.string))
(local array (require :lib.array))
(local {: must} (require :lib.utils))
@@ -33,7 +33,7 @@
(fn replace [line]
(var results [])
- (let [words (str.split line " ")
+ (let [words (libstr.split line " ")
words-count (# words)]
(for [i 1 words-count]
(var word nil)