File: myrd2html.rb

package info (click to toggle)
ruby-pgplot 0.2.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 496 kB
  • sloc: ruby: 1,625; makefile: 77; ansic: 57; sh: 17
file content (47 lines) | stat: -rw-r--r-- 1,076 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
while /^--/ =~ ARGV[0]
  a = ARGV.shift
  case a
  when /^--title=(.*)/
    $title = $1
  when /^--lang=(.*)/
    $lang = $1
  when /^--kw=(.*)/
    $kw = $1
  when /^--rt/
    $rt = true
  end
end

rdfile = ARGV.shift
if ENV['SOURCE_DATE_EPOCH'].nil?
  build_date = Time.now
else
  build_date = Time.at(ENV['SOURCE_DATE_EPOCH'].to_i).gmtime
end
$date = build_date.utc.strftime("%b %d %Y ")

case $lang
when 'ja'
  rd2 = 'rd2 -r ./rd2html-img-lib.rb --html-lang=ja --with-css=./css.css --out-code=utf8'
else
  rd2 = 'rd2 -r ./rd2html-img-lib.rb --html-lang=en --with-css=./css.css'
end

rd2 << " --html-title='#{$title}'"  if $title
rd2 << " -r rd/rt-filter --with-part=RT:rt"  if $rt

IO.popen("#{rd2} #{rdfile}", "r") do |f|
  until f.eof
    s = f.readline
    s.sub!(%r|</head>|io) do |x|
      x = %|<meta name="Keywords" content="#{$kw}"/>\n| + x  if $kw
      x = %|<meta name="author" content="Masahiro Tanaka"/>\n| + x
      x
    end
    s.sub!(%r|</body>|io) do |x|
      x = %|<div>Last update: #{$date}</div>\n| + x  if $date
      x
    end
    puts s
  end
end