File: recent2.rb

package info (click to toggle)
hiki 0.8.7-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,796 kB
  • ctags: 1,736
  • sloc: ruby: 20,269; lisp: 926; sh: 269; makefile: 12
file content (38 lines) | stat: -rw-r--r-- 797 bytes parent folder | download | duplicates (3)
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
# $Id: recent2.rb,v 1.3 2004/12/14 16:12:33 fdiary Exp $
# Copyright (C) 2003 not <not@cds.ne.jp>

def recent2( n = 20 )
  n = n > 0 ? n : 0

  now = Time::now
  
  l = @db.page_info.sort do |a, b|
    b[b.keys[0]][:last_modified] <=> a[a.keys[0]][:last_modified]
  end

  s = "<ul>\n"

  l[0..n-1].each do |a|

    name = a.keys[0]
    p = a[name]
    
    tm = p[:last_modified ] 

    tp = now - tm
    if tp < 3600 then
      ps = "#{(tp / 60).to_i}m"
    elsif tp < 86400 then
      ps = "#{(tp / 3600).to_i}h"
    else
      ps = "#{(tp / 86400).to_i}d"
    end

    cur_date = tm.strftime( @conf.msg_date_format )
    t = page_name(name)
    an = hiki_anchor(name.escape, t)
    s << "<li title=\"#{cur_date}\">#{an} <span class=\"recent2\">(#{ps})</span>\n"
  end
  s << "</ul>\n"
  s
end