mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:19:27 +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:
parent
cc1e73b8e4
commit
9b200aba16
|
@ -11,6 +11,16 @@ export function addFeaturedLinkMetaDecorator(decorator) {
|
|||
export function extractLinkMeta(topic) {
|
||||
const href = topic.get("featured_link");
|
||||
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) {
|
||||
return;
|
||||
|
@ -19,8 +29,8 @@ export function extractLinkMeta(topic) {
|
|||
const meta = {
|
||||
target: target,
|
||||
href,
|
||||
domain: topic.get("featured_link_root_domain"),
|
||||
rel: "nofollow ugc",
|
||||
domain: domain,
|
||||
rel: rel,
|
||||
};
|
||||
|
||||
if (_decorators.length) {
|
||||
|
|
|
@ -259,6 +259,45 @@ acceptance("Topic", function (needs) {
|
|||
assert.ok(exists(".category-moderator"), "it has a class applied");
|
||||
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) {
|
||||
await visit("/t/test-pm/34");
|
||||
|
|
|
@ -4648,6 +4648,7 @@ export default {
|
|||
pinned_at: null,
|
||||
pinned_until: null,
|
||||
featured_link: "http://www.example.com/has-title.html",
|
||||
featured_link_root_domain: "example.com",
|
||||
details: {
|
||||
auto_close_at: null,
|
||||
auto_close_hours: null,
|
||||
|
|
|
@ -47,6 +47,7 @@ required:
|
|||
default: ""
|
||||
type: group
|
||||
exclude_rel_nofollow_domains:
|
||||
client: true
|
||||
default: ""
|
||||
type: list
|
||||
list_type: simple
|
||||
|
|
Loading…
Reference in New Issue
Block a user