From 7b7fa19bd92422ab9a2544599a1deb1360a19a25 Mon Sep 17 00:00:00 2001 From: niquola Date: Wed, 30 Aug 2023 21:14:53 +0100 Subject: [PATCH] stylofixes --- src/zd/core.clj | 8 +++++++ src/zd/view/menu.clj | 9 +++++-- src/zd/view/timeline.clj | 51 ++++++++++++++++++++++++---------------- zrc/zd.edn | 4 ++++ 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/src/zd/core.clj b/src/zd/core.clj index 2e158d5..c1b6d64 100644 --- a/src/zd/core.clj +++ b/src/zd/core.clj @@ -169,6 +169,13 @@ {:status 200 :body (str (store/parent-name docname))})) +(defmethod zen/op 'zd/re-validate + [ztx _cfg _req & opts] + (store/re-validate ztx) + {:status 301 + :headers {"Location" "/errors" + "Cache-Control" "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"}}) + (defmethod zen/start 'zd/zendoc [ztx config & opts] @@ -200,6 +207,7 @@ (def ztx (start)) + (stop ztx) (:zd/backlinks @ztx) diff --git a/src/zd/view/menu.clj b/src/zd/view/menu.clj index b8dea5b..5511814 100644 --- a/src/zd/view/menu.clj +++ b/src/zd/view/menu.clj @@ -26,9 +26,14 @@ [:div "Search"]] (let [cnt (count (or (store/errors ztx) []))] - (when (> cnt 0) + (if (> cnt 0) [:div#errors-link {:class (c :flex [:py 1.5] [:space-x 2] :items-center [:text :red-500])} - [:div {:class (c :flex-1)} (utils/menu-link ztx 'errors)] [:b#errors-count {:class (c :text-sm)} cnt]])) + [:div {:class (c :flex-1)} (utils/menu-link ztx 'errors)] [:b#errors-count {:class (c :text-sm)} cnt]] + [:form {:method "POST" + :class (c [:py 0] :flex :items-center [:space-x 2] {:margin-block-end 0 :font-size "inherited"}) + :action "/_revalidate"} + [:div {:class utils/menu-icon-c} [:i.fa-solid.fa-check]] + [:button {:class (c [:py 1] :text-base)} "Validate"]])) [:a {:class utils/menu-link-c :href "/git"} [:div {:class utils/menu-icon-c} [:i.fa-solid.fa-timeline]] diff --git a/src/zd/view/timeline.clj b/src/zd/view/timeline.clj index 54477d0..ddd3da4 100644 --- a/src/zd/view/timeline.clj +++ b/src/zd/view/timeline.clj @@ -6,6 +6,14 @@ [zd.view.utils :as utils :refer [btn-c]] [clojure.string :as str])) +(defn file-to-link [ztx f] + (when (str/starts-with? f "docs/") + (utils/symbol-link ztx + (-> (str/replace f #"^docs/" "") + (str/replace #"\.zd$" "") + (str/replace #"/" ".") + (symbol))))) + (defn changes-view [ztx changes] [:form {:action "/git" :method "POST"} [:div {:class (c :font-bold :text-lg :border-b :flex [:space-x 4] [:py 0.5] :divide-y)} @@ -22,7 +30,8 @@ (get {:deleted [:i.fa-solid.fa-trash] :new [:i.fa-solid.fa-square-plus] :modified [:i.fa-solid.fa-pen-to-square]} m (str m))] - [:div f]])))] + [:div f] + (file-to-link ztx f)])))] [:div {:class (c [:my 2] [:py 2] :border-t)} [:button {:class btn-c} "Commit"]]]) @@ -30,25 +39,27 @@ [:div {:class (c [:mt 4])} [:div {:class (c :font-bold :text-lg :border-b)} "History"] (->> history - (map (fn [{date :date commits :commits}] - [:details {:class (c [:my 4])} - [:summary {:class (c :block :border-b [:pt 1] [:pb 0.5] :font-bold [:text :gray-600] :cursor-pointer [:hover [:bg :gray-100]])} date] - [:div - (->> commits - (map (fn [com] - [:details {:class (c [:py 1])} - [:summary {:class (c :border-b [:space-x 4] :cursor-pointer [:hover [:bg :gray-100]])} - [:span {:class (c [:w 8] [:text :gray-600])} - (last (str/split (:time com) #"\s"))] - [:span (:user com)] - [:span "-"] - [:span (:comment com)]] - [:div {:class (c [:pt 2])} - (->> (:files com) - (map (fn [f] - [:div {:class (c [:ml 4] [:py 0.5] :flex :items-center [:space-x 2])} - [:i.fa-regular.fa-file {:class (str (c [:gray-400]))}] - [:space f]])))]])))]])))]) + (map-indexed + (fn [i {date :date commits :commits}] + [:details {:class (c [:my 4]) :open (> 10 i)} + [:summary {:class (c :block :border-b [:pt 1] [:pb 0.5] :font-bold [:text :gray-600] :cursor-pointer [:hover [:bg :gray-100]])} date] + [:div + (->> commits + (map-indexed (fn [j com] + [:details {:class (c [:py 0]) :open (> 3 i)} + [:summary {:class (c [:px 2] [:bg :gray-100] :border-b [:space-x 4] :cursor-pointer [:hover [:bg :gray-100]])} + [:span {:class (c [:w 8] [:text :gray-600])} + (last (str/split (:time com) #"\s"))] + [:span (:user com)] + [:span "-"] + [:span (:comment com)]] + [:div {:class (c [:pt 2] [:pb 4] :border-b)} + (->> (:files com) + (map (fn [f] + [:div {:class (c [:ml 4] [:py 0.5] :flex :items-center [:space-x 2])} + [:i.fa-regular.fa-file {:class (str (c [:gray-400]))}] + [:space f] + (file-to-link ztx f)])))]])))]])))]) (defn view [ztx {changes :changes history :history}] [:div {:class (c [:w 200])} diff --git a/zrc/zd.edn b/zrc/zd.edn index 82ce3b9..6ad8509 100644 --- a/zrc/zd.edn +++ b/zrc/zd.edn @@ -101,6 +101,9 @@ search-page {:zen/tags #{zen-web/op zen/op}} + re-validate + {:zen/tags #{zen-web/op zen/op}} + api {:zen/tags #{zen-web/api} :engine zen-web/routemap @@ -108,6 +111,7 @@ ;; :mw [zen-web/defaults] "_errors" {:GET check-errors} "_search" {:GET search-page} + "_revalidate" {:POST re-validate} "git" {:GET git-changes :POST git-commit} "new" {:GET new-doc