Code Monkey home page Code Monkey logo

clj-rss's Introduction

clj-rss

A library for generating RSS feeds from Clojure

Continuous Integration status

Installation

Leiningen

Clojars Project

Usage

The channel-xml function accepts a map of tags representing a channel, followed by 0 or more maps for items (or a seq of items) and outputs an XML string. Each item must be a map of valid RSS tags.

The following characters in the content of :description and :title tags will be escaped: <, &, >, ". Both :pubDate and :lastBuildDate keys are expected to be instances of java.util.Date or one of its subclasses. These will be converted to standard RSS date strings in the resulting XML.

If you need to get the data in a structured format, use channel instead.

Examples

Creating a channel with some items:

(require '[clj-rss.core :as rss])

(rss/channel-xml {:title "Foo" :link "http://foo/bar" :description "some channel"}
                 {:title "Foo"}
                 {:title "post" :author "[email protected]"}
                 {:description "bar"})

Creating a feed from a seq of items:

(let [items '({:title "Foo"} {:title "Bar"} {:title "Baz"})]
  (rss/channel {:title "Foo" :link "http://foo/bar" :description "some channel"}
               items))

Creating items with complex tags:

(rss/channel-xml {:title "Foo" :link "http://foo/bar" :description "some channel"}
                 {:title "test"
                  :category [{:domain "http://www.foo.com/bar"} "BAZ"]})

(rss/channel-xml {:title "Foo" :link "http://foo/bar" :description "some channel"}
                 {:title "test"
                  :category [[{:domain "http://www.microsoft.com"} "MSFT"]
                             [{:domain "http://www.apple.com"} "AAPL"]]})

(channel-xml {:title "Foo" :link "http://foo/bar" :description "some channel"}
              {:title "test"
              :category ["MSFT" "AAPL"]})                             

Items can contain raw HTML if the tag is enclosed in <![CDATA[ ... ]]>:

  {:title "HTML Item"
   :description "<![CDATA[ <h1><a href='http://foo/bar'>Foo</a></h1> ]]>"}

To get the raw data structure use:

(rss/channel {:title "Foo" :link "http://foo/bar" :description "some channel"}
             {:title "test"})

Pass in false as first parameter to disable content validation:

(rss/channel-xml false {:title "Foo" :link "http://foo/bar" :description "some channel"}
                       {:title "test"
                        :category [{:domain "http://www.foo.com/bar"} "BAZ"]})

(rss/channel false {:title "Foo" :link "http://foo/bar" :description "some channel"}
                   {:title "test"})

The output XML can be validated at http://validator.w3.org/feed/#validate_by_input

For more information on valid RSS tags and their content please refer to the official RSS 2.0 specification http://cyber.law.harvard.edu/rss/rss.html

License

Copyright Yogthos 2012

Distributed under the Eclipse Public License, the same as Clojure.

clj-rss's People

Contributors

anykao avatar builtinnya avatar juxtin avatar noisesmith avatar rbxbx avatar yogthos avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.