Permalink
Browse files

Bunch of changes, forgot what

svn path=/trunk/lb/; revision=126892
  • Loading branch information...
1 parent 995d841 commit 7fc7ea5344859a3645b6b4d062023e8dd799786e @migueldeicaza migueldeicaza committed Feb 13, 2009
Showing with 145 additions and 63 deletions.
  1. BIN RSS.NET.dll
  2. +89 −37 lb.cs
  3. +15 −8 log-style.css
  4. +41 −18 template
View
BIN RSS.NET.dll
Binary file not shown.
View
126 lb.cs
@@ -29,6 +29,7 @@
using System.Web;
using System.Xml;
using System.Xml.Serialization;
+using System.Linq;
using Rss;
class DayEntry : IComparable {
@@ -318,11 +319,12 @@ string Include (string file, out string caption)
class Blog {
public Config config;
+ string template;
public DateTime pubDate = new DateTime (1, 1, 1);
string entry_template;
string analytics = "";
string comments = "";
- string archive;
+ string archive_navigator;
Hashtable category_entries = new Hashtable ();
List<DayEntry> entries = new List<DayEntry> ();
@@ -333,8 +335,9 @@ class Blog {
}
}
- public Blog (Config config)
+ public Blog (Config config, string template)
{
+ this.template = template;
this.config = config;
this.entry_template = File.OpenText (config.EntryTemplate).ReadToEnd ();
@@ -352,12 +355,50 @@ public Blog (Config config)
comments = File.OpenText (config.CommentsStub).ReadToEnd ();
}
+ GenerateArchiveNavigation ();
}
- void GenerateArchiveGadget ()
+ void GenerateArchiveNavigation ()
{
- //var x = from be in entries
- //group be by be.
+ StringBuilder ab = new StringBuilder ();
+
+ ab.Append ("<div class=\"archive\">");
+
+ var grouping = from be in entries
+ group be by be.Date.Year into years
+ orderby years.Key descending
+ select new {
+ Year = years.Key,
+ Months = from ybe in years
+ group ybe by ybe.Date.Month into monthly
+ orderby monthly.Key
+ select new { Month = monthly.Key, Entries = monthly } };
+
+ foreach (var year_group in grouping){
+ ab.Append (String.Format ("\n<br/><b>{0}</b>\n", year_group.Year));
+ int count = 0;
+ foreach (var month in year_group.Months){
+ if ((count++ % 6) == 0){
+ ab.Append ("<br/>\n");
+ }
+ DateTime year_month = new DateTime (year_group.Year, month.Month, 1);
+ string month_archive_path = String.Format ("archive/{0:yyyy}/{0:MMM}.html", year_month);
+
+ ab.Append (String.Format ("<a href=\"{1}/{2}\">{0:MMM}</a> ", year_month, config.BlogWebDirectory, month_archive_path));
+ }
+ }
+ ab.Append ("</div>");
+ archive_navigator = ab.ToString ();
+
+ foreach (var year_group in grouping){
+ foreach (var month in year_group.Months){
+ DateTime year_month = new DateTime (year_group.Year, month.Month, 1);
+ string month_archive_path = String.Format ("archive/{0:yyyy}/{0:MMM}.html", year_month);
+
+ IList month_entries = month.Entries.ToList<DayEntry> ();
+ RenderHtml (Path.Combine (LB.config.Prefix, month_archive_path), "../../", month_entries, 0, month_entries.Count, false);
+ }
+ }
}
void LoadDirectory (DirectoryInfo dir)
@@ -601,8 +642,7 @@ string GetPageNavigation (int start, int end)
return nav.ToString ();
}
- void RenderHtml (string template, string output, string blog_base, IList entries,
- int start, int end)
+ void RenderHtml (string output, string blog_base, IList entries, int start, int end, bool include_page_navigation)
{
using (FileStream o = CreateFile (output)){
StreamWriter w = new StreamWriter (o, GetOutputEncoding ());
@@ -613,16 +653,17 @@ string GetPageNavigation (int start, int end)
StringWriter blog_articles = new StringWriter ();
RenderArticleList (blog_articles);
- string page_navigation;
+ string page_navigation = "";
string title;
if (Math.Abs (start - end) == 1){
DayEntry d = (DayEntry) entries [entries.Count - start - 1];
title = String.Format ("{0} - {1}", d.Caption, config.Title);
- page_navigation = "";
} else {
title = config.Title;
- page_navigation = GetPageNavigation (start, end);
+
+ if (include_page_navigation)
+ page_navigation = GetPageNavigation (start, end);
}
Hashtable substitutions = new Hashtable ();
@@ -636,7 +677,7 @@ string GetPageNavigation (int start, int end)
substitutions.Add ("@RSSFILENAME@", config.RSSFileName);
substitutions.Add ("@EDITOR@", config.ManagingEditor);
substitutions.Add ("@BLOGWEBDIR@", config.BlogWebDirectory);
-
+ substitutions.Add ("@ARCHIVE_NAVIGATOR@", archive_navigator);
substitutions.Add ("@PAGE_NAVIGATION@", page_navigation);
Translate (template, w, substitutions);
@@ -674,21 +715,21 @@ string CreateEntryIndex (IList entries, int start, int end)
return sb.ToString ();
}
- public void RenderHtml (string template, string output, int start, int end, string blog_base)
+ public void RenderHtml (string output, int start, int end, string blog_base, bool include_page_navigation)
{
- RenderHtml (template, output, blog_base, entries, start, end);
+ RenderHtml (output, blog_base, entries, start, end, include_page_navigation);
}
- public void RenderArchive (string template)
+ public void RenderArchive ()
{
for (int i = 0; i < Entries; i++){
DayEntry d = (DayEntry) entries [i];
string parent_dir = "../..";
if (d.Category.Length > 0)
parent_dir += Regex.Replace (d.Category, "[^/]+", "..");
- RenderHtml (template, Path.Combine (config.Prefix, d.PermaLink),
- entries.Count - i - 1, entries.Count - i, parent_dir);
+ RenderHtml (Path.Combine (config.Prefix, d.PermaLink),
+ entries.Count - i - 1, entries.Count - i, parent_dir, false);
if (d.Images == null)
continue;
foreach (string filename in d.Images) {
@@ -721,19 +762,15 @@ public void RenderArchive (string template)
string category = de.Key.ToString ();
IList entries = (IList) de.Value;
string parent_dir = ".." + Regex.Replace (category, "[^/]+", "..");
- RenderHtml (template,
- Path.Combine (config.Prefix, "archive" + category + config.BlogFileName),
- parent_dir, entries, 0, entries.Count);
+ RenderHtml (Path.Combine (config.Prefix, "archive" + category + config.BlogFileName),
+ parent_dir, entries, 0, entries.Count, false);
}
}
RssChannel MakeChannel ()
{
- RssChannel c = new RssChannel ();
+ RssChannel c = new RssChannel (config.Title, config.Description, new Uri (config.BlogWebDirectory + "/" + config.BlogFileName));
- c.Title = config.Title;
- c.Link = new Uri (config.BlogWebDirectory + "/" + config.BlogFileName);
- c.Description = config.Description;
c.Copyright = config.Copyright;
c.Generator = "lb#";
c.ManagingEditor = config.ManagingEditor;
@@ -748,13 +785,12 @@ public void RenderArchiveRss (RssVersion version, string output, int end)
foreach (DictionaryEntry de in category_entries) {
string category = de.Key.ToString ();
IList entries = (IList) de.Value;
- RenderRSS (version,
- Path.Combine (config.Prefix, "archive" + category + output),
- entries, 0, Math.Min (end, entries.Count));
+ RenderRSS (Path.Combine (config.Prefix, "archive" + category + output),
+ entries, 0, Math.Min (end, entries.Count));
}
}
- public void RenderRSS (RssVersion version, string output, IList entries, int start, int end)
+ public void RenderRSS (string output, IList entries, int start, int end)
{
RssChannel channel = MakeChannel ();
@@ -791,17 +827,16 @@ public void RenderRSS (RssVersion version, string output, IList entries, int sta
}
FileStream o = CreateFile (output);
- RssWriter w = new RssWriter (o, new UTF8Encoding (false));
-
- w.Version = version;
+ XmlTextWriter xtw = new XmlTextWriter (o, new UTF8Encoding (false));
+ Rss20Writer w = new Rss20Writer (xtw);
w.Write (channel);
w.Close ();
}
public void RenderRSS (string output, int start, int end)
{
- RenderRSS (RssVersion.RSS20, output + ".rss2", entries, start, end);
+ RenderRSS (output + ".rss2", entries, start, end);
}
public class Article {
@@ -858,19 +893,36 @@ static void Main (string[] args)
if (!config.Parse (args))
return;
- Blog b = new Blog (config);
-
string template = File.OpenText (config.BlogTemplate).ReadToEnd ();
+ Blog b = new Blog (config, template);
+
+ //
+ // Renders the main page (index.html) and the various pageNN.html
+ //
for (int start = 0; start < b.Entries; start += Config.EntriesPerPage){
string output = GetOutputFileAtOffset (start);
- b.RenderHtml (template, Path.Combine (config.Prefix, output), start, start + Config.EntriesPerPage, "");
+ b.RenderHtml (Path.Combine (config.Prefix, output), start, start + Config.EntriesPerPage, "", true);
}
-
- b.RenderHtml (template, Path.Combine (config.Prefix, "all.html"), 0, b.Entries, "");
- b.RenderArchive (template);
+
+ //
+ // Renders the year/month dinguses
+ //
+ //
+ // Legacy render: all.html
+ //
+ b.RenderHtml (Path.Combine (config.Prefix, "all.html"), 0, b.Entries, "", false);
+
+ //
+ // Renders each individual blog entry into the archive
+ //
+ b.RenderArchive ();
+
+ //
+ // The RSS feed
+ //
b.RenderRSS (Path.Combine (config.Prefix, config.RSSFileName), 0, 30);
b.RenderArchiveRss (RssVersion.RSS20, config.RSSFileName + ".rss2", 30);
View
23 log-style.css
@@ -82,6 +82,20 @@ img {
line-height:110%;
}
+#title {
+ background: #4D4D4D url(header-bg.png) no-repeat scroll;
+ color: #ffffff;
+ font-size: 14pt;
+ font-family: "Droid Sans",Myriad,Segoe,Sans-Serif;;
+ border: 0;
+ margin: 0;
+ padding: 1em;
+}
+
+#title a:visited {
+ color: #ffffff;
+}
+
#main {
margin-left: 2em;
position: absolute;
@@ -126,11 +140,4 @@ img {
border-bottom: 1px dotted #aaaaaa; padding-top: 1em; padding-bottom: 1em;
}
-.comment {
- margin-left: 50pt;
- margin-bottom: 10pt;
- padding: 10pt;
- border-style: solid;
- border-width: 1px;
- border-color: #bccceb;
-}
+
View
59 template
@@ -1,22 +1,23 @@
<html>
- <head>
- <title>@TITLE@</title>
- <link rel='stylesheet' href='@BASEDIR@log-style.css' type='text/css' />
- <link rel="alternate" type="application/rss+xml" title="RSS" href="http://tirania.org/blog/miguel.rss2" />
- <script src='@BASEDIR@prettyprint.js' type='text/javascript'></script>
- <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
-<script type="text/javascript">
-function startup()
-{
- paintColors ();
-}
- </script>
- @ANALYTICS@
- </head>
+ <head>
+ <title>@TITLE@</title>
+ <link rel='stylesheet' href='@BASEDIR@log-style.css' type='text/css' />
+ <link rel="alternate" type="application/rss+xml" title="RSS" href="http://tirania.org/blog/miguel.rss2" />
+ <script src='@BASEDIR@prettyprint.js' type='text/javascript'></script>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+ <script type="text/javascript">
+ function startup()
+ {
+ paintColors ();
+ }
+ </script>
+ @ANALYTICS@
+</head>
<body onload='startup ();'>
-<h1><a href="@BLOGWEBDIR@">@DESCRIPTION@</a></h1>
+<div id='title'><a href="@BLOGWEBDIR@">@DESCRIPTION@</a>
+</div>
<div id='sidebar'>
<h2>RSS</h2>
@@ -44,23 +45,45 @@ function startup()
</script>
<!-- Google CSE Search Box Ends -->
+ <h2>Recommended Reading</h2>
+
+ <a href="http://www.amazon.com/gp/product/0321562992?ie=UTF8&tag=tiraniaorg-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=0321562992">
+ <img border="0" src="https://images-na.ssl-images-amazon.com/images/I/51uwyv0A0QL._SL160_.jpg"></a>
+ <img src="http://www.assoc-amazon.com/e/ir?t=tiraniaorg-20&l=as2&o=1&a=0321562992"
+ width="1" height="1" border="0" alt="" style="border:none
+ !important; margin:0px !important;" />
+
+ <p>
+
+ <a href="http://www.amazon.com/gp/product/0123704901?ie=UTF8&tag=tiraniaorg-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=0123704901"><img border="0"
+ src="https://images-na.ssl-images-amazon.com/images/I/517kQTy1i7L._SL160_.jpg"></a><img src="http://www.assoc-amazon.com/e/ir?t=tiraniaorg-20&l=as2&o=1&a=0123704901"
+ width="1" height="1" border="0" alt="" style="border:none
+ !important; margin:0px !important;" />
+
<h2>Pictures:</h2>
<a href="http://picasaweb.google.com/miguel.de.icaza/?pli=1">Picasa</a><br/>
<a href="http://www.flickr.com/photos/migueldeicaza/">Flickr</a>
- <p>
- <a href="http://www.go-mono.com"><img src="http://www.go-mono.com/images/mono-contributor-static.gif" alt="mono-contributor-static.gif" /></a>
- </p>
<script type="text/javascript" src="http://www.google.com/reader/ui/publisher.js"></script>
<script type="text/javascript" src="http://www.google.com/reader/public/javascript/user/13685641577668204834/state/com.google/broadcast?n=10&callback=GRC_p(%7Bc%3A'blue'%2Ct%3A'Miguel%5C047s%20shared%20items'%2Cs%3A'true'%7D)%3Bnew%20GRC"></script>
<div class="separator">
</div>
+ @ARCHIVE_NAVIGATOR@
+
+ <div class="separator">
+ </div>
+
+ <p>
+ <a href="http://www.go-mono.com"><img src="http://www.go-mono.com/images/mono-contributor-static.gif" alt="mono-contributor-static.gif" /></a>
+ </p>
+
<h2>Fundamental</h2>
<a href="http://www.go-mono.com/monologue">Monologue</a><br/>
<a href="http://www.commondreams.org">CommonDreams</a><br/>
+ <a href="http://grurrah.com/">Grurrah - Green Ideas</a><br/>
<h2>Friends</h2>

0 comments on commit 7fc7ea5

Please sign in to comment.