Fixing tests

This commit is contained in:
2023-03-06 21:44:10 +11:00
parent fd3cf2dba1
commit 1ea4224fb5
4 changed files with 34 additions and 19 deletions

View File

@@ -3,6 +3,7 @@ require "digest"
require "tempfile"
require "open-uri"
require "dry/monads"
require "sanitize"
module Adamantium
module Client
@@ -18,7 +19,7 @@ module Adamantium
content = if post[:name]
"#{post[:name]}#{settings.micropub_site_url}/post/#{post[:slug]}"
else
post[:content]
sanitze_post(post[:content])
end
tags = post[:category].map { |tag| "##{tag}" }.join(" ")
@@ -74,6 +75,19 @@ module Adamantium
JSON.parse(response.body, symbolize_names: true).fetch(:id, nil)
end
private
def sanitze_post(content)
replace_links = lambda { |env|
return unless env[:node_name] == "a"
node = env[:node]
url = node[:href]
env[:node].replace(url)
}
Sanitize.fragment(content, transformers: [replace_links]).strip
end
end
end
end