Permalink
Browse files

Small changes to try to merge a wordpress theme

  • Loading branch information...
1 parent 5083943 commit b2903b975554d5f4fdf2d44da078d42a5771d25b @migueldeicaza migueldeicaza committed Dec 8, 2010
Showing with 39 additions and 20 deletions.
  1. +2 −0 .gitignore
  2. +10 −0 config.cs
  3. +21 −14 lb.cs
  4. +6 −6 makefile
View
@@ -1,2 +1,4 @@
*.exe
*.mdb
+output
+
View
@@ -24,6 +24,9 @@ public class Config {
[XmlAttribute] public string EntrySpecific;
[XmlAttribute] public string ImageDirectory;
[XmlAttribute] public string ThumbnailCommand;
+ public string ConfigFile;
+ public bool Verbose;
+
static public int EntriesPerPage = 15;
internal string ThumbnailCommandFileName;
@@ -61,6 +64,13 @@ public bool Parse (string[] args)
if (NextArgument (args, ref i, ref ThumbnailCommand))
break;
return false;
+ case "-c": case "--config":
+ if (NextArgument (args, ref i, ref ConfigFile))
+ break;
+ return false;
+ case "-v": case "--verbose":
+ Verbose = true;
+ break;
default:
if (ExtractArgument ("-p", arg, ref Prefix))
break;
View
35 lb.cs
@@ -69,9 +69,9 @@ class DayEntry : IComparable {
using (FileStream i = File.OpenRead (file)){
using (StreamReader s = new StreamReader (i, Encoding.GetEncoding (blog.config.InputEncoding))){
if (file.EndsWith (".html"))
- Load (s, true);
+ Load (s, true, file);
else if (file.EndsWith (".txt"))
- Load (s, false);
+ Load (s, false, file);
}
}
}
@@ -83,7 +83,8 @@ public static DayEntry Load (Blog blog, string file)
try {
de = new DayEntry (blog, file);
} catch (Exception e) {
- Console.WriteLine ("Failed to load file: {0}. Reason: {1}", file, e.Message);
+ if (blog.Verbose)
+ Console.WriteLine ("Failed to load file: {0}. Reason: {1}", file, e.Message);
}
return de;
}
@@ -155,7 +156,7 @@ void ParseDate (string file)
DateCaption = String.Format ("{0:dd} {0:MMM} {0:yyyy}", Date);
}
- void Load (StreamReader i, bool is_html)
+ void Load (StreamReader i, bool is_html, string file)
{
bool caption_found = false;
bool in_pre = false;
@@ -192,7 +193,7 @@ void Load (StreamReader i, bool is_html)
try {
Date = DateTime.ParseExact (s.Substring (6), "r", null);
} catch (Exception e) {
- Console.WriteLine ("Error parsing: '{0}'\n{1}", s.Substring (5), e);
+ Console.WriteLine ("Error parsing: '{0}'\n{1} on {2}", s.Substring (5), e, file);
Environment.Exit (1);
}
continue;
@@ -217,7 +218,7 @@ void Load (StreamReader i, bool is_html)
} else if (s.StartsWith ("#pic")){
int idx = s.IndexOf (",");
if (idx == -1){
- Console.WriteLine ("Wrong #pic command");
+ Console.WriteLine ("Wrong #pic command on {0}", file);
continue;
}
@@ -319,6 +320,7 @@ string Include (string file, out string caption)
class Blog {
public Config config;
+ public bool Verbose;
string template;
public DateTime pubDate = new DateTime (1, 1, 1);
string entry_template;
@@ -340,6 +342,7 @@ public Blog (Config config, string template)
this.template = template;
this.config = config;
this.entry_template = File.OpenText (config.EntryTemplate).ReadToEnd ();
+ Verbose = config.Verbose;
LoadDirectory (new DirectoryInfo (config.BlogDirectory));
@@ -405,7 +408,8 @@ void LoadDirectory (DirectoryInfo dir)
{
if (dir.Name.EndsWith ("drafts"))
return;
- Console.WriteLine ("dir:" + dir);
+ if (Verbose)
+ Console.WriteLine ("dir:" + dir);
foreach (DirectoryInfo subdir in dir.GetDirectories ()) {
LoadDirectory (subdir);
}
@@ -794,7 +798,6 @@ public void RenderRSS (string output, IList entries, int start, int end)
{
RssChannel channel = MakeChannel ();
- Console.WriteLine ("{0} to {1}", start, end);
for (int i = start; i < end; i++){
int idx = entries.Count - i - 1;
if (idx < 0)
@@ -818,7 +821,6 @@ public void RenderRSS (string output, IList entries, int start, int end)
item.Guid.PermaLink = DBBool.True;
item.PubDate = d.Date.ToUniversalTime ();
- Console.WriteLine ("{0} to {1}", d.Caption, item.PubDate);
if (d.Caption == ""){
Console.WriteLine ("No caption for: " + d.DateCaption);
d.Caption = d.DateCaption;
@@ -873,15 +875,19 @@ class LB {
static public string GetOutputFileAtOffset (int offset)
{
- if (offset == 0)
- return config.BlogFileName;
- else
- return String.Format ("page{0}.html", offset / Config.EntriesPerPage);
+ return offset == 0 ? config.BlogFileName : String.Format ("page{0}.html", offset / Config.EntriesPerPage);
}
static void Main (string[] args)
{
- config = (Config) new XmlSerializer (typeof (Config)).Deserialize (new XmlTextReader ("config.xml"));
+ var basicConfig = new Config ();
+ if (!basicConfig.Parse (args))
+ return;
+
+ config = (Config) new XmlSerializer (typeof (Config)).Deserialize (new XmlTextReader (basicConfig.ConfigFile));
+
+ if (args.Length > 1)
+ config.Prefix = args [1];
if (config.BlogImageBasedir == null || config.BlogImageBasedir == "")
config.BlogImageBasedir = config.BlogWebDirectory;
@@ -930,6 +936,7 @@ static void Main (string[] args)
if (File.Exists ("log-style.css")) {
File.Copy ("log-style.css", "texts/log-style.css", true);
+ File.Copy ("log-style.css", Path.Combine (config.Prefix, "log-style.css"), true);
}
}
View
@@ -8,16 +8,16 @@ lb.exe: lb.cs config.cs
gmcs $(ASSEMBLIES) -debug lb.cs config.cs -out:lb.exe
b: lb.exe
- mono --debug lb.exe
+ mono --debug lb.exe -c config.xml -p output
clean:
- rm -f *.exe
+ rm -fr *.exe output
push: b
- chmod 644 archive/*/*.html
- chmod 644 *html *rss2 *php
- rsync -zu --checksum -pr -v --rsh=ssh texts archive prettyprint.js \
- log-style.css *.rss2 *.php index.html page*.html all.html \
+ chmod 644 output/archive/*/*.html
+ chmod 644 output/*html output/*rss2
+ rsync -zu --checksum -pr -v --rsh=ssh texts prettyprint.js log-style.css \
+ output/archive output/*.rss2 output/index.html output/page*.html output/all.html \
$(REMOTE_DIRECTORY)
check-update:

0 comments on commit b2903b9

Please sign in to comment.