#!/usr/bin/ruby # -*- encoding: utf-8 -*- require 'erb' require 'rss' require '../bin/rss_cdata.rb' require '../bin/newsparser.rb' # Layout class class Layout extend ERB::DefMethod def_erb_method('layout', '../template/layout-news.html.erb') end # urlhead="http://vinelinux.org/" newsdir="./" topdir=".." tmpdir = topdir+'/template/' targetname="news" rssname=targetname+'.rdf' header=File.open(topdir+"/template/header.tmpl") footer=File.open(topdir+"/template/footer.tmpl") # Create rss object rss = RSS::Maker.make("1.0") do |maker| maker.channel.about = "http://vinelinux.org/news/rss" maker.channel.title = "お知らせ" maker.channel.description = "Vine Linux からのお知らせです" maker.channel.link = "http://vinelinux.org/news/" maker.items.do_sort = true # create news indexhtml contents newsindex = <Vine Linux からのお知らせ
EOF # create all news page Dir.open(newsdir) { |dir| for filename in dir.grep(/.dat$/).sort.reverse news = NewsParser.new IO.read(newsdir+filename) titletext = news.item['title'].gsub("\n","").gsub(/<[^>]+>/,"").strip $header_title = 'Vine Linux News - '+titletext # index content newsindex += <<-EOF EOF # rss rssitem = maker.items.new_item rssitem.link = urlhead+"#{targetname}/#{filename.gsub(/.dat/,".html")}" rssitem.title = news.item['title'] rssitem.date = Time.parse(news.item['date'].gsub(/\,/,"/")) rssitem.dc_date = Time.parse(news.item['date'].gsub(/\,/,"/")) rssitem.content_encoded = news.item['description'] # news page content newshtml = <<-EOF

#{news.item['title']}

発行日:#{news.item['date']}

#{news.item['description']}

EOF # wrtite news page template = ERB.new(newshtml) newfile = open(filename.gsub(/.dat/,".html"), "w") newfile.puts Layout.new.layout { template.result } newfile.close end } newsindex += < EOF # write news indexhtml $header_title = 'Vine Linux News' template = ERB.new(newsindex) newsindexhtml = open("index.html", "w") newsindexhtml.puts Layout.new.layout { template.result } newsindexhtml.close end # write news rss File.open(rssname, "w") do |file| file.puts rss.to_s end
[#{news.item['date']}] #{titletext}