Matt Drudge is my hero. He started
The Drudge Report while working the graveyard shift at 7-11. He was at the store when the newspapers first arrived and most of the world was asleep. He was able to parlay that
first access to the news into creating one of the most popular sites on the internet. Read his book
Drudge Manifesto if you wish to learn more about his rise to fame.
Unlike Matt Drudge, I have no desire to get up super early and go through endless newspapers to create a hand-edited HTML page of my favorite links. Fortunately for me, we now have RSS feeds. This article will mix the
ASP.NET article of the day RSS feed with the Drudge look and feel to create the
ASP.NET Report.
Reverse Engineer the Drudge Report
The Drudge Report is basically a 3 column layout with an image logo and a top story link. The layout will vary over time, but that is the usual template. For the 3 column news look, we will use the
asp:DataList control.
Drudge Font and Image
The logo was created using the Impact font at 100 points and Italic. In PhotoShop, under Blending Options (right mouse click Text layer), add a Drop Shadow. Play with the color, width and direction of the shadow.
Drudge uses a large upper-case Arial font for the top story and Courier for the 3-column stories. All links are black.
body
{
font-family: "Courier New", Courier, monospaced;
font-size: 10pt;
font-weight: bold;
color: #000;
background-color: #fff;
}
#headerDIV
{
text-align: center;
}
#topstoryDIV
{
font-size:32pt;
font-weight:bold;
font-family: Arial, Verdana, Helvetica;
}
a:link, a:active, a:visited {
color:#000;
text-decoration:underline;
line-height:1.2;
}
The Code
The RSS feed is loaded into an XmlDocument. The first story in the RSS feed will be designated the
top story. The rest of the stories will be loaded into a DataTable which is binded to the asp:DataList.
Since ASP.NET code tends not to be photogenic, I've hard-coded links to some of my vacation photos for the top image. To mix it up a little, it will change depending upon the day of the week.
DataTable dt = new DataTable();
dt.Columns.Add("title", Type.GetType("System.String"));
dt.Columns.Add("link", Type.GetType("System.String"));
// ASP.NET Article of the Day
string rssURL = "http://asp.net/community/articles/rss.ashx";
XmlDocument doc = new XmlDocument();
doc.XmlResolver = null;
doc.Load(rssURL);
// display a different image based upon day of week
int dayOfWeek = (int)DateTime.Now.DayOfWeek;
switch (dayOfWeek)
{
case 0:
imgHeader.ImageUrl = "http://criticalmas.smugmug.com/photos/117793421-S.jpg";
break;
case 1:
imgHeader.ImageUrl = "http://criticalmas.smugmug.com/photos/118708221-S.jpg";
break;
case 2:
imgHeader.ImageUrl = "http://criticalmas.smugmug.com/photos/95113678-S.jpg";
break;
case 3:
imgHeader.ImageUrl = "http://criticalmas.smugmug.com/photos/91872258-S.jpg";
break;
case 4:
imgHeader.ImageUrl = "http://criticalmas.smugmug.com/photos/91842649-S.jpg";
break;
case 5:
imgHeader.ImageUrl = "http://criticalmas.smugmug.com/photos/79938653-S.jpg";
break;
default:
imgHeader.ImageUrl = "http://criticalmas.smugmug.com/photos/92103181-S.jpg";
break;
}
XmlNode oNode = doc.DocumentElement;
XmlNodeList oNodeList = oNode.SelectNodes("channel/item");
for (int itemCount = 0; itemCount < oNodeList.Count; itemCount++)
{
string title = oNodeList[itemCount].SelectSingleNode("title").InnerText;
string link = oNodeList[itemCount].SelectSingleNode("link").InnerText;
if (itemCount == 0)
{
// top story
hypTopStory.Text = title.ToUpper();
hypTopStory.NavigateUrl = link;
}
else
{
DataRow dr = dt.NewRow();
dr["title"] = title;
dr["link"] = link;
dt.Rows.Add(dr);
}
}
dlStories.DataSource = dt;
dlStories.DataBind();
The ASP.NET Page
<form id="form1" runat="server">
<div id="parentDIV">
<p><a href="/">Return to Digital Colony</a></p>
<div id="headerDIV" >
<asp:Image ID="imgHeader" runat="server" Width="400" Height="300" BorderWidth="1" />
<div id="topstoryDIV"><asp:HyperLink ID="hypTopStory" runat="server" /></div>
<img src="aspnet-report.gif" width="716" height="137" alt="ASP.NET Report" />
</div>
<div id="storiesDIV">
<asp:DataList ID="dlStories" runat="server" RepeatColumns="3" Width="100%" CellPadding="5">
<ItemTemplate>
<a href="<%# Eval("link") %>"><%# Eval("title") %></a>
<hr />
</ItemTemplate>
</asp:DataList>
</div>
</div>
</form>
Caching
When pulling RSS feeds, it is wise to be considerate of the bandwidth of your host site. Don't pull a fresh feed with every Page Load. Add an
OutputCache directive to your page. For the ASP.NET Report example, I know that this feed updates daily, so I can set the Duration to 86400 which is the number of seconds in one day.
<%@ OutputCache Duration="86400" VaryByParam="none" %>
Working Demo
Visit my
ASP.NET Report web page.
Better Than Drudge
Unlike The Drudge Report which uses awful HTML, our ASP.NET version is both XHTML and CSS compliant. It also validates under
Section 508.
Your Drudge Report
If you create your own version using a different RSS feed, share it by adding a comment with a link to your page.
UPDATE JULY 2007: Microsoft moved the URL to the ASP.NET RSS feed and now restricts it to 10 articles. This makes it look silly in the Drudge format, but at least it working again. An ideal number of posts in an RSS feed for the Drudge look would be around 40.
Labels: ASP.NET, Csharp, DataList, Drudge, RSS