Skip to content

Commit

Permalink
Adding nofollow to links. Fixes #542
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines committed Jan 11, 2022
1 parent 656f023 commit 7e2b2b2
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 25 deletions.
3 changes: 2 additions & 1 deletion src/shared/components/common/markdown-textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
mdToHtml,
pictrsDeleteToast,
randomStr,
relTags,
setupTippy,
setupTribute,
toast,
Expand Down Expand Up @@ -297,7 +298,7 @@ export class MarkdownTextArea extends Component<
href={markdownHelpUrl}
class="btn btn-sm text-muted font-weight-bold"
title={i18n.t("formatting_help")}
rel="noopener"
rel={relTags}
>
<Icon icon="help-circle" classes="icon-inline" />
</a>
Expand Down
4 changes: 2 additions & 2 deletions src/shared/components/common/sort-select.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, linkEvent } from "inferno";
import { SortType } from "lemmy-js-client";
import { i18n } from "../../i18next";
import { randomStr, sortingHelpUrl } from "../../utils";
import { randomStr, relTags, sortingHelpUrl } from "../../utils";
import { Icon } from "./icon";

interface SortSelectProps {
Expand Down Expand Up @@ -71,7 +71,7 @@ export class SortSelect extends Component<SortSelectProps, SortSelectState> {
<a
className="text-muted"
href={sortingHelpUrl}
rel="noopener"
rel={relTags}
title={i18n.t("sorting_help")}
>
<Icon icon="help-circle" classes="icon-inline" />
Expand Down
3 changes: 2 additions & 1 deletion src/shared/components/community/community-link.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from "inferno";
import { Link } from "inferno-router";
import { CommunitySafe } from "lemmy-js-client";
import { hostname, showAvatars } from "../../utils";
import { hostname, relTags, showAvatars } from "../../utils";
import { PictrsImage } from "../common/pictrs-image";

interface CommunityLinkProps {
Expand Down Expand Up @@ -48,6 +48,7 @@ export class CommunityLink extends Component<CommunityLinkProps, any> {
title={apubName}
className={`${this.props.muted ? "text-muted" : ""}`}
href={link}
rel={relTags}
>
{this.avatarAndName(displayName)}
</a>
Expand Down
3 changes: 2 additions & 1 deletion src/shared/components/community/community.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
getPageFromProps,
getSortTypeFromProps,
notifyPost,
relTags,
restoreScrollPosition,
saveCommentRes,
saveScrollPosition,
Expand Down Expand Up @@ -371,7 +372,7 @@ export class Community extends Component<any, State> {
this.state.sort
)}
title="RSS"
rel="noopener"
rel={relTags}
>
<Icon icon="rss" classes="text-muted small" />
</a>
Expand Down
7 changes: 4 additions & 3 deletions src/shared/components/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
mdToHtml,
notifyPost,
numToSI,
relTags,
restoreScrollPosition,
saveCommentRes,
saveScrollPosition,
Expand Down Expand Up @@ -690,7 +691,7 @@ export class Home extends Component<any, HomeState> {
{this.state.listingType == ListingType.All && (
<a
href={`/feeds/all.xml?sort=${this.state.sort}`}
rel="noopener"
rel={relTags}
title="RSS"
>
<Icon icon="rss" classes="text-muted small" />
Expand All @@ -699,7 +700,7 @@ export class Home extends Component<any, HomeState> {
{this.state.listingType == ListingType.Local && (
<a
href={`/feeds/local.xml?sort=${this.state.sort}`}
rel="noopener"
rel={relTags}
title="RSS"
>
<Icon icon="rss" classes="text-muted small" />
Expand All @@ -710,7 +711,7 @@ export class Home extends Component<any, HomeState> {
<a
href={`/feeds/front/${UserService.Instance.auth}.xml?sort=${this.state.sort}`}
title="RSS"
rel="noopener"
rel={relTags}
>
<Icon icon="rss" classes="text-muted small" />
</a>
Expand Down
4 changes: 2 additions & 2 deletions src/shared/components/home/instances.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from "inferno";
import { GetSiteResponse } from "lemmy-js-client";
import { i18n } from "../../i18next";
import { setIsoData } from "../../utils";
import { relTags, setIsoData } from "../../utils";
import { HtmlTags } from "../common/html-tags";

interface InstancesState {
Expand Down Expand Up @@ -60,7 +60,7 @@ export class Instances extends Component<any, InstancesState> {
<ul>
{items.map(i => (
<li>
<a href={`https://${i}`} rel="noopener">
<a href={`https://${i}`} rel={relTags}>
{i}
</a>
</li>
Expand Down
3 changes: 2 additions & 1 deletion src/shared/components/person/inbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
editCommentRes,
fetchLimit,
isBrowser,
relTags,
saveCommentRes,
setIsoData,
setupTippy,
Expand Down Expand Up @@ -159,7 +160,7 @@ export class Inbox extends Component<any, InboxState> {
<a
href={`/feeds/inbox/${UserService.Instance.auth}.xml`}
title="RSS"
rel="noopener"
rel={relTags}
>
<Icon icon="rss" classes="ml-2 text-muted small" />
</a>
Expand Down
3 changes: 2 additions & 1 deletion src/shared/components/person/person-listing.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from "inferno";
import { Link } from "inferno-router";
import { PersonSafe } from "lemmy-js-client";
import { hostname, isCakeDay, showAvatars } from "../../utils";
import { hostname, isCakeDay, relTags, showAvatars } from "../../utils";
import { PictrsImage } from "../common/pictrs-image";
import { CakeDay } from "./cake-day";

Expand Down Expand Up @@ -60,6 +60,7 @@ export class PersonListing extends Component<PersonListingProps, any> {
title={apubName}
className={this.props.muted ? "text-muted" : "text-info"}
href={link}
rel={relTags}
>
{this.avatarAndName(displayName)}
</a>
Expand Down
5 changes: 3 additions & 2 deletions src/shared/components/person/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
mdToHtml,
numToSI,
previewLines,
relTags,
restoreScrollPosition,
routeSortTypeToEnum,
saveCommentRes,
Expand Down Expand Up @@ -346,7 +347,7 @@ export class Profile extends Component<any, ProfileState> {
/>
<a
href={`/feeds/u/${this.state.userName}.xml?sort=${this.state.sort}`}
rel="noopener"
rel={relTags}
title="RSS"
>
<Icon icon="rss" classes="text-muted small mx-2" />
Expand Down Expand Up @@ -420,7 +421,7 @@ export class Profile extends Component<any, ProfileState> {
className={`d-flex align-self-start btn btn-secondary mr-2 ${
!pv.person.matrix_user_id && "invisible"
}`}
rel="noopener"
rel={relTags}
href={`https://matrix.to/#/${pv.person.matrix_user_id}`}
>
{i18n.t("send_secure_message")}
Expand Down
3 changes: 2 additions & 1 deletion src/shared/components/person/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
languages,
personSelectName,
personToChoice,
relTags,
setIsoData,
setTheme,
setupTippy,
Expand Down Expand Up @@ -466,7 +467,7 @@ export class Settings extends Component<any, SettingsState> {
</div>
<div class="form-group row">
<label class="col-sm-5 col-form-label" htmlFor="matrix-user-id">
<a href={elementUrl} rel="noopener">
<a href={elementUrl} rel={relTags}>
{i18n.t("matrix_user_id")}
</a>
</label>
Expand Down
5 changes: 3 additions & 2 deletions src/shared/components/post/metadata-card.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, linkEvent } from "inferno";
import { Post } from "lemmy-js-client";
import { relTags } from "shared/utils";
import { i18n } from "../../i18next";
import { Icon } from "../common/icon";

Expand Down Expand Up @@ -35,15 +36,15 @@ export class MetadataCard extends Component<
<div class="card-body">
{post.name !== post.embed_title && [
<h5 class="card-title d-inline">
<a class="text-body" href={post.url} rel="noopener">
<a class="text-body" href={post.url} rel={relTags}>
{post.embed_title}
</a>
</h5>,
<span class="d-inline-block ml-2 mb-2 small text-muted">
<a
class="text-muted font-italic"
href={post.url}
rel="noopener"
rel={relTags}
>
{new URL(post.url).hostname}
<Icon icon="external-link" classes="ml-1" />
Expand Down
7 changes: 4 additions & 3 deletions src/shared/components/post/post-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
isBrowser,
isImage,
pictrsDeleteToast,
relTags,
setupTippy,
toast,
validTitle,
Expand Down Expand Up @@ -219,7 +220,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
this.state.postForm.url
)}`}
class="mr-2 d-inline-block float-right text-muted small font-weight-bold"
rel="noopener"
rel={relTags}
>
archive.org {i18n.t("archive_link")}
</a>
Expand All @@ -228,7 +229,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
this.state.postForm.url
)}`}
class="mr-2 d-inline-block float-right text-muted small font-weight-bold"
rel="noopener"
rel={relTags}
>
ghostarchive.org {i18n.t("archive_link")}
</a>
Expand All @@ -237,7 +238,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
this.state.postForm.url
)}`}
class="mr-2 d-inline-block float-right text-muted small font-weight-bold"
rel="noopener"
rel={relTags}
>
archive.today {i18n.t("archive_link")}
</a>
Expand Down
9 changes: 5 additions & 4 deletions src/shared/components/post/post-listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
mdToHtml,
numToSI,
previewLines,
relTags,
setupTippy,
showScores,
wsClient,
Expand Down Expand Up @@ -225,7 +226,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
<a
class="float-right text-body d-inline-block position-relative mb-2"
href={post.url}
rel="noopener"
rel={relTags}
title={post.url}
>
{this.imgThumb(this.getImageSrc())}
Expand Down Expand Up @@ -253,7 +254,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
className="text-body"
href={post.url}
title={post.url}
rel="noopener"
rel={relTags}
>
<div class="thumbnail rounded bg-light d-flex justify-content-center">
<Icon icon="external-link" classes="d-flex align-items-center" />
Expand Down Expand Up @@ -316,7 +317,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
className="text-muted font-italic"
href={post_view.post.url}
title={post_view.post.url}
rel="noopener"
rel={relTags}
>
{hostname(post_view.post.url)}
</a>
Expand Down Expand Up @@ -399,7 +400,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
className={!post.stickied ? "text-body" : "text-primary"}
href={post.url}
title={post.url}
rel="noopener"
rel={relTags}
>
{post.name}
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
authField,
capitalizeFirstLetter,
isBrowser,
relTags,
setupTippy,
toast,
wsClient,
Expand Down Expand Up @@ -141,7 +142,7 @@ export class PrivateMessageForm extends Component<
#
<a
class="alert-link"
rel="noopener"
rel={relTags}
href="https://element.io/get-started"
>
#
Expand Down
2 changes: 2 additions & 0 deletions src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ export const postRefetchSeconds: number = 60 * 1000;
export const fetchLimit = 20;
export const mentionDropdownFetchLimit = 10;

export const relTags = "noopener nofollow";

export const languages = [
{ code: "ca" },
{ code: "en" },
Expand Down

0 comments on commit 7e2b2b2

Please sign in to comment.