[1284] | 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 | # |
---|
[1295] | 14 | urlhead="http://vinelinux.org/" |
---|
[1284] | 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> |
---|
[1409] | 37 | Vine Linux Magazine では Vine Linux を活用するのに便利な情報を記事として提供していきます。 |
---|
[1284] | 38 | </p> |
---|
[1409] | 39 | <dl> |
---|
| 40 | <dt>掲載予定</dt> |
---|
[2153] | 41 | <dd>- 定期的な VineSeed/VinePlus パッケージ紹介 (ほぼ月刊)<br/> |
---|
| 42 | - Vine Linux 活用記事 (月1本程度で不定期)</dd> |
---|
[1409] | 43 | </dl> |
---|
| 44 | |
---|
[1284] | 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 | |
---|
[1323] | 56 | if (news.item['date'].gsub(/\,/,"") <= Time.now.strftime('%Y%m%d')) |
---|
| 57 | # index content |
---|
| 58 | newsindex += <<-EOF |
---|
| 59 | <tr> |
---|
| 60 | <td class="date">[#{news.item['date']}]</td> |
---|
| 61 | <td class="title"><a href="/#{targetname}/#{filename.gsub(/.dat/,".html")}"> |
---|
| 62 | #{titletext}</a></td> |
---|
| 63 | </tr> |
---|
| 64 | EOF |
---|
[1284] | 65 | |
---|
[1323] | 66 | # rss |
---|
| 67 | rssitem = maker.items.new_item |
---|
| 68 | rssitem.link = urlhead+"#{targetname}/#{filename.gsub(/.dat/,".html")}" |
---|
| 69 | rssitem.title = news.item['title'] |
---|
| 70 | rssitem.date = Time.parse(news.item['date'].gsub(/\,/,"/")) |
---|
| 71 | rssitem.dc_date = Time.parse(news.item['date'].gsub(/\,/,"/")) |
---|
| 72 | rssitem.content_encoded = news.item['description'] |
---|
| 73 | end |
---|
[1284] | 74 | |
---|
| 75 | # news page content |
---|
| 76 | newshtml = <<-EOF |
---|
| 77 | <h1 class="title">Vine Linux Magazine<br/>#{news.item['title']}</h1> |
---|
[1380] | 78 | <div class="ads-middle-linkunit"> |
---|
| 79 | <script type="text/javascript"><!-- |
---|
| 80 | google_ad_client = "pub-0334540465096658"; |
---|
| 81 | /* vinelinux link-unit */ |
---|
| 82 | google_ad_slot = "4566651758"; |
---|
| 83 | google_ad_width = 728; |
---|
| 84 | google_ad_height = 15; |
---|
| 85 | //--> |
---|
| 86 | </script> |
---|
| 87 | <script type="text/javascript" |
---|
| 88 | src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> |
---|
| 89 | </script> |
---|
| 90 | </div> |
---|
[2153] | 91 | EOF |
---|
| 92 | |
---|
| 93 | if (news.item['author']) |
---|
| 94 | newshtml += <<-EOF |
---|
| 95 | <div align="right">筆者: #{news.item['author']}</div> |
---|
| 96 | EOF |
---|
| 97 | end |
---|
| 98 | |
---|
| 99 | newshtml += <<-EOF |
---|
| 100 | <div align="right">発行日: #{news.item['date']}</div> |
---|
[1284] | 101 | <div class="news"> |
---|
| 102 | <p> |
---|
| 103 | #{news.item['description']} |
---|
| 104 | </p> |
---|
| 105 | </div> |
---|
| 106 | EOF |
---|
| 107 | |
---|
| 108 | # wrtite news page |
---|
| 109 | template = ERB.new(newshtml) |
---|
| 110 | newfile = open(filename.gsub(/.dat/,".html"), "w") |
---|
| 111 | newfile.puts Layout.new.layout { template.result } |
---|
| 112 | newfile.close |
---|
| 113 | end |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | newsindex += <<EOF |
---|
| 117 | </table> |
---|
| 118 | </div> |
---|
| 119 | EOF |
---|
| 120 | |
---|
| 121 | # write news indexhtml |
---|
| 122 | template = ERB.new(newsindex) |
---|
| 123 | newsindexhtml = open("index.html", "w") |
---|
| 124 | newsindexhtml.puts Layout.new.layout { template.result } |
---|
| 125 | newsindexhtml.close |
---|
| 126 | |
---|
| 127 | end |
---|
| 128 | |
---|
| 129 | # write news rss |
---|
| 130 | File.open(rssname, "w") do |file| |
---|
| 131 | file.puts rss.to_s |
---|
| 132 | end |
---|