Save source name when adding syndication target

This commit is contained in:
2024-05-27 20:50:58 +10:00
parent b894fe93fa
commit f5ba90cc89
3 changed files with 80 additions and 51 deletions

View File

@@ -5,7 +5,8 @@ module Micropub
include Deps[
"repos.post_repo",
"renderers.markdown",
"commands.posts.add_syndication_source"
"commands.posts.add_syndication_source",
"queries.posts.syndication_url_to_source"
]
def call(params:)
@@ -31,7 +32,8 @@ module Micropub
if params.key? :add
attrs_to_add = {}
syndication = params[:add].delete(:syndication)&.first
syndication_url = params[:add].delete(:syndication)&.first
syndication_source = syndication_url_to_source.call(url: syndication_url) if syndication_url && !syndication_url.empty?
tags = params[:add].delete(:category)
content = params[:add].delete(:content)&.first
name = params[:add].delete(:name)
@@ -46,7 +48,7 @@ module Micropub
post_repo.update(post.id, attrs_to_add) unless attrs_to_add.empty?
post_repo.tag_post(post_id: post.id, tags: tags) if tags && !tags.empty?
add_syndication_source.call(post.id, "", syndication) if syndication && !syndication.empty?
add_syndication_source.call(post.id, syndication_source, syndication_url) if syndication_url && !syndication_url.empty?
Success()
end

View File

@@ -0,0 +1,21 @@
module Micropub
module Queries
module Posts
class SyndicationUrlToSource
def call(url:)
if url.match("https://social.dnitza.com")
return :mastodon
end
if url.match("https://bsky.social")
return :bluesky
end
if url.match("https://gist.github.com")
return :gist
end
end
end
end
end
end