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(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) { string file = Path.GetFileName(filename); string thumbnail = Path.Combine(LB.GetEntryPath(config.Prefix + "/", d), LB.GetThumbnailName(file)); string thumbnail_target = Path.Combine( LB.GetEntryPath(config.Prefix + "/", d), file); file = Path.Combine(config.ImageDirectory, filename); if (!File.Exists(file)) { Console.Error.WriteLine("lb: Missing file for #thumbnail {0}, ({1}).", filename, file); continue; } if (!File.Exists(thumbnail_target)) { File.Copy(file, thumbnail_target); } if (!File.Exists(thumbnail)) { ProcessStartInfo psi = new ProcessStartInfo(config.ThumbnailCommandFileName); psi.Arguments = string.Format(config.ThumbnailCommandArguments, file, thumbnail); Process p = Process.Start(psi); p.WaitForExit(); if (p.ExitCode != 0) { Console.Error.WriteLine("lb: error running command: {0} {1}", psi.FileName, psi.Arguments); } } } } foreach (DictionaryEntry de in category_entries) { string category = de.Key.ToString(); IList entries = (IList)de.Value; string parent_dir = ".." + Regex.Replace(category, "[^/]+", ".."); RenderHtml(Path.Combine(config.Prefix, "archive" + category + config.BlogFileName), parent_dir, entries, 0, entries.Count, false); } }
void Load(TextReader i, bool is_html, string file) { bool caption_found = false; bool in_pre = false; StringBuilder sb = new StringBuilder(); string s; while ((s = i.ReadLine()) != null) { if (!caption_found) { if (is_html) { if (s.StartsWith("<h1>")) { Caption = s.Replace("<h1>", "").Replace("</h1>", ""); caption_found = true; continue; } else if (s.StartsWith("#include")) { sb.Append(Include(s.Substring(9), out Caption)); caption_found = true; continue; } } else { if (s.StartsWith("@") && !caption_found) { Caption = s.Substring(1); caption_found = true; continue; } } } // '#date' followed by the output of: // LC_TIME=C date -u +"%a, %d %b %Y %T GMT" // will set the publication date. // Example: // #date Thu, 09 Feb 2006 18:42:56 GMT if (s.StartsWith("#date ")) { try { Date = DateTime.ParseExact(s.Substring(6), "r", null); } catch (Exception e) { Console.WriteLine("Error parsing: '{0}'\n{1} on {2}", s.Substring(5), e, file); Environment.Exit(1); } continue; } if (!is_html) { if (s == "" && !in_pre) { sb.Append("<p>"); } else if (s.StartsWith("@")) { sb.Append(String.Format("<h1>{0}</h1>", s.Substring(1))); } else if (s.StartsWith("#pre")) { in_pre = true; } else if (s.StartsWith("#endpre")) { in_pre = false; } else { sb.Append(s); } } else { if (s.StartsWith("#include")) { string c; sb.Append(Include(s.Substring(9), out c)); continue; } else if (s.StartsWith("#pic")) { int idx = s.IndexOf(","); if (idx == -1) { Console.WriteLine("Wrong #pic command on {0}", file); continue; } string filename = s.Substring(5, idx - 5); string caption = s.Substring(idx + 1); sb.Append(String.Format("<p><center><a href=\"{0}pic.php?name={1}&caption={2}\"><img border=0 src=\"{3}/pictures/small-{1}\"></a><p>{2}</center></p>", blog_base, filename, caption, blog.config.BlogImageBasedir)); continue; } else if (s.StartsWith("#comment")) { Comments = true; continue; } else if (s.StartsWith("#nocomment")) { Comments = false; continue; } else if (s.StartsWith("#thumbnail")) { Match m = Regex.Match(s, @"^#thumbnail\s+(?<filename>[^\s]+)\s+(?<desc>.*)$"); if (m.Groups.Count > 0) { string filename = Path.GetFileName(m.Groups ["filename"].Value); string thumbnail = LB.GetThumbnailName(filename); sb.AppendFormat("<blockquote><p><a href=\"@ENTRY_PATH@{0}\"><img " + "src=\"@ENTRY_PATH@{1}\" title=\"{2}\" " + "alt=\"{2}\" /></a></p></blockquote>\n", filename, thumbnail, m.Groups.Count == 1 ? "" : m.Groups ["desc"].Value); Images = Images ?? new List <string> (); Images.Add(m.Groups ["filename"].Value); continue; } } sb.Append(s); } sb.Append("\n"); } Body = sb.ToString(); }