/////////////////////////////////////////////////////////////////////////////////////// // SimpleBlogger.cs -- Steven Romej Jan 2004 // // 0.1 30-31 January 2004 (it was late and the clock struck 12) // Initial version. Reads a text file and writes it out with tags // that reflect the current style of romej.com. Will only let you make // one entry for that day (b/c named by date), so that needs a fix, perhaps. // // 0.2 31 January 2004 // Added support for automatic rewriting of the index.php file to reflect both the new // blog entry as well as the 'Last modified' line. Can now blog *twice* in one day; // silly thing just adds 'a' to the end of the day (so 2nd blog is: 21aJanuary2004,eg) // /////////////////////////////////////////////////////////////////////////////////////// using System; using System.IO; using Blurcore.Configuration; public class SimplisticBlogger { private static string[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; public SimplisticBlogger( ) { //Initialization } public static void Main(String[] args) { SimplisticBlogger blogger = new SimplisticBlogger( ); StreamReader reader = null; StreamWriter writer = null; Configurator cfg = new Configurator( ); cfg.AddConfigEntry("file","index.php"); cfg.AddConfigEntry("marker1","//marker1"); cfg.AddConfigEntry("putmarker1","after"); cfg.AddConfigEntry("marker2","//marker2"); cfg.AddConfigEntry("putmarker2","replace"); cfg.WriteConfig( ); if( args.Length == 0 ) { blogger.Usage( ); return; } string blogfile = args[0]; string phpblog = DateTime.Now.Day + months[DateTime.Now.Month-1] + DateTime.Now.Year + ".php"; if (!File.Exists( blogfile )) { Console.WriteLine("{0} does not exist.", blogfile); return; } reader = File.OpenText( blogfile ); if (File.Exists( phpblog )) { Console.WriteLine("{0} already exists. Renaming...", phpblog); phpblog = DateTime.Now.Day +"a"+ months[DateTime.Now.Month-1] + DateTime.Now.Year + ".php"; } writer = File.CreateText( phpblog ); Console.WriteLine("Writing PHP blog {0} based on the content in {1}",phpblog,blogfile); string input; writer.Write("
");
reader.ReadLine(); //after the blog title there is a line of whitespace I don't want to reflect in the PHP
while ( (input = reader.ReadLine()) != null )
{
if( input.Length == 0 )
{
writer.WriteLine("
");
writer.WriteLine("
");
}
else
writer.WriteLine( input );
}
writer.WriteLine("