Added my picture
[mono.git] / doc / web / mono-rss.cs
1 //
2 // Generates the Mono RSS feed
3 //
4 // Miguel de Icaza
5 //
6 using System;
7 using System.IO;
8 using System.Xml;
9 using RSS;
10
11 class X {
12         static RSS.RSS rss;
13         static Channel c;
14         static int item_count;
15
16         static void PopulateRSS (StreamReader input)
17         {
18                 string s;
19                 
20                 while ((s = input.ReadLine ()) != null){
21                         if (s.StartsWith ("@item "))
22                                 break;
23                 }
24
25                 if (s == null || !s.StartsWith ("@item ")){
26                         Console.WriteLine ("Could not find beginning of text to RSS");
27                         return;
28                 }
29
30                 Item i = null;
31                 string description = "";
32                 do {
33                         if (s.StartsWith ("@item ")){
34                                 if (item_count++ > 25)
35                                         break;
36
37                                 if (i != null){
38                                         i.Description = description;
39                                         description = "";
40                                 }
41                                 
42                                 string title = s.Substring (6);
43                                 string link = "http://www.go-mono.com/index.html#";
44                                 foreach (char ch in title){
45                                         if (ch != ' ')
46                                                 link += ch;
47                                 }
48                                 
49                                 i = c.NewItem ();
50                                 i.Title = title;
51                                 i.Link = link;
52                         } else {
53                                 description += "\n" + (s == "\n" ? "<p>" : s);
54                         }
55                 } while ((s = input.ReadLine ()) != null);
56
57                 if (i != null){
58                         i.Description = description;
59                 }
60         }
61         
62         static void MakeRSS (string input, string output)
63         {
64                 rss = new RSS.RSS ();
65                 c = rss.NewChannel ("Mono Project News", "http://www.go-mono.com");
66                 
67                 c.Title = "Mono Project News";
68                 c.Link = "http://www.go-mono.com";
69                 c.Description =
70                 "News from the Mono project: a portable implementation of the .NET Framework";
71                 c.WebMaster = "webmaster@go-mono.com";
72                 c.ManagingEditor = "miguel@ximian.com";
73                 string t = File.GetLastWriteTime (input).ToString ("r");
74                 c.PubDate = t;
75                 c.LastBuildDate = t;
76
77                 using (FileStream fs = new FileStream (input, FileMode.Open)){
78                         using (StreamReader input_stream = new StreamReader (fs)){
79                                 PopulateRSS (input_stream);
80                         }
81                 }
82                 
83                 rss.XmlDocument.Save (output);
84         }
85         
86         static int Main (string [] args)
87         {
88                 switch (args.Length){
89                 case 0:
90                         MakeRSS ("index", "index.rss");
91                         break;
92                 case 2:
93                         MakeRSS (args [0], args [1]);
94                         break;
95                         
96                 default:
97                         Console.WriteLine ("Usage is: mono-rss [input output.rss]");
98                         return 1;
99                 }
100
101                 return 0;
102         }
103 }