# coding: utf-8 # # sections_of_a_category.rb # # shows links to the sections which have the same category. #add_section_leave_proc{|date, section_index| add_body_leave_proc{|date, section_index| diary = @diaries[date.strftime('%Y%m%d')]; next unless diary; next unless diary.categorizable?; sections_with_sanchor = []; diary.each_section(&lambda{|sanchor_fmt| return lambda{|_| sections_with_sanchor.push([_, sanchor_fmt%(1+sections_with_sanchor.length)]); }; }.call(date.strftime("%Y%m%dp%%02d"))); sections_with_sanchor = sections_with_sanchor.slice(section_index-1, 1) if section_index; categorized_sanchor_of_myself = {} #=> {'category'=>[sanchor,...],...} sections_with_sanchor.each{|section, sanchor| section.categories.each{|c| (categorized_sanchor_of_myself[c]||=[]).push(sanchor); } } sections_with_sanchor = nil; next if categorized_sanchor_of_myself.empty?; categorized_data = {} #=> {"category"=>[[sanchor, subtitle],...],...} each value is sorted by sanchor. @category_cache.categorize(categorized_sanchor_of_myself.keys, @years).each{|c, data| mydata = categorized_data[c] = []; data.keys.sort.each{|ymd| sanchor_fmt = "#{ymd}p%02d"; mydata.concat(data[ymd].sort_by{|a| a[0] }.map{|sidx, subtitle,| [sanchor_fmt%sidx, subtitle] }); } }; select_bestNitems_around_me = lambda{|data, num_of_entries, me| index_of_me = []; (0...data.length).each{|i| break index_of_me.push(i) if data[i][0] == me.first; } return 0...0 if index_of_me.empty?; (index_of_me[0]...data.length).each{|i| break index_of_me.push(i) if data[i][0] == me.last; } return 0...0 if index_of_me.length == 1; start = [index_of_me.first - num_of_entries/2, 0].max; last = [index_of_me.last + num_of_entries/2, data.length].min; start = [[last - num_of_entries + 1, 0].max, start].min; last = [[start + num_of_entries, data.length].min, last].max; start = [[last - num_of_entries, 0].max, start].min; return start..(last-1); }; categorylist_item = lambda{|c, url| r = %Q(カテゴリ[#{h c}]の他の日記); r = %Q(#{r}); return r; }; sectionlist_item = lambda{|sanchor, subtitle, me| params = /\A(\d{4})(\d\d)(\d\d)p(\d+)/.match(sanchor).to_a.values_at(1,2,3,4).map(&:to_i) + [apply_plugin(subtitle, true)]; format = %Q(%d年%2d月%2d日p%02d %s); item = format % params; return me.include?(sanchor) ? item : my(sanchor, item); }; r = %Q(
\n); r << %Q(

See also...

\n); r << %Q(

#{kw 'plugin:sections_of_a_category.rb','listed by...'}

\n
\n); } if @category_cache and @mode == 'day';