Skip to content

Instantly share code, notes, and snippets.

@machu
Created August 14, 2010 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save machu/523944 to your computer and use it in GitHub Desktop.
Save machu/523944 to your computer and use it in GitHub Desktop.
Index: section_footer2.rb
===================================================================
--- section_footer2.rb (revision 38267)
+++ section_footer2.rb (working copy)
@@ -26,6 +26,31 @@
link
end
+unless defined?(subtitle)
+ def subtitle( date, index, escape = true )
+ diary = @diaries[date.strftime( "%Y%m%d" )]
+ return "" unless diary
+ sn = 1
+ diary.each_section do |section|
+ if sn == index
+ old_apply_plugin = @options["apply_plugin"]
+ @options["apply_plugin"] = true
+ title = apply_plugin( section.subtitle_to_html, true )
+ @options["apply_plugin"] = old_apply_plugin
+ title.gsub!( /(?=")/, "\\" ) if escape
+ return title
+ end
+ sn += 1
+ end
+ end
+end
+
+add_header_proc do
+ <<-"EOS"
+ <script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>
+ EOS
+end
+
add_section_enter_proc do |date, index|
@category_to_tag_list = {}
''
@@ -67,6 +92,9 @@
r << parse_sbm_yaml(file, date, index)
end
+ # add Twitter link
+ r << add_twitter(date, index)
+
# add Permalink
r << %Q|<a href="#{permalink(date, index, false)}">Permalink</a> |
@@ -124,6 +152,16 @@
return r
end
+def add_twitter(date, index)
+ r = <<-"EOS"
+ <a href="http://twitter.com/share" class="twitter-share-button"
+ data-url="#{permalink(date, index, false)}"
+ data-text="#{subtitle(date, index)}"
+ data-via="#{@conf['twitter.user']}"
+ >tweet</a> |
+ EOS
+end
+
def parse_sbm_yaml(file, date, index)
config = YAML.load( Pathname.new( file ).expand_path.read )
r = ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment