-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
68 lines (52 loc) · 1.68 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'nokogiri'
require 'set'
desc "Put HTML of latest issue on clipboard for pasting into tinyletter"
task :tl do
# Generate the site
system("bundle exec jekyll b")
# Find the latest post
last_issue = Dir.glob('_site/[0-9][0-9][0-9].html').
map {|f| File.basename(f, '.*') }.
map(&:to_i).
sort.
last
puts "Copying HTML of issue #{last_issue} to the clipboard"
fn = File.join(File.dirname(__FILE__), '_site', "#{last_issue}.html")
# Extract the HTML content
doc = Nokogiri::HTML(open(fn))
content = doc.xpath('//div[@class="post-content"]').first.inner_html
# Copy to clipboard
IO.popen('pbcopy', 'w') { |f| f << content }
end
desc "Get recent bookmarks from pinboard"
task :pins do
require 'open-uri'
require 'date'
require 'dotenv'
Dotenv.load
date = ENV['SINCE'] || (Date.today - 30).to_s
since = Date.parse(date)
(since..Date.today).reverse_each do |date|
url = "https://api.pinboard.in/v1/posts/get?tag=waw&dt=#{date.to_s}"
doc = Nokogiri::XML(open(url, http_basic_authentication: [ENV['PINBOARD_USER'], ENV['PINBOARD_PASSWORD']]))
posts = doc.xpath('//post')
posts.each do |post|
title = post.attribute('description').value
link = post.attribute('href').value
body = post.attribute('extended').value
title = title.empty? ? 'No title' : title
body = body.empty? ? 'No body' : body
puts "- [#{title}](#{link}): #{body}"
end
end
end
def all_links
links = Set.new
Dir.glob('_site/*.html').each do |fn|
doc = Nokogiri::XML(open(fn))
doc.xpath('//a').map do |link|
links << link.attribute('href').value
end
end
links
end