fix #188, add fb import tool

This commit is contained in:
Lorin Werthen 2017-10-11 18:07:13 +02:00
parent 7786d5153a
commit b3a3e36a08
No known key found for this signature in database
GPG key ID: F11FFC921E0E08E0
2 changed files with 32 additions and 1 deletions

View file

@ -31,7 +31,11 @@ For manual deployment, run
bundle exec nanoc deploy --target public
```
## Posts
## Events
Events can be fetched from facebook using `nanoc fetch [facebook event id]`. A file named `.fb_token` containing an app token for facebook must be present.
## Blogposts
Posts should be written in [kramdown](http://kramdown.gettalong.org/index.html), a markdown superset which has a very complete [syntax guide](http://kramdown.gettalong.org/syntax.html).

27
commands/fetch.rb Normal file
View file

@ -0,0 +1,27 @@
# frozen_string_literal: true
require 'net/http'
require 'json'
usage 'fetch [facebook event id]'
aliases :f
summary 'Fetch an event from facebook'
description 'Fetch an event from facebook'
run do |_opts, args, _cmd|
fb_token = File.read('.fb_token')
uri = URI("https://graph.facebook.com/v2.10/#{args[0]}?fields=cover,name,description,start_time,place,end_time&access_token=#{fb_token}")
o = JSON.parse(Net::HTTP.get(uri))
puts <<~EOS
---
title: "#{o['name']}"
time: #{o['start_time']}
location: #{o['place']['name']}
end: #{o['end_time']}
banner: #{o['cover']['source']}
---
#{o['description']}
EOS
end