improved timestamp & added card
This commit is contained in:
parent
0cfdf7fc02
commit
7775dc88f5
6 changed files with 63 additions and 3132 deletions
3118
package-lock.json
generated
3118
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -7,7 +7,7 @@
|
||||||
<body>
|
<body>
|
||||||
<div id="masto-embed"
|
<div id="masto-embed"
|
||||||
account_name="team"
|
account_name="team"
|
||||||
xaccount_id="2"
|
coment_in_account_id="2"
|
||||||
host_url="https://social.meissa-gmbh.de">
|
host_url="https://social.meissa-gmbh.de">
|
||||||
Here the timeline will appear.
|
Here the timeline will appear.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
:dependencies
|
:dependencies
|
||||||
[[orchestra "2019.02.06-1"]
|
[[orchestra "2019.02.06-1"]
|
||||||
[hiccups "0.3.0"]
|
[hiccups "0.3.0"]
|
||||||
|
[com.andrewmcveigh/cljs-time "0.5.2"]
|
||||||
[cider/cider-nrepl "0.21.0"]]
|
[cider/cider-nrepl "0.21.0"]]
|
||||||
:dev-http {8080 "public"}
|
:dev-http {8080 "public"}
|
||||||
:builds
|
:builds
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
(:require
|
(:require
|
||||||
["mastodon-api" :as Mastodon]
|
["mastodon-api" :as Mastodon]
|
||||||
[dda.masto-embed.infra :as infra]
|
[dda.masto-embed.infra :as infra]
|
||||||
|
[cljs-time.format :as t]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[orchestra.core :refer-macros [defn-spec]]))
|
[orchestra.core :refer-macros [defn-spec]]))
|
||||||
|
|
||||||
|
@ -26,14 +27,28 @@
|
||||||
(defn mastojs->edn [response]
|
(defn mastojs->edn [response]
|
||||||
(-> response .-data infra/js->edn))
|
(-> response .-data infra/js->edn))
|
||||||
|
|
||||||
(defn masto->html [statuus]
|
(defn mastocard->html [card]
|
||||||
|
(when (some? card)
|
||||||
|
(let [{:keys [title description image url]} card]
|
||||||
|
[:div {:class "card" :url url}
|
||||||
|
(when (some? image)
|
||||||
|
[:img {:src image}])
|
||||||
|
[:h1 title]
|
||||||
|
[:p description]])))
|
||||||
|
|
||||||
|
(defn masto->html [statuses]
|
||||||
[:ul
|
[:ul
|
||||||
(map (fn [status] [:li
|
(map (fn [status]
|
||||||
|
(let [{:keys [created_at card]} status
|
||||||
|
date (t/parse created_at)]
|
||||||
|
[:li
|
||||||
[:h2
|
[:h2
|
||||||
[:a {:href (get-in status [:account :url])}
|
[:a {:href (get-in status [:account :url])}
|
||||||
(:created_at status)]]
|
(t/unparse (t/formatters :date) date)
|
||||||
|
(t/unparse (t/formatters :hour-minute-second) date)]]
|
||||||
(:content status)
|
(:content status)
|
||||||
(:card status)]) statuus)])
|
(mastocard->html card)]))
|
||||||
|
statuses)])
|
||||||
|
|
||||||
|
|
||||||
(defn-spec mastodon-client any?
|
(defn-spec mastodon-client any?
|
||||||
|
|
|
@ -72,7 +72,7 @@
|
||||||
(print account-name)
|
(print account-name)
|
||||||
(print account-id)
|
(print account-id)
|
||||||
(->> statuus
|
(->> statuus
|
||||||
(take 4)
|
(take 14)
|
||||||
(api/masto->html)
|
(api/masto->html)
|
||||||
(render-html)
|
(render-html)
|
||||||
(infra/debug)
|
(infra/debug)
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
[cljs.test :refer (deftest is)]
|
[cljs.test :refer (deftest is)]
|
||||||
[dda.masto-embed.api :as sut]))
|
[dda.masto-embed.api :as sut]))
|
||||||
|
|
||||||
(def statuus [{:mentions []
|
(def statuses [{:mentions []
|
||||||
:emojis []
|
:emojis []
|
||||||
:tags []
|
:tags []
|
||||||
:reblog
|
:reblog
|
||||||
|
@ -153,11 +153,44 @@
|
||||||
:created_at "2020-05-17T10:12:10.403Z"
|
:created_at "2020-05-17T10:12:10.403Z"
|
||||||
:spoiler_text ""}])
|
:spoiler_text ""}])
|
||||||
|
|
||||||
(deftest test-mastodon-2-html
|
(deftest test-mastodon->html
|
||||||
(is (= [:ul
|
(is (= [:ul
|
||||||
'([:li
|
'([:li
|
||||||
[:h2 [:a {:href "https://social.meissa-gmbh.de/@team"}
|
[:h2 [:a {:href "https://social.meissa-gmbh.de/@team"}
|
||||||
"2020-05-17T10:12:10.403Z"]]
|
"2020-05-17" "10:12:10"]]
|
||||||
"<p>We've a new asciicast ... </p>"
|
"<p>We've a new asciicast ... </p>"
|
||||||
[:p ]])]
|
nil])]
|
||||||
(sut/masto->html statuus))))
|
(sut/masto->html statuses))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(deftest empty-card-should-produce-empty-result
|
||||||
|
(is (= nil
|
||||||
|
(sut/mastocard->html nil))))
|
||||||
|
|
||||||
|
(def link-card {:description "A comprehensive free SSL test for your public web servers.",
|
||||||
|
:author_url "", :width 0, :type "link", :embed_url "",
|
||||||
|
:title "SSL Server Test (Powered by Qualys SSL Labs)",
|
||||||
|
:provider_name "", :url "https://www.ssllabs.com/ssltest/",
|
||||||
|
:author_name "", :image nil, :provider_url "", :height 0, :html ""})
|
||||||
|
|
||||||
|
(deftest link-card-should-show-desc-and-link
|
||||||
|
(is (= [:div {:class "card", :url "https://www.ssllabs.com/ssltest/"}
|
||||||
|
nil
|
||||||
|
[:h1 "SSL Server Test (Powered by Qualys SSL Labs)"]
|
||||||
|
[:p "A comprehensive free SSL test for your public web servers."]]
|
||||||
|
(sut/mastocard->html link-card))))
|
||||||
|
|
||||||
|
(def link-card-with-image
|
||||||
|
{:description "Cryogen's core. Contribute to DomainDrivenArchitecture/cryogen-core development by creating an account on GitHub.", :author_url "", :width 400, :type "link", :embed_url "",
|
||||||
|
:title "DomainDrivenArchitecture/cryogen-core", :provider_name "",
|
||||||
|
:url "https://github.com/DomainDrivenArchitecture/cryogen-core", :author_name "",
|
||||||
|
:image "https://cf.mastohost.com/v1/AUTH_91eb37814936490c95da7b85993cc2ff/socialmeissagmbhde/cache/preview_cards/images/000/017/635/original/5634071238f1f91f.png",
|
||||||
|
:provider_url "", :height 400, :html ""})
|
||||||
|
|
||||||
|
(deftest link-card-should-show-image-and-desc-and-link
|
||||||
|
(is (= [:div {:class "card", :url "https://github.com/DomainDrivenArchitecture/cryogen-core"}
|
||||||
|
[:img {:src "https://cf.mastohost.com/v1/AUTH_91eb37814936490c95da7b85993cc2ff/socialmeissagmbhde/cache/preview_cards/images/000/017/635/original/5634071238f1f91f.png"}]
|
||||||
|
[:h1 "DomainDrivenArchitecture/cryogen-core"]
|
||||||
|
[:p "Cryogen's core. Contribute to DomainDrivenArchitecture/cryogen-core development by creating an account on GitHub."]]
|
||||||
|
(sut/mastocard->html link-card-with-image))))
|
Loading…
Reference in a new issue