UX: Replace heuristic solution for extracting root domain.

This commit is contained in:
Guo Xiang Tan 2017-11-29 16:24:27 +08:00
parent 3e9c3f6f13
commit 8491c5fba5
5 changed files with 29 additions and 8 deletions

View File

@ -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"]

View File

@ -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

View File

@ -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);
}
}

View File

@ -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

View 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