↓skel/diary.rhtml ($Revision: 1.21 $ / 3行目)
<h2><span class="date"><a name="<%=date.strftime("%Y%m%d")%>" href="<%= opt['index'] %><%%=anchor "<%= @date.strftime( '%Y%m%d' ) %>" %>"><%= @date.strftime( opt['date_format'] ) %></a></span> <span class="title"><%= title %></span><%
↓misc/plugin/index_list.rb →tDiary-2.1.1(N日表示)対応版
# index_list.rb
#
# 「最新」「月」表示に対応した目次を表示。
# recent_listやtitle_listと違い日付のリンク先は日別表示でなくページ内。
# その為に、diary.rhtmlをいじって日付にアンカーを付ける必要がある。
# 骨格にrecent_list.rbを使用。
# [2005-04-20] 月表示では昇順に。
def index_list(date_format = nil, show_title = true)
date_format ||= @date_format;
if(@mode == 'latest')
limit = @conf.latest_limit;
elsif(@mode == 'month')
limit = 31;
else
return '';
end
result = '';
@diaries.keys.sort.send(@mode == 'latest' ? :reverse_each : :each) {|date|
break if(limit <= 0);
diary = @diaries[date];
next unless(diary.visible?);
result << %Q[<p class="recentitem"><a href="##{date}">#{diary.date.strftime(date_format)}</a>\n];
if(show_title && diary.title)
result << %Q[ #{diary.title}];
end
result << %Q[</p>\n<div class="recentsubtitles">\n];
i = 1;
if(!@plugin_files.grep(/\/category.rb$/).empty? && diary.categorizable?)
diary.each_section{|section|
result << section.categories.collect{|c| category_anchor("#{c}")}.join;
result << ' '+section.stripped_subtitle_to_html if(section.stripped_subtitle);
result << "<br>\n";
i += 1;
}
else
diary.each_section{|section|
if(section.subtitle)
result << %Q[#{section.subtitle_to_html}<br>\n];
end
i += 1;
}
end
result << "</div>\n";
limit -= 1;
}
return apply_plugin(result);
end
↓recent_update.rb
# recent_update.rb
#
# 「追記」「編集」時に、日記の日付と実際の時刻を記録。
# プラグインで最近更新された日記を表示。
# [2005-04-20] 表示数の制限がきいてなかったのを修正。
def recent_update(limit=5)
result = '';
uplist = RecentUpdateCache.new(@cache_path);
uplist.each{|d, up, ar|
break if(limit == 0);
date = d.strftime('%Y%m%d');
result << %Q[<p class="recentitem"><a href="#{@index}#{anchor date}">#{d.strftime('%Y-%m-%d')}</a> <span class="recentupdate_lm">(更新日:#{up.strftime('%Y-%m-%d %H:%M:%S')} /#{ar})</span></p>\n];
limit -= 1;
}
result;
end
add_update_proc(){
uplist = RecentUpdateCache.new(@cache_path);
d = @date;
up = Time.now();
ar = @mode;
uplist.append(d, up, ar);
uplist.save(30);
}
class RecentUpdateCache
def initialize(cache_path)
@path = File.join(cache_path, 'recent_update');
@update_list = [];
begin
File.open(@path, 'r') {|f|
f.each_line{|line| line.chomp!;
date, up_date, ar = line.split(/\s*,\s*/);
date = Time.local($1, $2, $3) if(date =~ /(\d{4})-(\d{2})-(\d{2})/);
up_date = Time.local($1, $2, $3, $4, $5, $6) if(up_date =~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/);
@update_list.push([date, up_date, ar]);
}
}
rescue
end
end
def append(d, up, ar)
@update_list.unshift([d, up,ar]);
end
def save(limit=-1)
begin
File.open(@path, 'w'){|f|
@update_list.each(){|d, up, ar|
break if(0 == limit);
d = d.strftime('%Y-%m-%d') if(d.kind_of?(Time));
up = up.strftime('%Y-%m-%d %H:%M:%S') if(up.kind_of?(Time));
f.puts([d,up,ar].join(','));
limit -= 1;
}
}
rescue
end
end
def each(&block)
@update_list.each{|d, up, ar| yield(d, up, ar) }
end
end
昇順降順を考慮するように(index_list.rb)。表示数の制限が効いてない(recent_update.rb)。