From 76cd096f70c9fd5b6dabab1685f97f32449f2ff5 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Thu, 11 Apr 2024 14:29:01 +0300 Subject: [PATCH] Add the lazy loading for articles on the index page. --- src/main/blog/handlers.cljs | 4 ++-- src/main/blog/helpers.cljs | 6 ++++-- views/article_full.hbs | 1 + views/partials/article_briefly.hbs | 10 ++++++---- views/partials/article_full.hbs | 15 +++++++++++++++ 5 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 views/article_full.hbs create mode 100644 views/partials/article_full.hbs diff --git a/src/main/blog/handlers.cljs b/src/main/blog/handlers.cljs index 2139893..59fe555 100644 --- a/src/main/blog/handlers.cljs +++ b/src/main/blog/handlers.cljs @@ -10,7 +10,7 @@ id (.-id (.-params req))] (go (try - (let [articles ( {:articles articles} @@ -49,7 +49,7 @@ (res/send (ex-message "404"))) (do (res/status 200) - (.render res "article_briefly" + (.render res "article_full" (-> {:article article :layout false} (cljs.core/clj->js)))))) (catch js/Error err diff --git a/src/main/blog/helpers.cljs b/src/main/blog/helpers.cljs index 468fca9..c08d17e 100644 --- a/src/main/blog/helpers.cljs +++ b/src/main/blog/helpers.cljs @@ -4,8 +4,10 @@ (defn truncatestring-factory [] (fn [text limit] - (-> (. text substring 0 limit) - (str "...")))) + (if (> (. text -length) limit) + (-> (. text substring 0 limit) + (str "...")) + text))) (defn full-timestamp-factory [] diff --git a/views/article_full.hbs b/views/article_full.hbs new file mode 100644 index 0000000..ea59663 --- /dev/null +++ b/views/article_full.hbs @@ -0,0 +1 @@ +{{> article_full article=article }} diff --git a/views/partials/article_briefly.hbs b/views/partials/article_briefly.hbs index fe29253..20f2219 100644 --- a/views/partials/article_briefly.hbs +++ b/views/partials/article_briefly.hbs @@ -1,16 +1,18 @@ -
+

{{ article.title }}

{{{ article-timestamp article.created }}}

-

{{ article.content }}

+

{{ article.content }} {{ is-brief article.content_length }}

{{ article.content }}

-
diff --git a/views/partials/article_full.hbs b/views/partials/article_full.hbs new file mode 100644 index 0000000..1b98f0e --- /dev/null +++ b/views/partials/article_full.hbs @@ -0,0 +1,15 @@ +
+
+
+

{{ article.title }}

+

{{{ article-timestamp article.created }}}

+ +

{{ truncatestring article.content 60 }}

+

{{ article.content }}

+
+
+ + +
+
+