Formatting a feed for the Web

Another task you'll want once you've retrieved and manipulated a feed is to publish an HTML file or files from that feed. The feedhtml script does this.

Call writeFeedToPages something like so:

  1. def fh = new feedhtml()
  2. SyndFeed feed = ...;
  3. File parent = new File("/parent/directory/of/pages")
  4. def feedSiteURL = ...;
  5. def styleSheetURLs = [ "style.css", "layout.css" ]
  6. fh.writeFeedToPages(feed, 20, parent, feedSiteURL, styleSheetURLs)

The arguments are taken as follows:

  • feed Contains the feed you want to display. Presumably this is an aggregated feed created using the merge script.
  • numPerPage Defines the number of entries to display per page. For a feed containing lots of entries, rather than put them all on one page feedhtml can split them over several pages. This makes each page more manageable.
  • parent directory Specifies the directory into which the pages are generated.
  • feedSiteURL Specifies the URL for the main home page of the site. In a couple places on the page a link named "home" is generated using this URL.
  • styleSheetURLs Is a list of URL's for CSS stylesheets. Each stylesheet is linked in the page.

The HTML pages created are index.html for the first page, and then pageN.html (where 'N' is a number) for each subsequent page. These pages land in the parent directory.

The page layout uses div elements to list four boxes which your stylesheets can layout in any way you wish. These boxes are

  • div class=header Contains the title and description of this page, and is derived from the feed.
  • div class=page-navigation Contains a little navigation list for the individual pages that are generated, in case there are more than one page to generate.
  • div class=content Contains the main content of the page, namely the items from the feed.
  • div class=feedlist Contains a list of feeds from the OPML file, if there is an OPML file.