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)) html_text = wrap_anchors_in_object_tags(replace_urls_with_anchors(content))
res = Sanitize.fragment(html_text, res = Sanitize.fragment(html_text,
elements: ["img", "p", "object", "a"], 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 res.gsub(prefix_emoji[0], "") if prefix_emoji
end end
def raw_content def raw_content
res = Sanitize.fragment(content) rendered_content
res.gsub(prefix_emoji[0], "") if prefix_emoji
end end
def excerpt def excerpt
@@ -188,7 +187,8 @@ module Main
url_regex = %r{(?<!<a href="|img src="|video src=")(https?://[^\s]+)(?![^<>]*(</a>|/>))} url_regex = %r{(?<!<a href="|img src="|video src=")(https?://[^\s]+)(?![^<>]*(</a>|/>))}
text.gsub(url_regex) do |url| 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
end end

View File

@@ -10,13 +10,11 @@ module Main
module Decorators module Decorators
module Statuses module Statuses
class Decorator < Main::Decorators::Posts::Decorator class Decorator < Main::Decorators::Posts::Decorator
REGEXP = URI::DEFAULT_PARSER.make_regexp
def raw_content def raw_content
html_text = wrap_anchors_in_object_tags(replace_urls_with_anchors(content)) html_text = wrap_anchors_in_object_tags(replace_urls_with_anchors(content))
res = Sanitize.fragment(html_text, res = Sanitize.fragment(html_text,
elements: ["img", "p", "object", "a"], 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 res.gsub(prefix_emoji[0], "") if prefix_emoji
end end
@@ -27,7 +25,8 @@ module Main
url_regex = %r{(?<!<a href="|img src="|video src=")(https?://[^\s]+)(?![^<>]*(</a>|/>))} url_regex = %r{(?<!<a href="|img src="|video src=")(https?://[^\s]+)(?![^<>]*(</a>|/>))}
text.gsub(url_regex) do |url| 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
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 - 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="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" 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" span class="e-content status-body"
- if latest_status.key_image - if latest_status.key_image
img loading="lazy" class="float-start max-w-32 rounded mr-2" src=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 def display_title
title = name title = name
if prefix_emoji if prefix_emoji
return "#{prefix_emoji} #{title}" "#{prefix_emoji} #{title}"
else else
return title title
end end
end end