# link_navi.rb,v 0.0.2 2003/09/23 by 楠見直人さん # origin link_rel.rb by ogiさん # 2003/09/25 微修正。月情報でなく日情報で処理により月内分割の場合も対応のはず =begin link_rel.rb nDiary Plug-in : link rel の挿入 (calenar.rb が元になってます。) ナビが重複する部分がなくなるようにし、ナビゲーション用のリストにも 使えるように機能を追加。月分割ファイルには未対応。 example:
=end def plug(opt) title_format = (opt['title'] or "%Y年%m月の日記") title_latest = (opt['title_latest'] or "最近の日記") if self.kind_of?(LastDiary) or self.kind_of?(Topics) then latest = true elsif self.kind_of?(PastDiary) then latest = false else return end headday = @diaries.sort.first #生成日記に含まれる最前日付 tailday = @diaries.sort.last #生成日記に含まれる最後日付 alldays = @allDiaries.keys.sort #全日記の日付・日付順 firstday = alldays.first #全日記の最前日付 prevday = alldays[alldays.index(headday)-1] #生成日記に含まれない直前日付 nextday = alldays[alldays.index(tailday)+1] #生成日記に含まれない直後日付 # nil だと「そんな日付は無い」の意 link, title, lititle = {}, {}, {} #firstdayを含む生成日記のtitleとfilenameをチェック unless firstday.nil? time = Time.mktime(firstday[0..3].to_i, firstday[4..5].to_i) title['first'] = time.strftime2(title_format) link['first'] = date2monthlyfilelink(firstday) lititle['first'] = 'First' end #prevday(最新日記時はtailday)を含む生成日記のtitleとfilenameをチェック unless prevday.nil? time = Time.mktime(prevday[0..3].to_i, prevday[4..5].to_i) title['previous'] = time.strftime2(title_format) link['previous'] = date2monthlyfilelink(prevday) lititle['previous'] = 'Previous' end if latest && !tailday.nil? time = Time.mktime(tailday[0..3].to_i, tailday[4..5].to_i) title['previous'] = time.strftime2(title_format) link['previous'] = date2monthlyfilelink(tailday) lititle['previous'] = 'Previous' end #nextdayを含む生成日記のtitleとfilenameをチェック unless nextday.nil? time = Time.mktime(nextday[0..3].to_i, nextday[4..5].to_i) title['next'] = time.strftime2(title_format) link['next'] = date2monthlyfilelink(nextday) lititle['next'] = 'Next' end #最新日記のtitleとfilenameをチェック unless latest title['last'] = @title_latest link['last'] = @latestFilename lititle['last'] = 'Latest' end case opt['type'] #出力。optionは「list」と「それ以外(link)」 when 'list' str = "\t" else str = '' ['first', 'previous', 'next','last'].each{ |key| str << "\t\n" unless link[key].nil? } end return str end