More status link cleanup

This commit is contained in:
Daniel Nitsikopoulos
2024-10-19 20:00:51 +11:00
parent e3aabfe28b
commit 8011000ce8
4 changed files with 10 additions and 11 deletions

View File

@@ -117,13 +117,12 @@ module Main
html_text = wrap_anchors_in_object_tags(replace_urls_with_anchors(content))
res = Sanitize.fragment(html_text,
elements: ["img", "p", "object", "a"],
attributes: {"img" => ["alt", "src", "title"], "a" => ["href"]})
attributes: {"img" => ["alt", "src", "title"], "a" => ["href", "class"]})
res.gsub(prefix_emoji[0], "") if prefix_emoji
end
def raw_content
res = Sanitize.fragment(content)
res.gsub(prefix_emoji[0], "") if prefix_emoji
rendered_content
end
def excerpt
@@ -188,7 +187,8 @@ module Main
url_regex = %r{(?<!<a href="|img src="|video src=")(https?://[^\s]+)(?![^<>]*(</a>|/>))}
text.gsub(url_regex) do |url|
%(<object><a href="#{url}">#{url}</a></object>)
clean_url = Sanitize.fragment(url).gsub(/\s/, "")
%(<a class="hover:underline decoration-wavy" href="#{clean_url}">#{clean_url}</a>)
end
end

View File

@@ -10,13 +10,11 @@ module Main
module Decorators
module Statuses
class Decorator < Main::Decorators::Posts::Decorator
REGEXP = URI::DEFAULT_PARSER.make_regexp
def raw_content
html_text = wrap_anchors_in_object_tags(replace_urls_with_anchors(content))
res = Sanitize.fragment(html_text,
elements: ["img", "p", "object", "a"],
attributes: {"img" => ["alt", "src", "title"], "a" => ["href"]})
attributes: {"img" => ["alt", "src", "title"], "a" => ["href", "class"]})
res.gsub(prefix_emoji[0], "") if prefix_emoji
end
@@ -27,7 +25,8 @@ module Main
url_regex = %r{(?<!<a href="|img src="|video src=")(https?://[^\s]+)(?![^<>]*(</a>|/>))}
text.gsub(url_regex) do |url|
%(<object><a href="#{url}">#{url}</a></object>)
clean_url = Sanitize.fragment(url).gsub(/\s/, "")
%(<a class="hover:underline decoration-wavy" href="#{clean_url}">#{clean_url}</a>)
end
end

View File

@@ -14,7 +14,7 @@ div class="mb-8 max-w-screen-md mx-auto border-t border-solid border-gray-200 da
- if latest_status
div class="h-entry mb-12 p-2 grid grid-cols-7 gap-4 min-h-16 max-w-prose mx-auto bg-fuchsia-100 dark:bg-fuchsia-800 dark:text-gray-200 rounded"
div class="col-span-7 sm:col-span-6 text-left"
a class="u-url block my-auto hover:underline decoration-wavy" href=latest_status.permalink
a class="u-url block my-auto" href=latest_status.permalink
span class="e-content status-body"
- if latest_status.key_image
img loading="lazy" class="float-start max-w-32 rounded mr-2" src=latest_status.key_image

View File

@@ -51,9 +51,9 @@ module Micropub
def display_title
title = name
if prefix_emoji
return "#{prefix_emoji} #{title}"
"#{prefix_emoji} #{title}"
else
return title
title
end
end