cryogen-core/src/cryogen_core/rss.clj

36 lines
1.2 KiB
Clojure
Raw Normal View History

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]
[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
Add enclosure tag to facilitate Podcasting with Cryogen Add an enclosure tag to a post's metadata to let a podcast client to deliver your audio content. It should look like this: :enclosure [{:url "<full-url>"}] Without the brackets, you end up with NullPointerExceptions, so make sure you have that. The URL should be the full location of where the audio file is hosted (not relative), so for example: :enclosure [{:url "http://www.example.com/01_episode_IV.mp3"}] I created a bunch of markdown files with just the enclosure and info about the audiobook with the following bash snippet: find -L books -type f -iname "*mp3" | sort | while read mp3; do name=$(basename $mp3 .mp3); book=$(basename "$(dirname $mp3)"); echo "{:title \"$name\"\n:layout :post\n:tags [\"audiobooks\" \"$book\"]\n:enclosure [{:url \"http://clashthebunny.mason.ch/blog/$mp3\"}]}\n $book - $name\n==================" > md/posts/"$(date "+%Y-$name").md"; done Each book was in it's own subdirectory of books: books/Dracula/1-01-Chapter1_part01.mp3 books/Dracula/1-02-Chapter1_part02.mp3 books/Dracula/2-01-Chapter2_part01.mp3 Note that the above script requires the prefix of the episode to be "date-like". It should be fairly easy to work out a way to get your podcast up and running. Add the book names to your rss-filters array, e.g.: ["Dracula" "Pride & Prejudice"] Most podcasting clients support authentication, so just password protect those directories and you should be good to go, even if you are hosting copyrighted content.
2015-09-03 16:27:55 +00:00
(fn [{:keys [uri title content date enclosure]}]
(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
:description content
Add enclosure tag to facilitate Podcasting with Cryogen Add an enclosure tag to a post's metadata to let a podcast client to deliver your audio content. It should look like this: :enclosure [{:url "<full-url>"}] Without the brackets, you end up with NullPointerExceptions, so make sure you have that. The URL should be the full location of where the audio file is hosted (not relative), so for example: :enclosure [{:url "http://www.example.com/01_episode_IV.mp3"}] I created a bunch of markdown files with just the enclosure and info about the audiobook with the following bash snippet: find -L books -type f -iname "*mp3" | sort | while read mp3; do name=$(basename $mp3 .mp3); book=$(basename "$(dirname $mp3)"); echo "{:title \"$name\"\n:layout :post\n:tags [\"audiobooks\" \"$book\"]\n:enclosure [{:url \"http://clashthebunny.mason.ch/blog/$mp3\"}]}\n $book - $name\n==================" > md/posts/"$(date "+%Y-$name").md"; done Each book was in it's own subdirectory of books: books/Dracula/1-01-Chapter1_part01.mp3 books/Dracula/1-02-Chapter1_part02.mp3 books/Dracula/2-01-Chapter2_part01.mp3 Note that the above script requires the prefix of the episode to be "date-like". It should be fairly easy to work out a way to get your podcast up and running. Add the book names to your rss-filters array, e.g.: ["Dracula" "Pride & Prejudice"] Most podcasting clients support authentication, so just password protect those directories and you should be good to go, even if you are hosting copyrighted content.
2015-09-03 16:27:55 +00:00
:enclosure enclosure
: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)
:lastBuildDate (Date.)})
(posts-to-items (:site-url config) posts)))
(defn make-filtered-channels [{:keys [rss-filters blog-prefix] :as config} posts-by-tag]
(doseq [filter rss-filters]
(let [uri (path "/" blog-prefix (str (name filter) ".xml"))]
(println "\t-->" (cyan uri))
(create-file uri (make-channel config (get posts-by-tag filter))))))