Created
October 10, 2012 21:27
-
-
Save poritsky/3868522 to your computer and use it in GitHub Desktop.
Link Post YAML and Quote for Octopress (Safari Only)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on replaceCommasInStringWithHTMLEntity(theTitle) | |
set rubyCommand to quote & "puts " & "'" & theTitle & "'" & ".gsub( /,/, ',' )" & quote | |
set strippedTitle to do shell script "ruby -e " & rubyCommand | |
return strippedTitle | |
end replaceCommasInStringWithHTMLEntity | |
on stripUTMFromURL(urlToStrip) | |
set rubyCommand to quote & "puts " & "'" & urlToStrip & "'" & ".gsub( /\\?utm.*$/, '' )" & quote | |
set strippedURL to do shell script "ruby -e " & rubyCommand | |
return strippedURL | |
end stripUTMFromURL | |
tell application "Safari" | |
set pageTitle to name of document 1 | |
set currentURL to URL of current tab of window 1 | |
set selectedText to (do JavaScript "window.getSelection().toString()" in document 1) | |
end tell | |
set pageTitle to replaceCommasInStringWithHTMLEntity(pageTitle) | |
set currentURL to stripUTMFromURL(currentURL) | |
set theDate to current date | |
return "---" & " | |
" & "layout: post" & " | |
" & "title: " & "\"" & pageTitle & "\"" & " | |
" & "date: " & (do shell script "date +%Y") & "-" & (do shell script "date +%m") & "-" & (do shell script "date +%d") & " " & (do shell script "date +%H") & ":" & (do shell script "date +%M") & " | |
" & "comments: true" & " | |
" & "categories: " & " | |
" & "- " & " | |
" & "external-url: " & currentURL & " | |
" & "---" & " | |
" & " | |
" & "> " & selectedText |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment