From 190ce50d172f9d2b1d2114f43fa80e92f28da03e Mon Sep 17 00:00:00 2001 From: unwox Date: Tue, 22 Oct 2024 00:01:28 +0600 Subject: improve menu code --- bin/serve.fnl | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'bin/serve.fnl') diff --git a/bin/serve.fnl b/bin/serve.fnl index a0c5fc4..f9563ec 100644 --- a/bin/serve.fnl +++ b/bin/serve.fnl @@ -295,33 +295,22 @@ "")) (fn menu-template [path extra-class] + (local item + (fn [item-path title] + [:a {:href item-path + :class (if (= path item-path) "active" "")} + title])) [:nav {:class (.. "menu" (if (str.empty? extra-class) "" (.. " " extra-class)))} - [:a {:href "/red-tea" - :class (if (= path "/red-tea") "active" "")} - "Красный чай"] - [:a {:href "/sheng-puer" - :class (if (= path "/sheng-puer") "active" "")} - "Шен пуэр"] - [:a {:href "/shou-puer" - :class (if (= path "/shou-puer") "active" "")} - "Шу пуэр"] - [:a {:href "/oolong" - :class (if (= path "/oolong") "active" "")} - "Улун"] - [:a {:href "/green-tea" - :class (if (= path "/green-tea") "active" "")} - "Зеленый чай"] - [:a {:href "/white-tea" - :class (if (= path "/white-tea") "active" "")} - "Белый чай"] - [:a {:href "/yellow-tea" - :class (if (= path "/yellow-tea") "active" "")} - "Желтый чай"] - [:a {:href "/teaware" - :class (if (= path "/teaware") "active" "")} - "Посуда"]]) + (item "/red-tea" "Красный чай") + (item "/sheng-puer" "Шен пуэр") + (item "/shou-puer" "Шу пуэр") + (item "/oolong" "Улун") + (item "/green-tea" "Зелёный чай") + (item "/white-tea" "Белый чай") + (item "/yellow-tea" "Жёлтый чай") + (item "/teaware" "Посуда")]) (fn aside-template [form path paginator] [:aside {:class "aside"} @@ -420,7 +409,7 @@ (fn root-handler [{: path : query}] (local cache-key (.. "page:" path "?" (serialize-query query))) (local cached (cache.get db cache-key)) - (if false + (if cached (values 200 {:content-type "text/html"} cached) (do (fn respond [query category] -- cgit v1.2.3