[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> |
---|
| 37 | Vine Linux Magazine では Vine Linux を活用するのに便利な情報を記事として定期的に提供していきます。 |
---|
| 38 | </p> |
---|
| 39 | <h2>記事一覧</h2> |
---|
| 40 | <table> |
---|
| 41 | EOF |
---|
| 42 | |
---|
| 43 | # create all news page |
---|
| 44 | Dir.open(newsdir) { |dir| |
---|
| 45 | for filename in dir.grep(/.dat$/).sort.reverse |
---|
| 46 | |
---|
| 47 | news = NewsParser.new IO.read(newsdir+filename) |
---|
| 48 | titletext = news.item['title'].gsub("\n","").gsub(/<[^>]+>/,"").strip |
---|
| 49 | |
---|
[1323] | 50 | if (news.item['date'].gsub(/\,/,"") <= Time.now.strftime('%Y%m%d')) |
---|
| 51 | # index content |
---|
| 52 | newsindex += <<-EOF |
---|
| 53 | <tr> |
---|
| 54 | <td class="date">[#{news.item['date']}]</td> |
---|
| 55 | <td class="title"><a href="/#{targetname}/#{filename.gsub(/.dat/,".html")}"> |
---|
| 56 | #{titletext}</a></td> |
---|
| 57 | </tr> |
---|
| 58 | EOF |
---|
[1284] | 59 | |
---|
[1323] | 60 | # rss |
---|
| 61 | rssitem = maker.items.new_item |
---|
| 62 | rssitem.link = urlhead+"#{targetname}/#{filename.gsub(/.dat/,".html")}" |
---|
| 63 | rssitem.title = news.item['title'] |
---|
| 64 | rssitem.date = Time.parse(news.item['date'].gsub(/\,/,"/")) |
---|
| 65 | rssitem.dc_date = Time.parse(news.item['date'].gsub(/\,/,"/")) |
---|
| 66 | rssitem.content_encoded = news.item['description'] |
---|
| 67 | end |
---|
[1284] | 68 | |
---|
| 69 | # news page content |
---|
| 70 | newshtml = <<-EOF |
---|
| 71 | <h1 class="title">Vine Linux Magazine<br/>#{news.item['title']}</h1> |
---|
[1380] | 72 | <div class="ads-middle-linkunit"> |
---|
| 73 | <script type="text/javascript"><!-- |
---|
| 74 | google_ad_client = "pub-0334540465096658"; |
---|
| 75 | /* vinelinux link-unit */ |
---|
| 76 | google_ad_slot = "4566651758"; |
---|
| 77 | google_ad_width = 728; |
---|
| 78 | google_ad_height = 15; |
---|
| 79 | //--> |
---|
| 80 | </script> |
---|
| 81 | <script type="text/javascript" |
---|
| 82 | src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> |
---|
| 83 | </script> |
---|
| 84 | </div> |
---|
[1284] | 85 | <div align="right">発行日:#{news.item['date']}</div> |
---|
| 86 | <div class="news"> |
---|
| 87 | <p> |
---|
| 88 | #{news.item['description']} |
---|
| 89 | </p> |
---|
| 90 | </div> |
---|
| 91 | EOF |
---|
| 92 | |
---|
| 93 | # wrtite news page |
---|
| 94 | template = ERB.new(newshtml) |
---|
| 95 | newfile = open(filename.gsub(/.dat/,".html"), "w") |
---|
| 96 | newfile.puts Layout.new.layout { template.result } |
---|
| 97 | newfile.close |
---|
| 98 | end |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | newsindex += <<EOF |
---|
| 102 | </table> |
---|
| 103 | </div> |
---|
| 104 | EOF |
---|
| 105 | |
---|
| 106 | # write news indexhtml |
---|
| 107 | template = ERB.new(newsindex) |
---|
| 108 | newsindexhtml = open("index.html", "w") |
---|
| 109 | newsindexhtml.puts Layout.new.layout { template.result } |
---|
| 110 | newsindexhtml.close |
---|
| 111 | |
---|
| 112 | end |
---|
| 113 | |
---|
| 114 | # write news rss |
---|
| 115 | File.open(rssname, "w") do |file| |
---|
| 116 | file.puts rss.to_s |
---|
| 117 | end |
---|