Allow configuring 'replacements'
This commit is contained in:
parent
dfb1685569
commit
3f9cd958f5
4 changed files with 27 additions and 1 deletions
|
@ -131,10 +131,15 @@
|
|||
(exit-with-error error)
|
||||
(callback response)))))
|
||||
|
||||
(defn perform-replacements [post]
|
||||
(assoc post :text (reduce-kv string/replace (:text post) (:replacements mastodon-config)))
|
||||
)
|
||||
|
||||
(defn post-items [last-post-time items]
|
||||
(doseq [{:keys [text media-links]} (->> items
|
||||
(remove #(blocked-content? (:text %)))
|
||||
(filter #(> (:created-at %) last-post-time)))]
|
||||
(filter #(> (:created-at %) last-post-time))
|
||||
(map perform-replacements))]
|
||||
(if media-links
|
||||
(post-status-with-images text media-links)
|
||||
(when-not (:media-only? mastodon-config)
|
||||
|
|
|
@ -26,6 +26,12 @@
|
|||
(:text (core/parse-tweet (readfile "testdata/twitter/normal-tweet.edn")))
|
||||
)))
|
||||
|
||||
(deftest test-replacements
|
||||
(is (=
|
||||
"💠 Check out what has been going on during March in the world of @ReproBuilds! 💠 https://t.co/k6NsSO115z @opensuse@fosstodon.org @conservancy@mastodon.technology @PrototypeFund@mastodon.social @debian@fosstodon.org "
|
||||
(:text (core/perform-replacements (core/parse-tweet (readfile "testdata/twitter/tweet-mentions.edn"))))
|
||||
)))
|
||||
|
||||
(cljs.test/run-tests)
|
||||
|
||||
; Don't run core's -main when testing
|
||||
|
|
14
test.edn
14
test.edn
|
@ -51,5 +51,19 @@
|
|||
;; optional keyword filter regexes
|
||||
;; any posts not matching the regexes will be filtered out
|
||||
:keyword-filters [".*clojure.*"]
|
||||
;; optional replacements
|
||||
:replacements {"@openSUSE " "@opensuse@fosstodon.org ",
|
||||
"@archlinux " "",
|
||||
"@lolamby " "",
|
||||
"@conservancy " "@conservancy@mastodon.technology ",
|
||||
"@prototypefund " "@PrototypeFund@mastodon.social ",
|
||||
"@coreboot_org " "",
|
||||
"@OpenTechFund " "",
|
||||
"@OpenWrtSummit " "",
|
||||
"@OpenMirage " "",
|
||||
"@debian " "@debian@fosstodon.org ",
|
||||
"@nixos_org " "",
|
||||
"@lwnnet " "",
|
||||
"@guixhpc" ""}
|
||||
;; Replace Twitter links by Nitter
|
||||
:nitter-urls? false}}
|
||||
|
|
1
testdata/twitter/tweet-mentions.edn
vendored
Normal file
1
testdata/twitter/tweet-mentions.edn
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in a new issue