root/platform/tdiary/plugin/simple_autopagerize.rb

Revision 4415, 1.4 kB (checked in by poppen, 11 months ago)

platform/tdiary/plugin/simple_autopagerize.rb: import

Line 
1#
2# simple_autopagerize.rb - tDiary plugin
3#
4# add <link rel="prev"> and <link rel="next"> tags for AutoPagerize
5#
6# Copyright (C) 2008 MATSUI Shinsuke <poppen@karashi.org>
7# You can redistribute it and/or modify it under GPL2.
8#
9
10return unless /^(latest|month)$/ =~ @mode
11
12add_header_proc do
13        result = String.new
14        case @mode
15        when 'latest'
16                if @conf['ndays.prev'] then
17                        result << %Q[<link rel="next" title="#{h navi_prev_ndays}" href="#{h @index}#{anchor( @conf['ndays.prev'] + '-' + @conf.latest_limit.to_s )}">\n\t]
18                end
19                if @conf['ndays.next'] then
20                        result << %Q[<link rel="prev" title="#{h navi_next_ndays}" href="#{h @index}#{anchor( @conf['ndays.next'] + '-' + @conf.latest_limit.to_s )}">\n\t]
21                end
22        when 'month'
23                ym = []
24                @years.keys.each do |y|
25                        ym += @years[y].collect {|m| y + m}
26                end
27                ym.sort!
28                now = @date.strftime( '%Y%m' )
29                return '' unless ym.index( now )
30                prev_month = ym.index( now ) == 0 ? nil : ym[ym.index( now )-1]
31                next_month = ym[ym.index( now )+1]
32
33                if prev_month then
34                        result << %Q[<link rel="prev" title="#{h navi_prev_month}" href="#{h @index}#{anchor( prev_month )}">\n\t]
35                end
36                if next_month then
37                        result << %Q[<link rel="next" title="#{h navi_next_month}" href="#{h @index}#{anchor( next_month )}">\n\t]
38                end
39        end
40        result.chop.chop
41end
42
43# Local Variables:
44# mode: ruby
45# indent-tabs-mode: t
46# tab-width: 3
47# ruby-indent-level: 3
48# End:
49# vi: ts=3 sw=3
Note: See TracBrowser for help on using the browser.