1 | #!/usr/bin/ruby |
---|
2 | require 'erb' |
---|
3 | require 'rss' |
---|
4 | require '../bin/rss_cdata.rb' |
---|
5 | require '../bin/newsparser.rb' |
---|
6 | |
---|
7 | # Layout class |
---|
8 | class Layout |
---|
9 | extend ERB::DefMethod |
---|
10 | def_erb_method('layout', '../template/layout-news.html.erb') |
---|
11 | end |
---|
12 | |
---|
13 | # |
---|
14 | urlhead="http://vinelinux.org/" |
---|
15 | newsdir="./" |
---|
16 | topdir=".." |
---|
17 | tmpdir = topdir+'/template/' |
---|
18 | targetname="vlmagazine" |
---|
19 | rssname=targetname+'.rdf' |
---|
20 | |
---|
21 | header=File.open(topdir+"/template/header.tmpl") |
---|
22 | footer=File.open(topdir+"/template/footer.tmpl") |
---|
23 | |
---|
24 | # Create rss object |
---|
25 | rss = RSS::Maker.make("1.0") do |maker| |
---|
26 | maker.channel.about = "http://vinelinux.org/#{targetname}/rss" |
---|
27 | maker.channel.title = "Vine Linux Magazine" |
---|
28 | maker.channel.description = "Vine Linux Magazine です" |
---|
29 | maker.channel.link = "http://vinelinux.org/#{targetname}/" |
---|
30 | maker.items.do_sort = true |
---|
31 | |
---|
32 | # create news indexhtml contents |
---|
33 | newsindex = <<EOF |
---|
34 | <h1 class="title">Vine Linux Magazine</h1> |
---|
35 | <div class="news"> |
---|
36 | <p> |
---|
37 | Vine Linux Magazine では Vine Linux を活用するのに便利な情報を記事として提供していきます。 |
---|
38 | </p> |
---|
39 | <dl> |
---|
40 | <dt>掲載予定</dt> |
---|
41 | <dd>- 定期的な VineSeed/VinePlus パッケージ紹介 (ほぼ月刊)<br/> |
---|
42 | - Vine Linux 活用記事 (月1本程度で不定期)</dd> |
---|
43 | </dl> |
---|
44 | |
---|
45 | <h2>記事一覧</h2> |
---|
46 | <table> |
---|
47 | EOF |
---|
48 | |
---|
49 | # create all news page |
---|
50 | Dir.open(newsdir) { |dir| |
---|
51 | for filename in dir.grep(/.dat$/).sort.reverse |
---|
52 | |
---|
53 | news = NewsParser.new IO.read(newsdir+filename) |
---|
54 | titletext = news.item['title'].gsub("\n","").gsub(/<[^>]+>/,"").strip |
---|
55 | $header_title = 'Vine Linux Magazine - '+titletext |
---|
56 | |
---|
57 | if (news.item['date'].gsub(/\,/,"") <= Time.now.strftime('%Y%m%d')) |
---|
58 | # index content |
---|
59 | newsindex += <<-EOF |
---|
60 | <tr> |
---|
61 | <td class="date">[#{news.item['date']}]</td> |
---|
62 | <td class="title"><a href="/#{targetname}/#{filename.gsub(/.dat/,".html")}"> |
---|
63 | #{titletext}</a></td> |
---|
64 | </tr> |
---|
65 | EOF |
---|
66 | |
---|
67 | # rss |
---|
68 | rssitem = maker.items.new_item |
---|
69 | rssitem.link = urlhead+"#{targetname}/#{filename.gsub(/.dat/,".html")}" |
---|
70 | rssitem.title = news.item['title'] |
---|
71 | rssitem.date = Time.parse(news.item['date'].gsub(/\,/,"/")) |
---|
72 | rssitem.dc_date = Time.parse(news.item['date'].gsub(/\,/,"/")) |
---|
73 | rssitem.content_encoded = news.item['description'] |
---|
74 | end |
---|
75 | |
---|
76 | # news page content |
---|
77 | newshtml = <<-EOF |
---|
78 | <h1 class="title">Vine Linux Magazine<br/>#{news.item['title']}</h1> |
---|
79 | <div class="ads-middle-linkunit"> |
---|
80 | <script type="text/javascript"><!-- |
---|
81 | google_ad_client = "pub-0334540465096658"; |
---|
82 | /* vinelinux link-unit */ |
---|
83 | google_ad_slot = "4566651758"; |
---|
84 | google_ad_width = 728; |
---|
85 | google_ad_height = 15; |
---|
86 | //--> |
---|
87 | </script> |
---|
88 | <script type="text/javascript" |
---|
89 | src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> |
---|
90 | </script> |
---|
91 | </div> |
---|
92 | EOF |
---|
93 | |
---|
94 | if (news.item['author']) |
---|
95 | newshtml += <<-EOF |
---|
96 | <div align="right">筆者: #{news.item['author']}</div> |
---|
97 | EOF |
---|
98 | end |
---|
99 | |
---|
100 | newshtml += <<-EOF |
---|
101 | <div align="right">発行日: #{news.item['date']}</div> |
---|
102 | <div class="news"> |
---|
103 | <p> |
---|
104 | #{news.item['description']} |
---|
105 | </p> |
---|
106 | </div> |
---|
107 | EOF |
---|
108 | |
---|
109 | # wrtite news page |
---|
110 | template = ERB.new(newshtml) |
---|
111 | newfile = open(filename.gsub(/.dat/,".html"), "w") |
---|
112 | newfile.puts Layout.new.layout { template.result } |
---|
113 | newfile.close |
---|
114 | end |
---|
115 | } |
---|
116 | |
---|
117 | newsindex += <<EOF |
---|
118 | </table> |
---|
119 | </div> |
---|
120 | EOF |
---|
121 | |
---|
122 | # write news indexhtml |
---|
123 | template = ERB.new(newsindex) |
---|
124 | newsindexhtml = open("index.html", "w") |
---|
125 | newsindexhtml.puts Layout.new.layout { template.result } |
---|
126 | newsindexhtml.close |
---|
127 | |
---|
128 | end |
---|
129 | |
---|
130 | # write news rss |
---|
131 | File.open(rssname, "w") do |file| |
---|
132 | file.puts rss.to_s |
---|
133 | end |
---|