| 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="news" |
|---|
| 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/news/rss" |
|---|
| 27 | maker.channel.title = "お知らせ" |
|---|
| 28 | maker.channel.description = "Vine Linux からのお知らせです" |
|---|
| 29 | maker.channel.link = "http://vinelinux.org/news/" |
|---|
| 30 | maker.items.do_sort = true |
|---|
| 31 | |
|---|
| 32 | # create news indexhtml contents |
|---|
| 33 | newsindex = <<EOF |
|---|
| 34 | <h1>Vine Linux からのお知らせ</h1> |
|---|
| 35 | <div class="news"> |
|---|
| 36 | <table> |
|---|
| 37 | EOF |
|---|
| 38 | |
|---|
| 39 | # create all news page |
|---|
| 40 | Dir.open(newsdir) { |dir| |
|---|
| 41 | for filename in dir.grep(/.dat$/).sort.reverse |
|---|
| 42 | |
|---|
| 43 | news = NewsParser.new IO.read(newsdir+filename) |
|---|
| 44 | titletext = news.item['title'].gsub("\n","").gsub(/<[^>]+>/,"").strip |
|---|
| 45 | $header_title = 'Vine Linux News - '+titletext |
|---|
| 46 | |
|---|
| 47 | # index content |
|---|
| 48 | newsindex += <<-EOF |
|---|
| 49 | <tr> |
|---|
| 50 | <td class="date">[#{news.item['date']}]</td> |
|---|
| 51 | <td class="title"><a href="/#{targetname}/#{filename.gsub(/.dat/,".html")}"> |
|---|
| 52 | #{titletext}</a></td> |
|---|
| 53 | </tr> |
|---|
| 54 | EOF |
|---|
| 55 | |
|---|
| 56 | # rss |
|---|
| 57 | rssitem = maker.items.new_item |
|---|
| 58 | rssitem.link = urlhead+"#{targetname}/#{filename.gsub(/.dat/,".html")}" |
|---|
| 59 | rssitem.title = news.item['title'] |
|---|
| 60 | rssitem.date = Time.parse(news.item['date'].gsub(/\,/,"/")) |
|---|
| 61 | rssitem.dc_date = Time.parse(news.item['date'].gsub(/\,/,"/")) |
|---|
| 62 | rssitem.content_encoded = news.item['description'] |
|---|
| 63 | |
|---|
| 64 | # news page content |
|---|
| 65 | newshtml = <<-EOF |
|---|
| 66 | <h1>#{news.item['title']}</h1> |
|---|
| 67 | <div class="ads-middle-linkunit"> |
|---|
| 68 | <script type="text/javascript"><!-- |
|---|
| 69 | google_ad_client = "pub-0334540465096658"; |
|---|
| 70 | /* vinelinux link-unit */ |
|---|
| 71 | google_ad_slot = "4566651758"; |
|---|
| 72 | google_ad_width = 728; |
|---|
| 73 | google_ad_height = 15; |
|---|
| 74 | //--> |
|---|
| 75 | </script> |
|---|
| 76 | <script type="text/javascript" |
|---|
| 77 | src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> |
|---|
| 78 | </script> |
|---|
| 79 | </div> |
|---|
| 80 | <div align="right">発行日:#{news.item['date']}</div> |
|---|
| 81 | <div class="news"> |
|---|
| 82 | <p> |
|---|
| 83 | #{news.item['description']} |
|---|
| 84 | </p> |
|---|
| 85 | </div> |
|---|
| 86 | EOF |
|---|
| 87 | |
|---|
| 88 | # wrtite news page |
|---|
| 89 | template = ERB.new(newshtml) |
|---|
| 90 | newfile = open(filename.gsub(/.dat/,".html"), "w") |
|---|
| 91 | newfile.puts Layout.new.layout { template.result } |
|---|
| 92 | newfile.close |
|---|
| 93 | end |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | newsindex += <<EOF |
|---|
| 97 | </table> |
|---|
| 98 | </div> |
|---|
| 99 | EOF |
|---|
| 100 | |
|---|
| 101 | # write news indexhtml |
|---|
| 102 | template = ERB.new(newsindex) |
|---|
| 103 | newsindexhtml = open("index.html", "w") |
|---|
| 104 | newsindexhtml.puts Layout.new.layout { template.result } |
|---|
| 105 | newsindexhtml.close |
|---|
| 106 | |
|---|
| 107 | end |
|---|
| 108 | |
|---|
| 109 | # write news rss |
|---|
| 110 | File.open(rssname, "w") do |file| |
|---|
| 111 | file.puts rss.to_s |
|---|
| 112 | end |
|---|