mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +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 'mail'
|
||||||
gem 'mime-types', require: 'mime/types/columnar'
|
gem 'mime-types', require: 'mime/types/columnar'
|
||||||
gem 'mini_mime'
|
gem 'mini_mime'
|
||||||
|
gem 'mini_suffix'
|
||||||
|
|
||||||
gem 'hiredis'
|
gem 'hiredis'
|
||||||
gem 'redis', require: ["redis", "redis/connection/hiredis"]
|
gem 'redis', require: ["redis", "redis/connection/hiredis"]
|
||||||
|
|
|
@ -177,6 +177,8 @@ GEM
|
||||||
mini_portile2 (2.3.0)
|
mini_portile2 (2.3.0)
|
||||||
mini_racer (0.1.11)
|
mini_racer (0.1.11)
|
||||||
libv8 (~> 5.7)
|
libv8 (~> 5.7)
|
||||||
|
mini_suffix (0.1.0)
|
||||||
|
ffi (~> 1.9)
|
||||||
minitest (5.10.3)
|
minitest (5.10.3)
|
||||||
mocha (1.2.1)
|
mocha (1.2.1)
|
||||||
metaclass (~> 0.0.1)
|
metaclass (~> 0.0.1)
|
||||||
|
@ -451,6 +453,7 @@ DEPENDENCIES
|
||||||
mime-types
|
mime-types
|
||||||
mini_mime
|
mini_mime
|
||||||
mini_racer
|
mini_racer
|
||||||
|
mini_suffix
|
||||||
minitest
|
minitest
|
||||||
mocha
|
mocha
|
||||||
mock_redis
|
mock_redis
|
||||||
|
|
|
@ -168,17 +168,16 @@ createWidget('topic-map-expanded', {
|
||||||
|
|
||||||
const result = [avatars];
|
const result = [avatars];
|
||||||
if (attrs.topicLinks) {
|
if (attrs.topicLinks) {
|
||||||
|
|
||||||
const toShow = state.allLinksShown ? attrs.topicLinks : attrs.topicLinks.slice(0, LINKS_SHOWN);
|
const toShow = state.allLinksShown ? attrs.topicLinks : attrs.topicLinks.slice(0, LINKS_SHOWN);
|
||||||
const links = toShow.map(l => {
|
|
||||||
|
|
||||||
|
const links = toShow.map(l => {
|
||||||
let host = '';
|
let host = '';
|
||||||
|
|
||||||
if (l.title && l.title.length) {
|
if (l.title && l.title.length) {
|
||||||
const domain = l.domain;
|
const rootDomain = l.root_domain;
|
||||||
if (domain && domain.length) {
|
|
||||||
const s = domain.split('.');
|
if (rootDomain && rootDomain.length) {
|
||||||
if (s[0] === 'www') s.shift();
|
host = h('span.domain', rootDomain);
|
||||||
host = h('span.domain', s.join('.'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,8 @@ class TopicLinkSerializer < ApplicationSerializer
|
||||||
:reflection,
|
:reflection,
|
||||||
:clicks,
|
:clicks,
|
||||||
:user_id,
|
:user_id,
|
||||||
:domain
|
:domain,
|
||||||
|
:root_domain,
|
||||||
|
|
||||||
def url
|
def url
|
||||||
object['url']
|
object['url']
|
||||||
|
@ -50,4 +51,8 @@ class TopicLinkSerializer < ApplicationSerializer
|
||||||
object['domain']
|
object['domain']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def root_domain
|
||||||
|
MiniSuffix.domain(domain)
|
||||||
|
end
|
||||||
|
|
||||||
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