Syndicate code posts to Github Gists

This commit is contained in:
2024-03-05 20:34:34 +11:00
parent 56edde6ab5
commit 97c05d3f86
11 changed files with 84 additions and 2 deletions

View File

@@ -36,6 +36,7 @@ module Adamantium
"syndication.dayone",
"syndication.mastodon",
"syndication.blue_sky",
"syndication.gist",
"syndication.raindrop",
"view_cache.cacher",
"renderers.markdown"

View File

@@ -3,5 +3,6 @@ Hanami.app.register_provider :clients, namespace: true do
register "mastodon", Adamantium::Client::Mastodon.new
register "blue_sky", Adamantium::Client::BlueSky.new
register "omdb", Adamantium::Client::Omdb.new(api_key: target["settings"].omdb_api_key)
register "gist", Adamantium::Client::Gist.new(token: target["settings"].gist_client_token)
end
end

View File

@@ -1,6 +1,7 @@
Hanami.app.register_provider :syndication, namespace: true do
start do
register "mastodon", Adamantium::Syndication::Mastodon.new
register "gist", Adamantium::Syndication::Gist.new
register "blue_sky", Adamantium::Syndication::BlueSky.new
register "raindrop", Adamantium::Syndication::Raindrop.new(api_key: "Bearer #{target["settings"].raindrop_api_key}")
register "dayone", Adamantium::Syndication::Dayone.new(

View File

@@ -72,5 +72,7 @@ module Adamantium
setting :sentry_dsn, default: nil
setting :raise_exceptions, default: true
setting :gist_client_token, default: nil
end
end

4
config/taglines.yaml Normal file
View File

@@ -0,0 +1,4 @@
taglines:
- lord of the dance
- would that it were so simple
- "*furious hand gestures*"

View File

@@ -0,0 +1,31 @@
require "httparty"
module Adamantium
module Client
class Gist
include Dry::Monads[:result]
def initialize(token:)
@token = token
end
def create_gist(description:, public:, files: {})
request_body = {
description: description,
public: public,
files: files
}
res = HTTParty.post("https://api.github.com/gists",
body: JSON.generate(request_body),
headers: {Authorization: "Bearer #{@token}"})
if res.code >= 200 && res.code < 400
Success(res["html_url"])
else
Failure(:could_not_save_gist)
end
end
end
end
end

View File

@@ -0,0 +1,23 @@
require "dry/monads"
require "sanitize"
module Adamantium
module Syndication
class Gist
include Dry::Monads[:result]
include Deps[gist_client: "clients.gist"]
def call(post:)
description = ""
public = true
files = {
post[:name] => {content: Sanitize.fragment(post[:content])}
}
gist_client.create_gist(description: description,
public: public,
files: files)
end
end
end
end

View File

@@ -0,0 +1,3 @@
- w_class = defined?(width) ? width : "w-6"
<svg class="fill-grey-900 hover:fill-grey-600 #{w_class}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M186.1 328.7c0 20.9-10.9 55.1-36.7 55.1s-36.7-34.2-36.7-55.1 10.9-55.1 36.7-55.1 36.7 34.2 36.7 55.1zM480 278.2c0 31.9-3.2 65.7-17.5 95-37.9 76.6-142.1 74.8-216.7 74.8-75.8 0-186.2 2.7-225.6-74.8-14.6-29-20.2-63.1-20.2-95 0-41.9 13.9-81.5 41.5-113.6-5.2-15.8-7.7-32.4-7.7-48.8 0-21.5 4.9-32.3 14.6-51.8 45.3 0 74.3 9 108.8 36 29-6.9 58.8-10 88.7-10 27 0 54.2 2.9 80.4 9.2 34-26.7 63-35.2 107.8-35.2 9.8 19.5 14.6 30.3 14.6 51.8 0 16.4-2.6 32.7-7.7 48.2 27.5 32.4 39 72.3 39 114.2zm-64.3 50.5c0-43.9-26.7-82.6-73.5-82.6-18.9 0-37 3.4-56 6-14.9 2.3-29.8 3.2-45.1 3.2-15.2 0-30.1-.9-45.1-3.2-18.7-2.6-37-6-56-6-46.8 0-73.5 38.7-73.5 82.6 0 87.8 80.4 101.3 150.4 101.3h48.2c70.3 0 150.6-13.4 150.6-101.3zm-82.6-55.1c-25.8 0-36.7 34.2-36.7 55.1s10.9 55.1 36.7 55.1 36.7-34.2 36.7-55.1-10.9-55.1-36.7-55.1z"/></svg>

View File

@@ -29,6 +29,10 @@ module Micropub
{
uid: "https://bsky.social",
name: "Blue Sky"
},
{
uid: "https://gist.github.com",
name: "Gist"
}
]
}.to_json
@@ -44,6 +48,10 @@ module Micropub
{
uid: "https://bsky.social",
name: "Blue Sky"
},
{
uid: "https://gist.github.com",
name: "Gist"
}
]
}.to_json

View File

@@ -15,7 +15,7 @@ module Micropub
post_params = prepare_params(params: post)
created_post = post_repo.create(post_params)
# syndicate.call(created_post.id, post)
syndicate.call(created_post.id, post)
# decorated_post = Decorators::Posts::Decorator.new(created_post)

View File

@@ -11,6 +11,7 @@ module Micropub
include Deps["settings",
"syndication.mastodon",
"syndication.blue_sky",
"syndication.gist",
add_post_syndication_source: "commands.posts.add_syndication_source",
send_to_dayone: "syndication.dayone",
]
@@ -30,7 +31,13 @@ module Micropub
add_post_syndication_source.call(post_id, :blue_sky, res.value!) if res.success?
end
if post[:category].include? "weekly"
if syndicate_to.include? :gist
res = gist.call(post: post)
add_post_syndication_source.call(post_id, :gist, res.value!) if res.success?
end
if post[:category]&.include? "weekly"
send_to_dayone.call(name: post[:name], content: post[:content])
end
@@ -43,6 +50,7 @@ module Micropub
targets = []
targets << :mastodon if syndicate_to.any? { |url| settings.mastodon_server.match(/#{url}/) }
targets << :blue_sky if syndicate_to.any? { |url| settings.blue_sky_url.match(/#{url}/) }
targets << :gist if syndicate_to.any? { |url| "https://gist.github.com".match(/#{url}/) }
targets
end
end