/////////////////////////////////////////////////////////////////////////////////////// // 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("

"); input = reader.ReadLine(); writer.Write( input ); writer.WriteLine("

"); writer.WriteLine("
"); writer.Write("
"); writer.Write( DateTime.Now.Day + " " + months[DateTime.Now.Month - 1] + " " + DateTime.Now.Year ); writer.WriteLine("
"); writer.WriteLine("

"); 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("

"); writer.WriteLine("
"); Console.WriteLine("{0} written successfully.",phpblog); reader.Close(); writer.Close(); blogger.ModifyIndexPage( phpblog ); } public void ModifyIndexPage( string newblog ) { StreamReader reader = null; StreamWriter writer = null; Configurator cfg = new Configurator( ); cfg.ParseOptions( ); if( File.Exists("index.php.bak") ) { Console.WriteLine("removing index.php.bak"); File.Delete("index.php.bak"); } Console.WriteLine("creating new backup file"); File.Copy("index.php","index.php.bak"); reader = File.OpenText( "index.php.bak" ); writer = File.CreateText( "index.php.new" ); string input = null; while( (input = reader.ReadLine()) != null ) { if( input.StartsWith(cfg.GetValue("start1"))) { writer.WriteLine("include(\""+newblog+"\");"); } if( input.StartsWith(cfg.GetValue("start2"))) { input = "Last modified: "+DateTime.Now.Day+" "+months[ DateTime.Now.Month-1 ]+" "+DateTime.Now.Year+"
"; } writer.WriteLine( input ); } reader.Close(); writer.Close(); Console.WriteLine("finalizing updated blog entry"); File.Delete("index.php"); File.Copy("index.php.new","index.php"); File.Delete("index.php.new"); } public void Usage( ) { Console.WriteLine("SimpleBlogger v0.2 - Blursoft 2004"); Console.WriteLine("Create a blog with HTML markup based on a simple text blog"); Console.WriteLine("Usage: mono SimpleBlogger.exe [BLOGFILE]"); return; } }