Here's how you move to Subtext while keeping your old feed - with a twist: My old feed is the same as the new but it is prefixed in every post with the message:
"The feed for Techie.notepad has moved! Please update your aggregator to this url: http://blog.noop.se/rss.aspx"
Scenario:
I am moving my blog from one blog engine to another. Not that I fantasize that my blog has that many readers, but call me vain, I'd like to keep my old feed with a forward to the new one.
dasBlog published my blogs feed at this url: http://blog.noop.se/SyndicationService.asmx/GetRss
Subtext publishes it here: http://blog.noop.se/rss.aspx
Solution:
- Configure a handler to listen to your old url.
- Create the handler as an inheritance of the one used by Subtext with a slight modification.
- Modify each post body in the handler to prepend a message informing subscribers your feed has moved.
Configure Handler
This is realy straight forward. All you need to do is tell your Subtext web site in the web.config that you want all requests to your old feel url to be taken care of by your new handler. This is what goes into the web.config <HttpHandlers> section:
<HttpHandler pattern="/SyndicationService.asmx/GetRss"
type="Dotway.Subtext.Framework.Syndication.LegacyRssFeedHandler, Dotway.Subtext"
handlerType="Direct"
UseBasicAuthentication="true"/>
Create the handler
The Handler that creates rss feeds in Subtext is easily subclassed like so:
public class LegacyRssFeedHandler : RssHandler
{
}
RssHandler inherits BaseSyndicationHandler<Entry> which implements IHttpHandler. The method that gets called by the web site is ProcessRequest(System.Web.HttpContext context) which will take the httpContext and produce a suitable response to the request. But this bit was just for curiosity.
All you really need to do is call your own rss writer by overriding the SyndicationWriter property:
BaseSyndicationWriter<Entry> writer;
protected override BaseSyndicationWriter SyndicationWriter
{
get
{
if (writer == null)
{
writer = new LegacyRssWriter(Entries.GetMainSyndicationEntries(CurrentBlog.ItemCount),
PublishDateOfLastFeedItemReceived,
UseDeltaEncoding);
}
return writer;
}
}
Modify all posts on the old feed uri
This means you now have to create your own custom RssWriter. Easiest way to do this is to implement the LegacyRssWriter by subclassing the Subtext RssWriter. This in turn inherits BaseRssWriter<Entry>.
There is again only one override you need to be concerned with and it is the GetBodyFromItem(Entry item) method. Use a simple override and prepend your body string message with a custom informatory message. I put my message in the resources and it is a static message - same for all posts.
public class LegacyRssWriter : RssWriter
{
protected override string GetBodyFromItem(Entry item)
{
return item.SyndicateDescriptionOnly ? BodyWithRedirectLink(item.Description) : BodyWithRedirectLink(item.Body); //use desc or full post
}
private string BodyWithRedirectLink(string body)
{
return string.Concat(Properties.Settings.Default.MessageToPrepend, body);
}
}
Now I have two functioning feeds: http://blog.noop.se/SyndicationService.asmx/GetRss and http://blog.noop.se/rss.aspx which are identical in content with the small addition that my old url will inform any potential readers to move to the new feed. Also I no longer offer up any links to subscribe to my legacy feed...
Cheers,
/Magnus
Technorati Tags:
blogging,
Subtext
posted @ Wednesday, August 20, 2008 2:29 PM