[1284] | 1 | #!/usr/bin/ruby |
---|
[7251] | 2 | # -*- encoding: utf-8 -*- |
---|
[1284] | 3 | require 'erb' |
---|
| 4 | require 'rss' |
---|
| 5 | require '../bin/rss_cdata.rb' |
---|
| 6 | require '../bin/newsparser.rb' |
---|
| 7 | |
---|
| 8 | # Layout class |
---|
| 9 | class Layout |
---|
| 10 | extend ERB::DefMethod |
---|
| 11 | def_erb_method('layout', '../template/layout-news.html.erb') |
---|
| 12 | end |
---|
| 13 | |
---|
| 14 | # |
---|
[1295] | 15 | urlhead="http://vinelinux.org/" |
---|
[1284] | 16 | newsdir="./" |
---|
| 17 | topdir=".." |
---|
| 18 | tmpdir = topdir+'/template/' |
---|
| 19 | targetname="news" |
---|
| 20 | rssname=targetname+'.rdf' |
---|
| 21 | |
---|
| 22 | header=File.open(topdir+"/template/header.tmpl") |
---|
| 23 | footer=File.open(topdir+"/template/footer.tmpl") |
---|
| 24 | |
---|
| 25 | # Create rss object |
---|
| 26 | rss = RSS::Maker.make("1.0") do |maker| |
---|
| 27 | maker.channel.about = "http://vinelinux.org/news/rss" |
---|
[3101] | 28 | maker.channel.title = "お知らせ" |
---|
[1284] | 29 | maker.channel.description = "Vine Linux からのお知らせです" |
---|
| 30 | maker.channel.link = "http://vinelinux.org/news/" |
---|
| 31 | maker.items.do_sort = true |
---|
| 32 | |
---|
| 33 | # create news indexhtml contents |
---|
| 34 | newsindex = <<EOF |
---|
| 35 | <h1>Vine Linux からのお知らせ</h1> |
---|
| 36 | <div class="news"> |
---|
| 37 | <table> |
---|
| 38 | EOF |
---|
| 39 | |
---|
| 40 | # create all news page |
---|
| 41 | Dir.open(newsdir) { |dir| |
---|
| 42 | for filename in dir.grep(/.dat$/).sort.reverse |
---|
| 43 | |
---|
| 44 | news = NewsParser.new IO.read(newsdir+filename) |
---|
| 45 | titletext = news.item['title'].gsub("\n","").gsub(/<[^>]+>/,"").strip |
---|
[4519] | 46 | $header_title = 'Vine Linux News - '+titletext |
---|
[1284] | 47 | |
---|
| 48 | # index content |
---|
| 49 | newsindex += <<-EOF |
---|
| 50 | <tr> |
---|
| 51 | <td class="date">[#{news.item['date']}]</td> |
---|
| 52 | <td class="title"><a href="/#{targetname}/#{filename.gsub(/.dat/,".html")}"> |
---|
| 53 | #{titletext}</a></td> |
---|
| 54 | </tr> |
---|
| 55 | EOF |
---|
| 56 | |
---|
| 57 | # rss |
---|
| 58 | rssitem = maker.items.new_item |
---|
| 59 | rssitem.link = urlhead+"#{targetname}/#{filename.gsub(/.dat/,".html")}" |
---|
| 60 | rssitem.title = news.item['title'] |
---|
| 61 | rssitem.date = Time.parse(news.item['date'].gsub(/\,/,"/")) |
---|
| 62 | rssitem.dc_date = Time.parse(news.item['date'].gsub(/\,/,"/")) |
---|
| 63 | rssitem.content_encoded = news.item['description'] |
---|
| 64 | |
---|
| 65 | # news page content |
---|
| 66 | newshtml = <<-EOF |
---|
[2658] | 67 | <h1>#{news.item['title']}</h1> |
---|
| 68 | <div class="ads-middle-linkunit"> |
---|
[1380] | 69 | <script type="text/javascript"><!-- |
---|
| 70 | google_ad_client = "pub-0334540465096658"; |
---|
| 71 | /* vinelinux link-unit */ |
---|
| 72 | google_ad_slot = "4566651758"; |
---|
| 73 | google_ad_width = 728; |
---|
| 74 | google_ad_height = 15; |
---|
| 75 | //--> |
---|
| 76 | </script> |
---|
| 77 | <script type="text/javascript" |
---|
| 78 | src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> |
---|
| 79 | </script> |
---|
[2658] | 80 | </div> |
---|
| 81 | <div align="right">発行日:#{news.item['date']}</div> |
---|
| 82 | <div class="news"> |
---|
| 83 | <p> |
---|
[1284] | 84 | #{news.item['description']} |
---|
[2658] | 85 | </p> |
---|
| 86 | </div> |
---|
[1284] | 87 | EOF |
---|
| 88 | |
---|
| 89 | # wrtite news page |
---|
| 90 | template = ERB.new(newshtml) |
---|
| 91 | newfile = open(filename.gsub(/.dat/,".html"), "w") |
---|
| 92 | newfile.puts Layout.new.layout { template.result } |
---|
| 93 | newfile.close |
---|
| 94 | end |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | newsindex += <<EOF |
---|
| 98 | </table> |
---|
| 99 | </div> |
---|
| 100 | EOF |
---|
| 101 | |
---|
| 102 | # write news indexhtml |
---|
[7367] | 103 | $header_title = 'Vine Linux News' |
---|
[1284] | 104 | template = ERB.new(newsindex) |
---|
| 105 | newsindexhtml = open("index.html", "w") |
---|
| 106 | newsindexhtml.puts Layout.new.layout { template.result } |
---|
| 107 | newsindexhtml.close |
---|
| 108 | |
---|
| 109 | end |
---|
| 110 | |
---|
| 111 | # write news rss |
---|
| 112 | File.open(rssname, "w") do |file| |
---|
| 113 | file.puts rss.to_s |
---|
| 114 | end |
---|