Module: Jekyll::MastodonSocial
- Defined in:
- lib/mastodon-social.rb,
lib/jekyll/generators/gather_posse.rb,
lib/jekyll/commands/mastodon-social.rb
Defined Under Namespace
Classes: Error, GatherPosse, MastodonSetup
Class Attribute Summary collapse
-
.bearer_token ⇒ Object
Returns the value of attribute bearer_token.
-
.client_id ⇒ Object
Returns the value of attribute client_id.
-
.client_secret ⇒ Object
Returns the value of attribute client_secret.
-
.config ⇒ Object
readonly
Returns the value of attribute config.
-
.mastodon_status ⇒ Object
readonly
Returns the value of attribute mastodon_status.
-
.site ⇒ Object
readonly
Returns the value of attribute site.
Class Method Summary collapse
- .clear_status ⇒ Object
-
.mark_as_published(post, mastodon_status) ⇒ Object
mastodon_status is one of: nil: this post has not been sent to mastodon true: This post has been sent as a status, but we have no url url: The Mastodon URL for the status linking this post.
- .save_config ⇒ Object
-
.setup(site) ⇒ Object
Load state from cache dir.
- .setup_config ⇒ Object
- .syndication_info(url) ⇒ Object
Class Attribute Details
.bearer_token ⇒ Object
Returns the value of attribute bearer_token.
13 14 15 |
# File 'lib/mastodon-social.rb', line 13 def bearer_token @bearer_token end |
.client_id ⇒ Object
Returns the value of attribute client_id.
13 14 15 |
# File 'lib/mastodon-social.rb', line 13 def client_id @client_id end |
.client_secret ⇒ Object
Returns the value of attribute client_secret.
13 14 15 |
# File 'lib/mastodon-social.rb', line 13 def client_secret @client_secret end |
.config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/mastodon-social.rb', line 14 def config @config end |
.mastodon_status ⇒ Object (readonly)
Returns the value of attribute mastodon_status.
14 15 16 |
# File 'lib/mastodon-social.rb', line 14 def mastodon_status @mastodon_status end |
.site ⇒ Object (readonly)
Returns the value of attribute site.
14 15 16 |
# File 'lib/mastodon-social.rb', line 14 def site @site end |
Class Method Details
.clear_status ⇒ Object
88 89 90 |
# File 'lib/mastodon-social.rb', line 88 def clear_status @mastodon_status = {} end |
.mark_as_published(post, mastodon_status) ⇒ Object
mastodon_status is one of: nil: this post has not been sent to mastodon true: This post has been sent as a status, but we have no url url: The Mastodon URL for the status linking this post
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/mastodon-social.rb', line 60 def mark_as_published(post, mastodon_status) if post.kind_of? String post_url = post excerpt = '' = nil else # Don't do anything with posts that are in _drafts return if post.path.include? '_drafts' post_url = post.url excerpt_html = post.data['excerpt'].to_s excerpt = Nokogiri::HTML(excerpt_html).text.strip = post.data['hashtags'] = .split if .is_a? String end status = @mastodon_status[post_url] if status.nil? @mastodon_status[post_url] = { mastodon_status: mastodon_status, excerpt: excerpt, hashtags: } else status[:mastodon_status] = mastodon_status @mastodon_status[post_url] = status end end |
.save_config ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mastodon-social.rb', line 44 def save_config state = { posts: @mastodon_status || {}, bearer_token: @bearer_token, client_id: @client_id, client_secret: @client_secret } File.open(@mastodon_cachefile, "wb") { |f| f.puts YAML.dump(state) } end |
.setup(site) ⇒ Object
Load state from cache dir. Setup cache dir if it doesn’t exist
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mastodon-social.rb', line 17 def setup(site) @site = site @jekyll_config = site.config @config = @jekyll_config["mastodon-syndication"] || {} # Set up the cache folder & files setup_config cache_data = YAML.load_file(@mastodon_cachefile) @mastodon_status = cache_data[:posts] @bearer_token = cache_data[:bearer_token] @client_id = cache_data[:client_id] @client_secret = cache_data[:client_secret] @mastodon_client = Mastodon::REST::Client.new(base_url: @config["server"], bearer_token: @bearer_token) end |
.setup_config ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/mastodon-social.rb', line 34 def setup_config @cache_folder = @site.in_source_dir(@config["cache-folder"] || ".jekyll-cache") unless File.exist?(@cache_folder) Dir.mkdir(@cache_folder) end file = Jekyll.sanitized_path(@cache_folder, "mastodon.yml") File.open(file, "wb") { |f| f.puts YAML.dump(Hash.new) } unless File.exist? file @mastodon_cachefile = file end |
.syndication_info(url) ⇒ Object
92 93 94 95 96 |
# File 'lib/mastodon-social.rb', line 92 def (url) status = @mastodon_status[url] return nil unless (status.kind_of? Hash and status[:mastodon_status].kind_of? Hash) status[:mastodon_status] end |