Implement config placeholders for more flexible target and host urls
This commit is contained in:
parent
6c825bcaaa
commit
373f2f2996
1 changed files with 24 additions and 9 deletions
|
@ -15,6 +15,7 @@
|
|||
(ns rss-thread-watch.core
|
||||
(:require [clojure.java.io :as io]
|
||||
[clojure.edn :as edn]
|
||||
[clojure.string :as s]
|
||||
[clojure.tools.cli :refer [parse-opts]]
|
||||
[ring.adapter.jetty :as jetty]
|
||||
[ring.middleware.params :as rp]
|
||||
|
@ -35,8 +36,8 @@
|
|||
:boards-defaults {:refresh-rate 300
|
||||
:starting-page 7
|
||||
:default-chod 94
|
||||
:target "https://api.4chan.org"
|
||||
:host "https://boards.4chan.org"
|
||||
:target "https://api.4chan.org/{board}/catalog.json"
|
||||
:host "https://boards.4chan.org/{board}/thread/{threadnum}"
|
||||
:lazy-load true}
|
||||
:boards-enabled {"/mlp/" {:lazy-load false}
|
||||
"/g/" {:starting-page 7}
|
||||
|
@ -76,17 +77,31 @@
|
|||
(with-open [r (io/reader fl)]
|
||||
(edn/read (java.io.PushbackReader. r))))))
|
||||
|
||||
(defn config-url-expand
|
||||
"Expands substitution in :target and :host fields"
|
||||
[filled-config]
|
||||
(let [boards (get filled-config :boards-enabled)
|
||||
selecting '(:target :host)
|
||||
pattern "{board}"]
|
||||
(u/fmap (fn [board confs]
|
||||
(->> (select-keys confs selecting)
|
||||
(u/fmap (fn [k v]
|
||||
(s/replace v pattern (s/replace board "/" ""))))
|
||||
(merge confs)))
|
||||
boards)))
|
||||
|
||||
(defn config-fill-board-defaults
|
||||
"Fills every enabled board with default config values"
|
||||
[config]
|
||||
(let [defaults (:boards-defaults config)]
|
||||
(dissoc (update-in config
|
||||
'(:boards-enabled)
|
||||
(fn [mp]
|
||||
(u/fmap (fn [k v]
|
||||
(assoc (u/map-apply-defaults v defaults) :name k))
|
||||
mp)))
|
||||
:boards-defaults)))
|
||||
(-> config
|
||||
(update-in '(:boards-enabled)
|
||||
(fn [mp]
|
||||
(u/fmap (fn [k v]
|
||||
(assoc (u/map-apply-defaults v defaults) :name k))
|
||||
mp)))
|
||||
(dissoc :boards-defaults)
|
||||
(config-url-expand))))
|
||||
|
||||
(defn get-some-config
|
||||
"Attempts to get config somehow,
|
||||
|
|
Loading…
Reference in a new issue