Add option to specify custom filename for feed

This commit is contained in:
Felisp 2024-09-10 19:59:29 +02:00
parent e871d1a6c4
commit 9a96deccb9
4 changed files with 18 additions and 11 deletions

View file

@ -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"

View file

@ -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 {

View file

@ -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

View file

@ -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)