mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 06:28:57 +08:00
UX: Replace heuristic solution for extracting root domain.
This commit is contained in:
parent
3e9c3f6f13
commit
8491c5fba5
1
Gemfile
1
Gemfile
|
@ -28,6 +28,7 @@ end
|
|||
gem 'mail'
|
||||
gem 'mime-types', require: 'mime/types/columnar'
|
||||
gem 'mini_mime'
|
||||
gem 'mini_suffix'
|
||||
|
||||
gem 'hiredis'
|
||||
gem 'redis', require: ["redis", "redis/connection/hiredis"]
|
||||
|
|
|
@ -177,6 +177,8 @@ GEM
|
|||
mini_portile2 (2.3.0)
|
||||
mini_racer (0.1.11)
|
||||
libv8 (~> 5.7)
|
||||
mini_suffix (0.1.0)
|
||||
ffi (~> 1.9)
|
||||
minitest (5.10.3)
|
||||
mocha (1.2.1)
|
||||
metaclass (~> 0.0.1)
|
||||
|
@ -451,6 +453,7 @@ DEPENDENCIES
|
|||
mime-types
|
||||
mini_mime
|
||||
mini_racer
|
||||
mini_suffix
|
||||
minitest
|
||||
mocha
|
||||
mock_redis
|
||||
|
|
|
@ -168,17 +168,16 @@ createWidget('topic-map-expanded', {
|
|||
|
||||
const result = [avatars];
|
||||
if (attrs.topicLinks) {
|
||||
|
||||
const toShow = state.allLinksShown ? attrs.topicLinks : attrs.topicLinks.slice(0, LINKS_SHOWN);
|
||||
const links = toShow.map(l => {
|
||||
|
||||
const links = toShow.map(l => {
|
||||
let host = '';
|
||||
|
||||
if (l.title && l.title.length) {
|
||||
const domain = l.domain;
|
||||
if (domain && domain.length) {
|
||||
const s = domain.split('.');
|
||||
if (s[0] === 'www') s.shift();
|
||||
host = h('span.domain', s.join('.'));
|
||||
const rootDomain = l.root_domain;
|
||||
|
||||
if (rootDomain && rootDomain.length) {
|
||||
host = h('span.domain', rootDomain);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ class TopicLinkSerializer < ApplicationSerializer
|
|||
:reflection,
|
||||
:clicks,
|
||||
:user_id,
|
||||
:domain
|
||||
:domain,
|
||||
:root_domain,
|
||||
|
||||
def url
|
||||
object['url']
|
||||
|
@ -50,4 +51,8 @@ class TopicLinkSerializer < ApplicationSerializer
|
|||
object['domain']
|
||||
end
|
||||
|
||||
def root_domain
|
||||
MiniSuffix.domain(domain)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
13
spec/serializers/topic_link_serializer_spec.rb
Normal file
13
spec/serializers/topic_link_serializer_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe TopicLinkSerializer do
|
||||
|
||||
it "correctly serializes the topic link" do
|
||||
post = Fabricate(:post, raw: 'https://meta.discourse.org/')
|
||||
TopicLink.extract_from(post)
|
||||
serialized = described_class.new(post.topic_links.first, root: false).as_json
|
||||
|
||||
expect(serialized[:domain]).to eq("meta.discourse.org")
|
||||
expect(serialized[:root_domain]).to eq("discourse.org")
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user