source: projects/web/trunk/bin/layout-errata.rb @ 8611

Revision 8611, 5.0 KB checked in by daisuke, 10 years ago (diff)
  • errata ファイルの間違いで起きる例外を処理するように変更
    • 間違っている.datをskipするように変更
    • <url> タグがなくても例外を起こさないように変更
Line 
1#!/usr/bin/ruby
2# -*- encoding: utf-8 -*-
3require 'erb'
4require 'rss'
5require '../../bin/rss_cdata.rb'
6require '../../bin/newsparser.rb'
7
8# Layout class
9class Layout
10  extend ERB::DefMethod
11  def_erb_method('layout', '../../template/layout-errata.html.erb')
12end
13
14#
15urlhead="http://vinelinux.org/"
16erratadir="./"
17tmpdir = '../../template/'
18
19header=File.open("../../template/header.tmpl")
20footer=File.open("../../template/footer.tmpl")
21
22curdir = File.basename(Dir.pwd)
23
24# Create rss object
25rss = RSS::Maker.make("1.0") do |maker|
26  maker.channel.about = "http://vinelinux.org/errata/#{curdir}/rss"
27  maker.channel.title = "エラッタ情報(#{curdir})"
28  maker.channel.description = "Vine Linux #{curdir} のセキュリティ及びバグ更新情報です"
29  maker.channel.link = "http://vinelinux.org/errata/#{curdir}/"
30  maker.items.do_sort = true
31
32# create errata indexhtml contents
33errataindex = <<EOF
34<h2>Vine Linux #{curdir} のエラッタ情報</h2>
35<div class="errata">
36<table>
37  <tr>
38   <th class="date">日付</th>
39   <th class="desc">内容</th>
40   <th class="target">対象</th>
41  </tr>
42EOF
43
44# create all errata page
45Dir.open(erratadir) { |dir|
46 for filename in dir.grep(/.dat$/).sort.reverse
47 begin
48  errata = NewsParser.new IO.read(erratadir+filename)
49  titletext = errata.item['title'].gsub("\n","").gsub(/<[^>]+>/,"").strip
50  $header_title = 'Vine Linux ' + curdir + ' Errata - ' + titletext
51
52  # index content
53  errataindex += <<-EOF
54  <tr>
55   <td class="date">[#{errata.item['date']}]</td>
56   <td class="desc"><a href="/errata/#{curdir}/#{filename.gsub(/.dat/,".html")}">
57       #{errata.item['title']}</a></td>
58   <td class="target">#{errata.item['target']}</td>
59  </tr>
60  EOF
61
62  # rss
63  rssitem = maker.items.new_item
64  rssitem.link = urlhead+"errata/#{curdir}/#{filename.gsub(/.dat/,".html")}"
65  rssitem.title = errata.item['title']
66  rssitem.date = Time.parse(errata.item['date'].gsub(/\,/,"/"))
67  rssitem.dc_date = Time.parse(errata.item['date'].gsub(/\,/,"/"))
68  rssitem.content_encoded = errata.item['info']
69
70  # errata page content
71  erratahtml = <<-EOF
72  <h2>#{errata.item['title']}</h2>
73  <div class="ads-middle-linkunit">
74<div id="google-linkads-2"></div>
75<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
76<!-- vinelinux new link-unit -->
77<script>
78     ad = document.getElementById('google-linkads-2');
79     var adWidth = (typeof ad.getBoundingClientRect === 'function') ?
80     ad.getBoundingClientRect().width : ad.offsetWidth;
81     
82     google_ad_client = "ca-pub-0334540465096658";
83     
84     if ( adWidth >= 728 )      google_ad_param = ["728", "15", "6936914939"];
85     else if ( adWidth >= 468 ) google_ad_param = ["468", "15", "2367114535"];
86     else if ( adWidth >= 200 ) google_ad_param = ["200", "90", "3843847731"];
87     else if ( adWidth >= 180 ) google_ad_param = ["180", "90", "5320580934"];
88     else if ( adWidth >= 160 ) google_ad_param = ["160", "90", "6797314134"];
89     else                       google_ad_param = ["120", "90", "8274047334"];
90     
91     document.write (
92     '<ins class="adsbygoogle" style="display:inline-block;'
93     + 'width:' + google_ad_param[0] + 'px;'
94     + 'height:' + google_ad_param[1] + 'px'
95     + '" data-ad-client="' + google_ad_client
96     + '" data-ad-slot="' + google_ad_param[2]
97     + '"></ins>'
98     );
99     (adsbygoogle = window.adsbygoogle || []).push({});
100</script>
101  </div>
102  <div align="right">発行日:#{errata.item['date']}</div>
103  <div class="errata">
104  <dl>
105    <dt>対象 (Vine Linuxバージョン):</dt>
106    <dd><p>#{errata.item['target']}</p></dd>
107    <dt>内容:</dt>
108    <dd>#{errata.item['info']}</dd>
109    <dt>修正済パッケージ/ファイル:</dt>
110    <dd>
111<pre>
112#{errata.item['update']}
113</pre>
114    </dd>
115    <dt>入手先:</dt>
116    <dd>#{'update-watch, ' if curdir != "4x"}synaptic または apt-get でアップグレードすることができます。
117<pre class="screen">
118# apt-get update
119# apt-get upgrade
120</pre>
121    該当するパッケージをインストールしていない場合は、
122    更新の必要はありません。<br />
123    また、各ミラーサイトの
124<pre>
125#{errata.item['directory']}
126</pre>
127    からも個別に入手することができます。
128    </dd>
129    <dt>関連URL:</dt>
130    <dd><ul>
131  EOF
132
133  if errata.item['url']
134    errata.item['url'].each_line do |line|
135      erratahtml += "    <li><a href=\"#{line}\">#{line}</a></li>\n"
136    end
137  end
138
139  erratahtml += <<-EOF
140    </ul></dd>
141  </dl>
142  </div>
143  EOF
144
145  # write errata page
146  template = ERB.new(erratahtml)
147  newfile = open(filename.gsub(/.dat/,".html"), "w")
148  newfile.puts Layout.new.layout { template.result }
149  newfile.close
150 rescue
151  puts "\nE: #{filename}, skipped."
152 end
153 end
154}
155
156errataindex += <<EOF
157</table>
158</div>
159EOF
160
161# write errata indexhtml
162template = ERB.new(errataindex)
163$header_title = 'Vine Linux ' + curdir + ' Errata'
164errataindexhtml = open("index.html", "w")
165errataindexhtml.puts Layout.new.layout { template.result }
166errataindexhtml.close
167
168end
169
170# write errata rss
171File.open("errata#{curdir}.rdf", "w") do |file|
172  file.puts rss.to_s
173end
Note: See TracBrowser for help on using the repository browser.