notes: convert internal links to Danbooru to relative urls.

This commit is contained in:
evazion
2017-06-16 00:36:31 -05:00
parent 48001c1293
commit 8c7c2a06e5
3 changed files with 28 additions and 2 deletions

View File

@@ -73,7 +73,20 @@ module NoteSanitizer
at_rules: [],
protocols: [],
properties: ALLOWED_PROPERTIES,
}
},
:transformers => method(:relativize_links),
)
end
def self.relativize_links(node:, **env)
return unless node.name == "a" && node.attribute("href")
href = node.attribute("href")
url = Addressable::URI.parse(href.value).normalize
if url.authority.in?(Danbooru.config.hostnames)
url.site = nil
href.value = url.to_s
end
end
end