2014-12-05 15:56:40 +00:00
|
|
|
(ns cryogen-core.rss
|
2014-12-04 16:38:48 +00:00
|
|
|
(:require [clj-rss.core :as rss]
|
2015-11-08 13:33:07 +00:00
|
|
|
[text-decoration.core :refer :all]
|
|
|
|
[cryogen-core.io :refer [create-file path]])
|
2014-12-04 16:38:48 +00:00
|
|
|
(:import java.util.Date))
|
|
|
|
|
|
|
|
|
2015-09-14 10:06:35 +00:00
|
|
|
(defn posts-to-items [^String site-url posts]
|
2014-12-04 16:38:48 +00:00
|
|
|
(map
|
2016-02-09 02:01:10 +00:00
|
|
|
(fn [{:keys [uri title content date enclosure author description]}]
|
2015-09-03 16:27:55 +00:00
|
|
|
(let [link (str (if (.endsWith site-url "/") (apply str (butlast site-url)) site-url) uri)
|
|
|
|
enclosure (if (nil? enclosure) "" enclosure)]
|
2014-12-04 16:38:48 +00:00
|
|
|
{:guid link
|
|
|
|
:link link
|
|
|
|
:title title
|
2016-02-09 02:01:10 +00:00
|
|
|
:description (or description content)
|
|
|
|
:author author
|
2015-09-03 16:27:55 +00:00
|
|
|
:enclosure enclosure
|
2015-03-11 01:29:04 +00:00
|
|
|
:pubDate date}))
|
2014-12-04 16:38:48 +00:00
|
|
|
posts))
|
|
|
|
|
|
|
|
(defn make-channel [config posts]
|
|
|
|
(apply
|
|
|
|
(partial rss/channel-xml
|
|
|
|
false
|
|
|
|
{:title (:site-title config)
|
|
|
|
:link (:site-url config)
|
|
|
|
:description (:description config)
|
2015-03-11 01:29:04 +00:00
|
|
|
:lastBuildDate (Date.)})
|
|
|
|
(posts-to-items (:site-url config) posts)))
|
2015-01-04 01:36:30 +00:00
|
|
|
|
2015-11-08 13:33:07 +00:00
|
|
|
(defn make-filtered-channels [{:keys [rss-filters blog-prefix] :as config} posts-by-tag]
|
2015-01-04 01:36:30 +00:00
|
|
|
(doseq [filter rss-filters]
|
2015-11-08 13:33:07 +00:00
|
|
|
(let [uri (path "/" blog-prefix (str (name filter) ".xml"))]
|
2015-01-04 01:36:30 +00:00
|
|
|
(println "\t-->" (cyan uri))
|
2015-11-08 13:33:07 +00:00
|
|
|
(create-file uri (make-channel config (get posts-by-tag filter))))))
|