diff options
| author | eltrac <hi@eltr.ac> | 2026-03-17 14:50:28 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-03-17 14:50:28 +0800 |
| commit | 260e604fe905b4c2e14a78843ef627639ea633e0 (patch) | |
| tree | 9a989b95656da3339d60e189996ef26cb723b688 /src | |
| parent | e19da85b729a4a0fc8316a80ccccb71411f183ce (diff) | |
feat(storage): get webmention by domain and path
Diffstat (limited to 'src')
| -rw-r--r-- | src/weepinbell/storage.clj | 17 | ||||
| -rw-r--r-- | src/weepinbell/utils.clj | 5 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/weepinbell/storage.clj b/src/weepinbell/storage.clj index f8630a4..3418bdc 100644 --- a/src/weepinbell/storage.clj +++ b/src/weepinbell/storage.clj @@ -1,6 +1,7 @@ (ns weepinbell.storage (:require [clojure.edn :as edn] [weepinbell.config :refer [get-config]] + [weepinbell.utils :refer [get-domain get-target get-path]] [clojure.java.io :as io] [clojure.string :refer [join]])) @@ -29,6 +30,12 @@ (if target #(st-pair-equal-pred source target %) #(id-equal-pred source %))) +(defn- domain-equal [domain wm] + (= domain + (-> wm get-target get-domain))) +(defn- path-equal [path wm] + (= path + (-> wm get-target get-path))) ;; end predicates (defn with-webmentions @@ -53,6 +60,16 @@ (with-webmentions #(->> % (remove pred) unload-data))))) +(defn get-wms-by-domain + ([domain] + (get-wms-by-domain domain nil)) + ([domain path] + (with-webmentions + #(cond->> % + true (filter (partial domain-equal domain)) + (some? path) (filter (partial path-equal path)) + true vec)))) + (defn first-line-empty? [path] (with-open [rdr (io/reader path)] (let [line (line-seq rdr)] diff --git a/src/weepinbell/utils.clj b/src/weepinbell/utils.clj index fe01d96..8c3a21a 100644 --- a/src/weepinbell/utils.clj +++ b/src/weepinbell/utils.clj @@ -10,7 +10,10 @@ [cheshire.core :as json])) (defn get-domain [url] - (-> (URI/create url) .getHost)) + (-> url URI/create .getHost)) + +(defn get-path [url] + (-> url URI/create .getPath)) (defn get-target [wm] (get-in wm [:webmention :target])) |
