mirror of
https://github.com/discourse/discourse.git
synced 2025-06-17 05:02:31 +08:00
FIX: respect nofollow exclusion setting in topic featured links. (#11858)
Previously, nofollow attribute is not removed even when a domain is added to the `exclude_rel_nofollow_domains` site setting.
This commit is contained in:
@ -11,6 +11,16 @@ export function addFeaturedLinkMetaDecorator(decorator) {
|
|||||||
export function extractLinkMeta(topic) {
|
export function extractLinkMeta(topic) {
|
||||||
const href = topic.get("featured_link");
|
const href = topic.get("featured_link");
|
||||||
const target = User.currentProp("external_links_in_new_tab") ? "_blank" : "";
|
const target = User.currentProp("external_links_in_new_tab") ? "_blank" : "";
|
||||||
|
const domain = topic.get("featured_link_root_domain");
|
||||||
|
let allowList = topic.siteSettings.exclude_rel_nofollow_domains;
|
||||||
|
let rel = "nofollow ugc";
|
||||||
|
|
||||||
|
if (allowList) {
|
||||||
|
allowList = allowList.split("|");
|
||||||
|
if (allowList.includes(domain)) {
|
||||||
|
rel = rel.replace("nofollow ", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!href) {
|
if (!href) {
|
||||||
return;
|
return;
|
||||||
@ -19,8 +29,8 @@ export function extractLinkMeta(topic) {
|
|||||||
const meta = {
|
const meta = {
|
||||||
target: target,
|
target: target,
|
||||||
href,
|
href,
|
||||||
domain: topic.get("featured_link_root_domain"),
|
domain: domain,
|
||||||
rel: "nofollow ugc",
|
rel: rel,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_decorators.length) {
|
if (_decorators.length) {
|
||||||
|
@ -259,6 +259,45 @@ acceptance("Topic", function (needs) {
|
|||||||
assert.ok(exists(".category-moderator"), "it has a class applied");
|
assert.ok(exists(".category-moderator"), "it has a class applied");
|
||||||
assert.ok(exists(".d-icon-shield-alt"), "it shows an icon");
|
assert.ok(exists(".d-icon-shield-alt"), "it shows an icon");
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
acceptance("Topic featured links", function (needs) {
|
||||||
|
needs.user();
|
||||||
|
needs.settings({
|
||||||
|
topic_featured_link_enabled: true,
|
||||||
|
max_topic_title_length: 80,
|
||||||
|
exclude_rel_nofollow_domains: "example.com",
|
||||||
|
});
|
||||||
|
|
||||||
|
test("remove nofollow attribute", async function (assert) {
|
||||||
|
await visit("/t/-/299/1");
|
||||||
|
|
||||||
|
const link = queryAll(".title-wrapper .topic-featured-link");
|
||||||
|
assert.equal(link.text(), " example.com");
|
||||||
|
assert.equal(link.attr("rel"), "ugc");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("remove featured link", async function (assert) {
|
||||||
|
await visit("/t/-/299/1");
|
||||||
|
assert.ok(
|
||||||
|
exists(".title-wrapper .topic-featured-link"),
|
||||||
|
"link is shown with topic title"
|
||||||
|
);
|
||||||
|
|
||||||
|
await click(".title-wrapper .edit-topic");
|
||||||
|
assert.ok(
|
||||||
|
exists(".title-wrapper .remove-featured-link"),
|
||||||
|
"link to remove featured link"
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: decide if we want to test this, test is flaky so it
|
||||||
|
// was commented out.
|
||||||
|
// If not fixed by May 2021, delete this code block
|
||||||
|
//
|
||||||
|
//await click(".title-wrapper .remove-featured-link");
|
||||||
|
//await click(".title-wrapper .submit-edit");
|
||||||
|
//assert.ok(!exists(".title-wrapper .topic-featured-link"), "link is gone");
|
||||||
|
});
|
||||||
|
|
||||||
test("Converting to a public topic", async function (assert) {
|
test("Converting to a public topic", async function (assert) {
|
||||||
await visit("/t/test-pm/34");
|
await visit("/t/test-pm/34");
|
||||||
|
@ -4648,6 +4648,7 @@ export default {
|
|||||||
pinned_at: null,
|
pinned_at: null,
|
||||||
pinned_until: null,
|
pinned_until: null,
|
||||||
featured_link: "http://www.example.com/has-title.html",
|
featured_link: "http://www.example.com/has-title.html",
|
||||||
|
featured_link_root_domain: "example.com",
|
||||||
details: {
|
details: {
|
||||||
auto_close_at: null,
|
auto_close_at: null,
|
||||||
auto_close_hours: null,
|
auto_close_hours: null,
|
||||||
|
@ -47,6 +47,7 @@ required:
|
|||||||
default: ""
|
default: ""
|
||||||
type: group
|
type: group
|
||||||
exclude_rel_nofollow_domains:
|
exclude_rel_nofollow_domains:
|
||||||
|
client: true
|
||||||
default: ""
|
default: ""
|
||||||
type: list
|
type: list
|
||||||
list_type: simple
|
list_type: simple
|
||||||
|
Reference in New Issue
Block a user