mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: add a way to map arbitrary urls to a topic, post, or category. Useful for sites that have migrated to Discourse and want to redirect from their old site to Discourse with 301 redirects.
This commit is contained in:
21
app/models/permalink.rb
Normal file
21
app/models/permalink.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class Permalink < ActiveRecord::Base
|
||||
belongs_to :topic
|
||||
belongs_to :post
|
||||
belongs_to :category
|
||||
|
||||
before_validation :normalize_url
|
||||
|
||||
def normalize_url
|
||||
if self.url
|
||||
self.url = self.url.strip
|
||||
self.url = self.url[1..-1] if url[0,1] == '/'
|
||||
end
|
||||
end
|
||||
|
||||
def target_url
|
||||
return post.url if post
|
||||
return topic.relative_url if topic
|
||||
return category.url if category
|
||||
nil
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user