From 9a96deccb991e10454c2f72c5ed48cbd0c139556 Mon Sep 17 00:00:00 2001 From: Felisp Date: Tue, 10 Sep 2024 19:59:29 +0200 Subject: [PATCH] Add option to specify custom filename for feed --- project.clj | 2 +- res/ExampleConfig-documented.edn | 3 ++- src/rss_thread_watch/config.clj | 5 ++++- src/rss_thread_watch/feed_generator.clj | 19 +++++++++++-------- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/project.clj b/project.clj index 9208f29..2ecf576 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject rss-thread-watch "0.4.6-SNAPSHOT" +(defproject rss-thread-watch "0.4.7-SNAPSHOT" :description "RSS based thread watcher" :url "http://example.com/FIXME" :license {:name "AGPL-3.0-only" diff --git a/res/ExampleConfig-documented.edn b/res/ExampleConfig-documented.edn index 8c1111f..c0ed0e3 100644 --- a/res/ExampleConfig-documented.edn +++ b/res/ExampleConfig-documented.edn @@ -3,7 +3,8 @@ ;; Message displayed when requested board is not enabled :board-disabled-message "This board is not enabled for feed generation.\n\nYou can contact me here: [contact]" ;; :enable-board-listing true ;Whether to show list of enabled boards in /boards UNIMPLEMENTED - + ;; The watcher feed will be served by this url, everything else will be 404 + :served-filename "/feed" ;; This map defines default values for all enabled boards, if you wish for some board ;; to use different values, specify them bellow in :borads-enabled :boards-defaults { diff --git a/src/rss_thread_watch/config.clj b/src/rss_thread_watch/config.clj index f6f867b..0dc69ef 100644 --- a/src/rss_thread_watch/config.clj +++ b/src/rss_thread_watch/config.clj @@ -6,7 +6,9 @@ [rss-thread-watch.utils :as u]) (:gen-class)) -(def VERSION "0.4.6") +;; Verification TODO: check if all required keys are included so we don't get nils + +(def VERSION "0.4.7") (def GLOBAL-CONFIG "Global config with defaults for missing entires" @@ -20,6 +22,7 @@ {:port 6969 :default-board "/mlp/" :enable-board-listing true + :served-filename "/feed" :board-disabled-message "This board is not enabled for feed generation.\n\nYou can contact me here: [contact] and I may enable it for you" :boards-defaults {:refresh-rate 300 :starting-page 7 diff --git a/src/rss_thread_watch/feed_generator.clj b/src/rss_thread_watch/feed_generator.clj index 42bf686..ee4f168 100644 --- a/src/rss_thread_watch/feed_generator.clj +++ b/src/rss_thread_watch/feed_generator.clj @@ -99,9 +99,11 @@ "Generates feed from matching items" [query-vec chod-treshold repeat? cache board-config] (let [items (filter-chod-posts query-vec chod-treshold repeat? cache) + served-filename (get @conf/GLOBAL-CONFIG :served-filename) head {:title (str "RSS Thread watcher v" conf/VERSION) - :link "https://tools.treebrary.org/thread-watcher/feed.xml" - :feed-url "https://tools.treebrary.org/thread-watcher/feed.xml" + ;; TODO: hardcoded homepage + :link (str "https://tools.treebrary.org/thread-watcher/" served-filename) + :feed-url (str "https://tools.treebrary.org/thread-watcher/" served-filename) :description "RSS based thread watcher"} body (map #(thread-to-rss-item %1 @@ -116,7 +118,8 @@ rss-thread-watch.watcher.chod-threads-cache rss-thread-watch.config.GLOBAL-CONFIG" ;TODO: Update if it really reads from there anymore [rqst] - (try (let [{{chod "chod" + (try (let [served-filename (get @conf/GLOBAL-CONFIG :served-filename) + {{chod "chod" board "board" repeat? "repeat" :or {chod "94" board (get @conf/GLOBAL-CONFIG :default-board) @@ -140,18 +143,18 @@ (println "\n\nRCVD: " rqst) ;; (println rqst) ;; ====== Errors ===== - ;; Something other than feed.xml requested - (when-not (s/ends-with? uri "feed.xml") + ;; Something other than $served-filename requested + (when-not (s/ends-with? uri served-filename) (throw (ex-info "404" {:status 404 :header {"Content-Type" "text/plain"} - :body "404 This server has nothing but /feed.xml"}))) + :body (str "404 This server has nothing but " served-filename)}))) (when-not (contains? @boards-enabled-cache board) (throw (ex-info "403" {:status 403 :header {"Content-Type" "text/plain"} :body (get @conf/GLOBAL-CONFIG :board-disabled-message)}))) ;; No url params -> we redirect to documentation about params (when (empty? prms) - (throw (ex-info "302" + (throw (ex-info "302" ;TODO: remove hardcode redirect (response/redirect "https://git.treebrary.org/Treebrary.org/rss-thread-watcher#headline-4")))) ;; No querry specified - don't know what to search for @@ -159,7 +162,7 @@ (throw (ex-info "400" {:status 400 :header {"Content-Type" "text/plain"} :body (str "400 You MUST specify query with one OR more'q=searchTerm' url parameter(s)\n\n\n" - "Exmple: '/feed.xml?q=pony&q=IWTCIRD' will show in your feed all threads with 'pony' or 'IWTCIRD'" + "Exmple: '" served-filename "?q=pony&q=IWTCIRD' will show in your feed all threads with 'pony' or 'IWTCIRD'" " in their title that are about to die.")}))) ;; Whether cache has been generated yet (when (empty? cache)