Compare commits

...

6 commits

Author SHA1 Message Date
bom
a24ee62d16 Split mode functions into raw and rendered
If we want to create different html to the default the raw functions can be used to build html from the reply itself.
2024-11-15 11:02:06 +01:00
bom
f0aa2633a7 General cleanup
imports, deprecations & versions
2024-11-15 10:54:30 +01:00
93aae1f7d6 [Skip-CI] Fix mastodon add website link 2024-08-06 15:01:00 +02:00
795d5397e7 [Skip-CI] Fix mastodon add website link 2024-08-06 14:52:34 +02:00
4a83bee3fc [Skip-CI] Fix mastodon add website link 2024-08-06 14:43:15 +02:00
e681d7be23 bump version to: 1.0.2-SNAPSHOT 2024-05-31 11:06:51 +02:00
8 changed files with 41 additions and 44 deletions

View file

@ -1,8 +1,8 @@
# dda-masto-embed
![build](https://github.com/DomainDrivenArchitecture/dda-masto-embed/workflows/build-it/badge.svg)
![build](https://gitlab.com/domaindrivenarchitecture/dda-masto-embed/-/commits/master) | [![pipeline status](https://gitlab.com/domaindrivenarchitecture/dda-masto-embed/badges/main/pipeline.svg)](https://gitlab.com/domaindrivenarchitecture/dda-masto-embed/-/commits/master)
[<img src="https://meissa-gmbh.de/img/community/Mastodon_Logotype.svg" width=20 alt="team@social.meissa-gmbh.de"> team@social.meissa-gmbh.de](https://social.meissa-gmbh.de/@team) | [Website & Blog](https://domaindrivenarchitecture.org)
[<img src="https://domaindrivenarchitecture.org/img/delta-chat.svg" width=20 alt="DeltaChat"> chat over e-mail](mailto:buero@meissa-gmbh.de?subject=community-chat) | [<img src="https://meissa.de/images/parts/contact/mastodon36_hue9b2464f10b18e134322af482b9c915e_5501_filter_14705073121015236177.png" width=20 alt="M"> meissa@social.meissa-gmbh.de](https://social.meissa-gmbh.de/@meissa) | [Blog](https://domaindrivenarchitecture.org) | [Website](https://meissa.de)
## In brief
@ -137,6 +137,6 @@ Mirrors are:
## License
Copyright © 2023 meissa GmbH
Copyright © 2024 meissa GmbH
Licensed under the [Apache License, Version 2.0](LICENSE) (the "License")
Pls. find licenses of our subcomponents [here](doc/SUBCOMPONENT_LICENSE)

View file

@ -9,7 +9,7 @@ name = 'dda-masto-embed'
MODULE = 'not-used'
PROJECT_ROOT_PATH = '.'
version = "1.0.1"
version = "1.0.2-dev"
@init
def initialize(project):

View file

@ -1,7 +1,7 @@
{
"name": "dda-masto-embed",
"author": "meissa GmbH",
"version": "1.0.1",
"version": "1.0.2-SNAPSHOT",
"homepage": "https://github.com/DomainDrivenArchitecture/dda-masto-embed",
"repository": "https://github.com/DomainDrivenArchitecture/dda-masto-embed",
"license": "Apache-2.0",

View file

@ -8,7 +8,7 @@
[hiccups "0.3.0"]
[org.clj-commons/hickory "0.7.4"]
[com.andrewmcveigh/cljs-time "0.5.2"]
[org.domaindrivenarchitecture/c4k-common-cljs "6.2.3"]]
[org.domaindrivenarchitecture/c4k-common-cljs "8.0.0"]]
:dev-http {8080 "public"}
:builds
{:test {:target :node-test

View file

@ -17,7 +17,6 @@
(:require
["mastodon-api" :as Mastodon]
[dda.masto-embed.infra :as infra]
[cljs-time.format :as t]
[clojure.spec.alpha :as s]
[orchestra.core :refer-macros [defn-spec]]))

View file

@ -15,8 +15,6 @@
; limitations under the License.
(ns dda.masto-embed.infra
(:require
[cljs.core.async :refer [go]]
[cljs.core.async.interop :refer-macros [<p!]]
[clojure.pprint :as pprint :refer [pprint]]))
(defn exit-with-error [error]

View file

@ -15,12 +15,10 @@
; limitations under the License.
(ns dda.masto-embed.modes
(:require
[cljs.core.async :refer [go close! put! take! timeout chan <! >!]]
[cljs.core.async :refer [go chan <! >!]]
[cljs.core.async.interop :refer-macros [<p!]]
[hiccups.runtime :refer [render-html]]
[cljs-time.format :as t]
[dda.masto-embed.api :as api]
[dda.masto-embed.infra :as infra]
[dda.masto-embed.browser :as b]
[dda.masto-embed.to-html :as th]
))
@ -36,8 +34,7 @@
(<p! (api/get-favorited-by host-url reply-id))
api/mastojs->edn
(filter #(= account-name (:acct %)))
(empty?)
(not))))
(seq))))
out))
(defn favorited? [host-url account-name replies]
@ -64,7 +61,7 @@
first)))
out))
(defn replies-mode [host-url account-name post-id filter-favorited]
(defn replies-mode-raw [host-url account-name post-id filter-favorited]
(go
(let [replies (->
(<p! (api/get-replies host-url post-id))
@ -74,12 +71,16 @@
(->> combined
(filter #(or (not filter-favorited) (:favorited %)))
(reverse)
(map :status)
(th/masto->html "replies-mode")
(render-html)
(b/render-to-document)))))
(map :status)))))
(defn account-mode [host-url account-name]
(defn replies-mode [host-url account-name post-id filter-favorited]
(go
(->> (replies-mode-raw host-url account-name post-id filter-favorited)
(th/masto->html "replies-mode")
(render-html)
(b/render-to-document))))
(defn account-mode-raw [host-url account-name]
(go
(let [account-id (<! (find-account-id host-url account-name))
status (->
@ -88,7 +89,11 @@
(->> status
(filter #(= nil (:reblog %)))
(filter #(= nil (:in_reply_to_account_id %)))
(take 4)
(th/masto->html "account-mode")
(render-html)
(b/render-to-document)))))
(take 4)))))
(defn account-mode [host-url account-name]
(go
(->> (account-mode-raw host-url account-name)
(th/masto->html "account-mode")
(render-html)
(b/render-to-document))))

View file

@ -15,12 +15,7 @@
; limitations under the License.
(ns dda.masto-embed.to-html
(:require
[cljs.core.async :refer [go chan <! >!]]
[cljs.core.async.interop :refer-macros [<p!]]
[hiccups.runtime :refer [render-html]]
[cljs-time.format :as t]
[dda.masto-embed.api :as api]
[dda.masto-embed.infra :as infra]
[dda.masto-embed.browser :as b]
[dda.c4k-common.common :as cm]
[clojure.walk :refer [postwalk]]))
@ -43,16 +38,16 @@
(let [{:keys [username display_name avatar_static]} account
date (t/parse created_at)]
(-> html
(cm/replace-all-matching-values-by-new-value "AVATAR_URL" avatar_static)
(cm/replace-all-matching-values-by-new-value "POST_URL" url)
(cm/replace-all-matching-values-by-new-value "DISPLAY_NAME" display_name)
(cm/replace-all-matching-values-by-new-value "ACCOUNT_NAME" (str "@" username))
(cm/replace-all-matching-values-by-new-value "DATETIME" created_at)
(cm/replace-all-matching-values-by-new-value "TIME" (t/unparse (t/formatter "EEEE, dd MMMM yyyy") date)))))
(cm/replace-all-matching "AVATAR_URL" avatar_static)
(cm/replace-all-matching "POST_URL" url)
(cm/replace-all-matching "DISPLAY_NAME" display_name)
(cm/replace-all-matching "ACCOUNT_NAME" (str "@" username))
(cm/replace-all-matching "DATETIME" created_at)
(cm/replace-all-matching "TIME" (t/unparse (t/formatter "EEEE, dd MMMM yyyy") date)))))
(defn masto-content->html [html content]
(-> html
(cm/replace-all-matching-values-by-new-value "POST_TEXT" content)))
(cm/replace-all-matching "POST_TEXT" content)))
; Meant to be used in postwalk on hiccup/hickory html-representation
(defn insert-into-content [item insertion-element]
@ -88,20 +83,20 @@
html
(-> html
(insert-link-prev)
(cm/replace-all-matching-values-by-new-value "LINK_PREVIEW_URL" url)
(cm/replace-all-matching-values-by-new-value "LINK_PREVIEW_IMG_URL" image)
(cm/replace-all-matching-values-by-new-value "LINK_PREVIEW_TITLE" (str (truncate title 47) "..."))
(cm/replace-all-matching-values-by-new-value "LINK_PREVIEW_DESC" description)))))
(cm/replace-all-matching "LINK_PREVIEW_URL" url)
(cm/replace-all-matching "LINK_PREVIEW_IMG_URL" image)
(cm/replace-all-matching "LINK_PREVIEW_TITLE" (str (truncate title 47) "..."))
(cm/replace-all-matching "LINK_PREVIEW_DESC" description)))))
(defn masto-footer->html [html replies_count reblogs_count favourites_count]
(-> html
(cm/replace-all-matching-values-by-new-value "REPLIES_COUNT" replies_count)
(cm/replace-all-matching-values-by-new-value "REBLOGS_COUNT" reblogs_count)
(cm/replace-all-matching-values-by-new-value "FAVOURITES_COUNT" favourites_count)))
(cm/replace-all-matching "REPLIES_COUNT" replies_count)
(cm/replace-all-matching "REBLOGS_COUNT" reblogs_count)
(cm/replace-all-matching "FAVOURITES_COUNT" favourites_count)))
(defn insert-mode [html mode]
(-> html
(cm/replace-all-matching-values-by-new-value "section MODE" (str "section " mode))))
(cm/replace-all-matching "section MODE" (str "section " mode))))
(defn masto->html [mode statuses]
(let [html (b/post-html-hiccup)]