REFACTOR: All kinds of permalinks should return relative URLs

Mixing relative and absolute URLs is unnecessary and confusing.
This commit is contained in:
Gerhard Schlager
2024-05-27 21:30:19 +02:00
committed by Gerhard Schlager
parent 4e80c9eb13
commit 387e906610
5 changed files with 124 additions and 71 deletions

View File

@@ -946,6 +946,8 @@ class Category < ActiveRecord::Base
end
end
alias_method :relative_url, :url
# If the name changes, try and update the category definition topic too if it's an exact match
def rename_category_definition
return if topic.blank?

View File

@@ -72,11 +72,11 @@ class Permalink < ActiveRecord::Base
def target_url
return external_url if external_url
return "#{Discourse.base_path}#{post.url}" if post
return post.relative_url if post
return topic.relative_url if topic
return category.url if category
return tag.full_url if tag
return user.full_url if user
return category.relative_url if category
return tag.relative_url if tag
return user.relative_url if user
nil
end

View File

@@ -210,6 +210,8 @@ class Tag < ActiveRecord::Base
"#{Discourse.base_path}/tag/#{UrlHelper.encode_component(self.name)}"
end
alias_method :relative_url, :url
def full_url
"#{Discourse.base_url}/tag/#{UrlHelper.encode_component(self.name)}"
end

View File

@@ -1779,6 +1779,10 @@ class User < ActiveRecord::Base
username_lower == User.normalize_username(another_username)
end
def relative_url
"#{Discourse.base_path}/u/#{encoded_username}"
end
def full_url
"#{Discourse.base_url}/u/#{encoded_username}"
end