はてなブックマークへの追加ボタンな tDiary プラグインが欲しくなったので、
大野
http://elpeo.jp/diary/
に作ってもらった。
# hbadd.rb unless @conf.mobile_agent? || /^append|replace|comment|showcomment|trackbackreceive|pingbackreceive$/ =~ @mode then def title_text( subtitle ) old_apply_plugin = @conf['apply_plugin'] @conf['apply_plugin'] = true r = apply_plugin( subtitle.sub( @conf.section_anchor, '' ), true ) @conf['apply_plugin'] = old_apply_plugin NKF::nkf( '-m0 -Ew', r ).strip end def permalink( date, index ) ymd = date.strftime( "%Y%m%d" ) uri = @conf.index.dup uri[0, 0] = @conf.base_url unless %r|^https?://|i =~ uri uri.gsub!( %r|/\./|, '/' ) uri + anchor( "#{ymd}p%02d" % index ) end add_subtitle_proc do |date, index, subtitle| t = title_text( subtitle + " - #{@conf.html_title.gsub(/"/, '\\"')} (#{@date.strftime('%Y-%m-%d')})"); p = permalink( date, index ) r = subtitle.dup r << %Q[<a href="http://b.hatena.ne.jp/add?mode=confirm&title=#{CGI::escape(t)}&url=#{CGI::escape(p)}">] r << %Q[<img src="http://b.hatena.ne.jp/images/append.gif" style="border: none;vertical-align: middle;" title="ブックマークを追加" alt="ブックマークを追加" width="16" height="12" />] r << %Q[</a>] end end
いい感じ。
hbadd.rb
http://elpeo.jp/diary/20070714.html#p02
なおしてみた。
# hbadd.rb unless @conf.mobile_agent? || /^append|replace|comment|showcomment|trackbackreceive|pingbackreceive$/ =~ @mode then def title_text( subtitle, title ) old_apply_plugin = @conf['apply_plugin'] @conf['apply_plugin'] = true r = apply_plugin( subtitle.sub( @conf.section_anchor, '' ), true ) @conf['apply_plugin'] = old_apply_plugin NKF::nkf( '-m0 -Ew', "#{r.strip} - #{title}" ) end def permalink( date, index, escape = true) ymd = date.strftime( "%Y%m%d" ) uri = @conf.index.dup uri[0, 0] = @conf.base_url unless %r|^https?://|i =~ uri uri.gsub!( %r|/\./|, '/' ) if escape uri + CGI::escape(anchor( "#{ymd}p%02d" % index )) else uri + anchor( "#{ymd}p%02d" % index ) end end add_subtitle_proc do |date, index, subtitle| t = title_text( subtitle, "#{@conf.html_title} (#{date.strftime('%Y-%m-%d')})" ) p = permalink( date, index, false ) r = subtitle.dup r << %Q[<a href="http://b.hatena.ne.jp/add?mode=confirm&title=#{CGI::escape(t)}&url=#{CGI::escape(p)}">] r << %Q[<img src="http://b.hatena.ne.jp/images/append.gif" style="border: none;vertical-align: middle;"] r << %Q[ title="ブックマークを追加" alt="ブックマークを追加" width="16" height="12" />] r << %Q[</a>] r << %Q[<a href="http://b.hatena.ne.jp/entry/#{permalink( date, index )}">] r << %Q[<img src="http://b.hatena.ne.jp/entry/image/#{permalink( date, index )}"] r << %Q[ style="border: none;vertical-align: middle;">] r << %Q[</a>] end end