summaryrefslogtreecommitdiff
path: root/bin/bookmark
diff options
context:
space:
mode:
Diffstat (limited to 'bin/bookmark')
-rwxr-xr-xbin/bookmark14
1 files changed, 10 insertions, 4 deletions
diff --git a/bin/bookmark b/bin/bookmark
index f6d389b..eb22730 100755
--- a/bin/bookmark
+++ b/bin/bookmark
@@ -8,7 +8,7 @@ require 'open-uri'
require 'openssl'
require 'yaml'
-Bookmark = Struct.new(:url, :title, :date, :host)
+Bookmark = Struct.new(:url, :title, :date, :host, :source_url, :source_host)
bookmark = Bookmark.new(date: Time.now.strftime('%Y-%m-%d'))
OptionParser.new do |opts|
opts.banner = 'Usage: bookmark [options]'
@@ -16,21 +16,27 @@ OptionParser.new do |opts|
opts.on('-uURL', '--url=URL', 'Url of the new bookmark') do |n|
bookmark[:url] = n
end
+
+ opts.on('-sURL', '--source=URL', 'Url of the source') do |n|
+ bookmark[:source_url] = n
+ end
end.parse!
bookmark.host = URI.parse(bookmark[:url]).host.gsub(/^www\./, '')
+bookmark.source_host = URI.parse(bookmark[:source_url]).host.gsub(/^www\./, '') if bookmark[:source_url]
URI.parse(bookmark[:url]).open({ ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE }) do |page|
noko = Nokogiri::HTML(page)
- title = noko.xpath('//title').first.content
+ title = noko.xpath('//title').first.content
- # remove known page title craps
- title = case bookmark.host
+ # remove known page title craps
+ title = case bookmark.host
when 'brainbaking.com' then title.gsub(/\s\|\sBrain Baking$/, '')
when 'vermaden.wordpress.com' then title.gsub(/\s\|\s𝚟𝚎𝚛𝚖𝚊𝚍𝚎𝚗$/, '')
when 'youtube.com' then title.gsub(/\s-|\sYouTube$/, '')
when 'blog.thechases.com' then title.gsub(/\s\|\sTim's blog$/, '')
when 'arstechnica.com' then title.gsub(/\s-\sArs Technica$/, '')
+ when 'servethehome.com' then title.gsub(/\s-\sServeTheHome$/, '')
else title
end