Author: miguel
Date: 2005-05-25 00:58:51 -0400 (Wed, 25 May 2005)
New Revision: 44966
Modified:
trunk/lb/README
trunk/lb/config.xml
trunk/lb/lb.cs
trunk/lb/log-style.css
trunk/lb/makefile
trunk/lb/template
Log:
Multiple blog entries per day.
Use datetime from the entry (only for entries after May 25th, 2005)
Use @EDITOR@ to substitute email.
Improve layout.
Add navigation left/right
Modified: trunk/lb/README
===================================================================
--- trunk/lb/README 2005-05-25 03:35:46 UTC (rev 44965)
+++ trunk/lb/README 2005-05-25 04:58:51 UTC (rev 44966)
@@ -21,12 +21,17 @@
It looks for blog entries in:
- ~/activity/YYYY/mmm-dd.{html|txt}
+ ~/activity/YYYY/mmm-dd{-N}.{html|txt}
Ie, for example:
~/activity/2003/oct-01.html
+ To add multiple entries per day, append a -N to the entry:
+
+ ~/activity/2003/oct-01-1.html
+ ~/activity/2003/oct-01-2.html
+
For historic reasons, it generates an all.html (compatibility
with old permalinks) and also now it generates per-day
permalink entries in the archive/ directory.
Modified: trunk/lb/config.xml
===================================================================
--- trunk/lb/config.xml 2005-05-25 03:35:46 UTC (rev 44965)
+++ trunk/lb/config.xml 2005-05-25 04:58:51 UTC (rev 44966)
@@ -3,7 +3,7 @@
Author="Miguel de Icaza ([EMAIL PROTECTED])"
BlogDirectory="/home/miguel/activity"
BlogFileName="index.html"
-BlogWebDirectory="http://tirania.org/blog/"
+BlogWebDirectory="http://tirania.org/blog"
BlogImageBasedir="http://primates.ximian.com/~miguel"
Copyright="Miguel de Icaza"
Description="Miguel de Icaza's web log"
Modified: trunk/lb/lb.cs
===================================================================
--- trunk/lb/lb.cs 2005-05-25 03:35:46 UTC (rev 44965)
+++ trunk/lb/lb.cs 2005-05-25 04:58:51 UTC (rev 44966)
@@ -29,22 +29,29 @@
using System.Xml.Serialization;
using Rss;
-#if ATOM
-using Atom.Core;
-using Atom;
-#endif
-
class DayEntry : IComparable {
public DateTime Date;
public string Body;
- public string Caption;
+ public string Caption = "";
+ public string DateCaption;
+
Blog blog;
+ string extra = "";
public string blog_base;
+
+ //
+ // Text to inline CSS for the blog for classes code, code-csharp and
shell
+ //
const string code_style = "class=\"code\" style=\"border-style: solid;
background: #ddddff; border-width: 1px; padding: 2pt;\"";
const string code_csharp_style = "class=\"code-csharp\"
style=\"border-style: solid; background: #ddddff; border-width: 1px; padding:
2pt;\"";
const string shell_style = "style=\"border-style: solid; background:
#000000; color: #bbbbbb; border-width: 1px; padding: 2pt;\"";
+ //
+ // The date when we started using filestamps instead of the hardcoded
4pm
+ //
+ public DateTime SwitchDate = new DateTime (2005, 05, 25, 0, 0, 8);
+
DayEntry (Blog blog, string file)
{
this.blog = blog;
@@ -75,15 +82,15 @@
void ParseDate (string file)
{
- int p = file.LastIndexOf ("/");
int month;
- Match match = Regex.Match (file,
"(200[0-9])/([a-z]+)-0*([0-9]+)");
+ Match match = Regex.Match (file,
"(200[0-9])/([a-z]+)-0*([0-9]+)(-[0-9])?");
int year = Int32.Parse (file.Substring (match.Groups [1].Index,
match.Groups [1].Length));
int day = Int32.Parse (file.Substring (match.Groups [3].Index,
match.Groups [3].Length));
string month_name = file.Substring (match.Groups [2].Index,
match.Groups [2].Length);
-
+ extra = file.Substring (match.Groups [4].Index, match.Groups
[4].Length);
+
switch (month_name){
case "jan":
month = 1; break;
@@ -114,7 +121,20 @@
}
Date = new DateTime (year, month, day, 13, 55, 0);
- Caption = String.Format ("{0:dd} {0:MMM} {0:yyyy}", Date);
+
+ //
+ // Start using the file time stamp as the publishing date, this
is
+ // better than hardcoding a value. To avoid people sending us
long
+ // rants, only do this after today
+ //
+ if (Date > SwitchDate){
+ FileInfo fi = new FileInfo (file);
+ DateTime access_date = fi.LastWriteTime;
+
+ Date = new DateTime (year, month, day,
access_date.Hour, access_date.Minute, 0);
+ }
+
+ DateCaption = String.Format ("{0:dd} {0:MMM} {0:yyyy}", Date);
}
void Load (StreamReader i, bool is_html)
@@ -128,7 +148,7 @@
if (!caption_found){
if (is_html){
if (s.StartsWith ("<h1>")){
- Caption = Caption + ": " +
s.Replace ("<h1>", "").Replace ("</h1>", "");
+ Caption = s.Replace ("<h1>",
"").Replace ("</h1>", "");
caption_found = true;
continue;
} else if (s.StartsWith ("#include")){
@@ -138,7 +158,7 @@
}
} else {
if (s.StartsWith ("@") &&
!caption_found){
- Caption = Caption + ": " +
s.Substring (1);
+ Caption = s.Substring (1);
caption_found = true;
continue;
}
@@ -234,7 +254,7 @@
public string PermaLink {
get {
- return String.Format
("archive/{0:yyyy}/{0:MMM}-{0:dd}.html", Date);
+ return String.Format
("archive/{0:yyyy}/{0:MMM}-{0:dd}{1}.html", Date, extra);
}
}
}
@@ -274,26 +294,46 @@
static DateTime LastDate = new DateTime (2004, 5, 19, 0, 0, 0);
- void Render (StreamWriter o, int idx, string blog_base, bool
include_daily_anchor)
+ void Render (StreamWriter o, int idx, string blog_base, bool
include_daily_anchor, bool include_navigation)
{
DayEntry d = (DayEntry) entries [idx];
string anchor = HttpUtility.UrlEncode (d.Date.ToString
()).Replace ('%','-').Replace ('+', '-');
if (include_daily_anchor || d.Date < LastDate)
o.WriteLine (String.Format ("<a name=\"{0}\"></a>",
anchor));
- o.WriteLine ("<h3><a href=\"{2}{0}\"
class=\"entryTitle\">{1}</a> <font size=\"-2\">(<a
href=\"{2}{0}\">Permalink</a>)</font></h3>",
- d.PermaLink, d.Caption, blog_base);
+
+ if (include_navigation){
+ DayEntry prev = (DayEntry) (idx > 0 ? entries [idx-1] :
null);
+ DayEntry next = (DayEntry) (idx+1 < Entries ? entries
[idx+1] : null);
+
+ o.WriteLine ("<p>");
+ if (prev != null)
+ o.WriteLine ("<a href=\"{0}{1}\">� {2}</a> | ",
blog_base, prev.PermaLink, prev.Caption);
+ o.WriteLine ("<a href=\"{0}{1}\">Main</a>", blog_base,
config.BlogFileName);
+ if (next != null)
+ o.WriteLine ("| <a href=\"{0}{1}\">{2} �</a> ",
blog_base, next.PermaLink, next.Caption);
+
+ o.WriteLine ("<p>");
+ }
+
+ o.WriteLine ("<h3><a href=\"{2}/{0}\"
class=\"entryTitle\">{3}</a></h3>",
+ d.PermaLink, d.DateCaption, blog_base, d.Caption);
o.WriteLine ("<div class='blogentry'>" + d.Body + "</div>");
+ o.WriteLine ("<div class='footer'>Posted by {2} on <a
href=\"{0}{1}\">{3}</a></div><p>",
+ blog_base, d.PermaLink, config.Copyright,
d.DateCaption);
+
}
void Render (StreamWriter o, int start, int end, string blog_base, bool
include_daily_anchor)
{
+ bool navigation = start + 1 == end;
+
for (int i = start; i < end; i++){
int idx = entries.Count - i - 1;
if (idx < 0)
return;
- Render (o, idx, blog_base, include_daily_anchor);
+ Render (o, idx, blog_base, include_daily_anchor,
navigation);
}
}
@@ -306,12 +346,11 @@
public void RenderHtml (string template, string output, int start, int
end, string blog_base)
{
-
using (FileStream i = File.OpenRead (template), o = File.Create
(output)){
StreamReader s = new StreamReader (i,
Encoding.GetEncoding (28591));
StreamWriter w = new StreamWriter (o,
Encoding.GetEncoding (28591));
string line;
-
+
while ((line = s.ReadLine ()) != null){
switch (line){
case "@BLOG_ENTRIES@":
@@ -326,6 +365,7 @@
line = line.Replace ("@TITLE@",
config.Title);
line = line.Replace ("@DESCRIPTION@",
config.Description);
line = line.Replace ("@RSSFILENAME@",
config.RSSFileName);
+ line = line.Replace ("@EDITOR@",
config.ManagingEditor);
w.WriteLine (line);
break;
}
@@ -339,7 +379,7 @@
{
for (int i = 0; i < Entries; i++){
DayEntry d = (DayEntry) entries [i];
-
+
RenderHtml (template, d.PermaLink, Entries - i - 1,
Entries - i, "../../");
}
}
@@ -378,6 +418,10 @@
item.Link = new Uri (item.Guid.Name);
item.Guid.PermaLink = DBBool.True;
item.PubDate = d.Date;
+ if (d.Caption == ""){
+ Console.WriteLine ("No caption for: " +
d.DateCaption);
+ d.Caption = d.DateCaption;
+ }
item.Title = d.Caption;
channel.Items.Add (item);
@@ -392,60 +436,6 @@
w.Close ();
}
- //
- // Atom support is still fairly early, I do not know how to use it
completely yet
- //
-#if ATOM
- AtomFeed MakeAtomFeed ()
- {
- AtomFeed feed = new AtomFeed ();
- feed.Title = new AtomContentConstruct("title", config.Title);
- string url = config.BlogWebDirectory + config.BlogFileName;
- feed.Author = new AtomPersonConstruct("contributor",
- config.Copyright, new Uri
(url), config.ManagingEditor);
-
- feed.Contributors.Add (new AtomPersonConstruct("contributor",
-
config.Copyright, new Uri (url), config.ManagingEditor));
- feed.Tagline = new AtomContentConstruct("tagline",
config.Description);
- feed.Id = new Uri (url);
- feed.Copyright = new AtomContentConstruct("copyright",
"Copyright � 2003, 2004");
- feed.Modified = new AtomDateConstruct("modified", DateTime.Now,
-
TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now));
-
- return feed;
- }
-
- public void RenderAtom (string output, int start, int end)
- {
- AtomFeed feed = MakeAtomFeed();
-
- Uri url = new Uri(config.BlogWebDirectory +
config.BlogFileName);
-
- for (int i = start; i < end; i++){
- int idx = entries.Count - i - 1;
- if (idx < 0)
- continue;
-
- DayEntry d = (DayEntry) entries [idx];
-
- AtomEntry entry = new AtomEntry ();
- entry.Title = new AtomContentConstruct("title",
d.Caption);
- entry.Modified = new AtomDateConstruct("modified",
d.Date, TimeZone.CurrentTimeZone.GetUtcOffset (d.Date));
- entry.Issued = new AtomDateConstruct("issued", d.Date,
TimeZone.CurrentTimeZone.GetUtcOffset (d.Date));
- entry.Summary = new AtomContentConstruct("summary",
d.Body);
- entry.Contents.Add (new AtomContent (d.Body));
- entry.Contributors.Add(new
AtomPersonConstruct("contributor",
-
config.Copyright, url, config.ManagingEditor));
- entry.Id = new Uri (config.BlogWebDirectory +
"all.html#" + HttpUtility.UrlEncode (d.Date.ToString ()));
-
- feed.Entries.Add (entry);
- }
-
- using (FileStream o = File.Create (output))
- feed.Save (o);
- }
-#endif
-
public void RenderRSS (string output, int start, int end)
{
RenderRSS (RssVersion.RSS20, output + ".rss2", start, end);
@@ -487,10 +477,6 @@
b.RenderArchive ("template");
b.RenderRSS (config.RSSFileName, 0, 30);
-#if ATOM
- b.RenderAtom (config.RSSFileName + ".atom", 0, 30);
-#endif
-
File.Copy ("log-style.css", "texts/log-style.css", true);
}
}
Modified: trunk/lb/log-style.css
===================================================================
--- trunk/lb/log-style.css 2005-05-25 03:35:46 UTC (rev 44965)
+++ trunk/lb/log-style.css 2005-05-25 04:58:51 UTC (rev 44966)
@@ -11,7 +11,6 @@
h2, h3, h4, h5, h6 {
font-family: Verdana,sans-serif;
font-weight: bold;
- margin: 9pt;
}
h2 {
@@ -30,7 +29,7 @@
body, table {
background-color: #ffffff;
- font-family: Verdana, sans-serif; font-size: 12px;
+ font-family: Verdana, sans-serif;
color: black;
margin: 0;
padding: 0;
@@ -38,7 +37,7 @@
}
.blogentry {
- margin-left: 2em;
+ margin-left: 1em;
margin-right: 2em;
}
@@ -48,6 +47,11 @@
border: 0;
}
+.footer {
+ margin-left: 0em;
+ margin-botton: 1em;
+}
+
img {
border: 0;
vertical-align: top;
Modified: trunk/lb/makefile
===================================================================
--- trunk/lb/makefile 2005-05-25 03:35:46 UTC (rev 44965)
+++ trunk/lb/makefile 2005-05-25 04:58:51 UTC (rev 44966)
@@ -1,9 +1,8 @@
ASSEMBLIES= -r:RSS.NET.dll \
-r:System.Web
- #-r:Atom.NET.dll
lb.exe: lb.cs
- mcs $(ASSEMBLIES) -g lb.cs config.cs -out:lb.exe
+ mcs $(ASSEMBLIES) -debug lb.cs config.cs -out:lb.exe
b: lb.exe
mono --debug lb.exe
Modified: trunk/lb/template
===================================================================
--- trunk/lb/template 2005-05-25 03:35:46 UTC (rev 44965)
+++ trunk/lb/template 2005-05-25 04:58:51 UTC (rev 44966)
@@ -14,7 +14,7 @@
<a href="@BASEDIR@@[EMAIL PROTECTED]"><img src="@[EMAIL
PROTECTED]" alt="xml.gif"></a>
<a
href="http://www.bloglines.com/sub/http://primates.ximian.com/~miguel/miguel.rss2"><img
src="http://www.bloglines.com/images/sub_modern5.gif"/></a>
-<p>Email: <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>
+<p>Email: <a href="mailto:@EDITOR@">@EDITOR@</a>
<p><b>Docs:</b></p>
@BLOG_ARTICLES@
@@ -54,7 +54,9 @@
<div id='blogs'>
@BLOG_ENTRIES@
</div>
-<a href="@[EMAIL PROTECTED]">All entries</a>
+<div class='footer'>
+<!--a href="@[EMAIL PROTECTED]">All entries</a-->
+</div>
<center>
This is a personal web page. Things said here do not represent the
position of my employer.
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches