River2 Blog

News and updates about the River2 aggregator.

Monthly Archives: May 2010

Matt’s questions about River2

Matt Diaz is an incoming Studio 20 student and has been using River2. He had some questions — which I am answering here on the blog in case these come up for others.

1. He’d like to be able to organize the feed he’s subscribed to into separate streams that River2 saves into separate HTML files and pushed to Dropbox.

There is a way to do this, it works, but there’s no user interface to set it up. I use the feature on the east-village.org server, I have a stream for the East Village blogs, one for nyblogs.org and another for my own personal aggregator with the news feeds I’m interested in.

I think it’s a little too difficult right now to hack it in yourself. I need to create a UI that makes it possible to create new users for a River2 installation. Just know that it’s not too far from being real, and if you really want it, bring your laptop to the next meetup and I’ll see if I can get it to work manually.

2. He’d like to get rid of the small notice of news that right now is advertising nyblogs.org.

That’s totally cool. I could add a pref to turn it off, but in the meantime you could change the CSS for the site to shrink it down to 0 pixels. Open river.css in the River2 sub-folder of the OPML folder, and look for “caption.” That’s where you go to change the style of the caption. Just save it, and the next time the page is rendered it’ll use the new stylesheet.

3. He writes: “I was hoping you could clarify how items are organized on the River2 main page. The way I think it works is that items are displayed with the newest ones closest to the top. Then, if River2 pulls an item from a feed that has published another item recently, River2 lumps all of them together (with the newest item at the bottom), and puts the lump at the top of the main page. Does this sound right?”

That’s pretty close. Every hour River2 does a scan. For each feed it reads, it pushes all the new items from that feed onto the home page, at the top of the page. Then it checks the next feed, until it’s read all of them. It groups them this way so it’s easy to see what’s new, and then easy to associate each new item with the feed it came from.

JavaScript includes in River2

See the earlier piece for a tutorial on what JavaScript includes are and how they work.

Today there’s a new feature in River2. If you have the Dropbox feature turned on, in addition of generating a static HTML page, River2 will also generate a JavaScript include file (index.js) and an OPML subscription list (index.opml) in the same folder as the HTML file. The screen shot below illustrates:

A picture named dbfolder.gif

The OPML subscription list, index.opml, is of obvious value — it makes it possible to share your list with other users. It also backs up your list in a place that’s automatically synched with your other computers.

The JavaScript include file, index.js, file lets you include the result of the aggregator in another website. We’re going to use it as part of the nyblogs.org project to include the news in a WordPress weblog.

For an example of how it works, do a View Source on this page:

http://scripting.com/misc/includeDemo/

There are basically two moving parts — the stylesheet and the <script> that includes the .js file.

If you look in the stylesheet, you’ll see it defines styles specifically for River2. You can either copy the contents of the stylesheet, or if you have CSS skills, you can customize the look of the river when it appears in your site.

How JavaScript includes work

I’ve long felt that HTML should have an “include file” mechanism similar to the one that many programming languages have. When I lobbied for it in the early days of the web, the people at Netscape and Microsoft said they feared it would we abused. I didn’t think that was much of an argument because people were copying HTML anyway. View-source was one of the best things about the web. If you wanted to understand how something worked, it was always just a matter of looking to see how they did it.

Finally they relented, or maybe it was just an accident, a door they forgot to close, because with JavaScript they gave us the ability to incude a script within a page. And a script can generate text. So you just have to come up with a way to turn your HTML text into a script. It’s a very simple thing, even though it seems like an unnecessary step — you can automate it so it’s not a big deal.

I wanted to show the members of the Thursday evening group how this works, because we’re going to use this technique in nyblogs.org, to allow us to include the result of the aggregator inside a WordPress blog. But first a simpler example.

Create a text file on your hard disk, and call it test.html. Add this code to the file:

<html><body><script type="text/javascript" src="http://static.newsriver.org/afp/js/randomThumb.js"></script></body></html>

Save it, then drag the file’s icon onto Firefox (or whatever browser you use) and you should see an image on the page. If you click the image it’ll take you to the full version of the page. And if you wait a few minutes and refresh the page, the image will be different.

This is how the random image in the right margin on scripting.com is implemented.

I have a process on one of my servers that generates the randomThumb.js file and puts it in the same place every time. Try entering the URL of the script into the address bar of your browser.

http://static.newsriver.org/afp/js/randomThumb.js

And do a View Source.

You’ll see a “document.write” statement, and inside it — a bit of HTML. That’s the extra step I had to do to make this work. Instead of HTML code, the file contains JavaScript code, and it in turn generates the HTML we want to appear in the page. Convoluted, but it works. (This is what programmers call a klooge.)