Skip to content

Commit

Permalink
Don't open internal links in a new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmalloy committed Mar 3, 2024
1 parent 6d72cc2 commit f32c6f4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="row">
<div class="stack">
<h2 class="link blog-title" [class.remote]="!local">
<a *ngIf="clickableLink" [href]="ref.url | safe" target="_blank">{{ title }}</a>
<a *ngIf="clickableLink" [href]="ref.url | safe" target="{{ !localhost ? '_blank' : '' }}">{{ title }}</a>
<span *ngIf="!clickableLink">{{ title }}</span>
</h2>
<div class="link-below">
Expand Down
7 changes: 7 additions & 0 deletions src/app/component/blog/blog-entry/blog-entry.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { ScrapeService } from '../../../service/api/scrape.service';
import { TaggingService } from '../../../service/api/tagging.service';
import { AuthzService } from '../../../service/authz.service';
import { BookmarkService } from '../../../service/bookmark.service';
import { ConfigService } from '../../../service/config.service';
import { EditorService } from '../../../service/editor.service';
import { Store } from '../../../store/store';
import { downloadRef } from '../../../util/download';
Expand Down Expand Up @@ -85,6 +86,7 @@ export class BlogEntryComponent implements OnChanges, OnDestroy {
serverError: string[] = [];

constructor(
private config: ConfigService,
public admin: AdminService,
public store: Store,
private router: Router,
Expand Down Expand Up @@ -177,6 +179,11 @@ export class BlogEntryComponent implements OnChanges, OnDestroy {
return this.ref.origin === this.store.account.origin;
}

@memo
get localhost() {
return this.ref.url.startsWith(this.config.base);
}

@memo
get pdf() {
if (!this.admin.getPlugin('plugin/pdf')) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
(pointerenter)="allowActions = true"
(pointerleave)="allowActions = false">
<div [class.has-title]="clickableLink || title && !focused">
<a *ngIf="clickableLink && (title && !focused || !media)" [href]="url | safe" target="_blank">{{ title }}</a>
<a *ngIf="clickableLink && (title && !focused || !media)" [href]="url | safe" target="{{ !localhost ? '_blank' : '' }}">{{ title }}</a>
<span *ngIf="!clickableLink && (title && !focused || !expand)">{{ title }}</span>
<app-md *ngIf="focused && bareRef?.comment"
[origin]="ref.origin!"
Expand Down
7 changes: 7 additions & 0 deletions src/app/component/chat/chat-entry/chat-entry.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ExtService } from '../../../service/api/ext.service';
import { RefService } from '../../../service/api/ref.service';
import { TaggingService } from '../../../service/api/tagging.service';
import { AuthzService } from '../../../service/authz.service';
import { ConfigService } from '../../../service/config.service';
import { Store } from '../../../store/store';
import { authors, clickableLink, formatAuthor, getTitle } from '../../../util/format';
import { printError } from '../../../util/http';
Expand Down Expand Up @@ -46,6 +47,7 @@ export class ChatEntryComponent implements OnChanges {
private _allowActions = false;

constructor(
private config: ConfigService,
public admin: AdminService,
public store: Store,
private auth: AuthzService,
Expand Down Expand Up @@ -113,6 +115,11 @@ export class ChatEntryComponent implements OnChanges {
return this.ref.origin || '';
}

@memo
get localhost() {
return this.ref.url.startsWith(this.config.base);
}

@memo
get authors() {
return authors(this.ref, this.store.view.ext?.config?.authorTags || []);
Expand Down
2 changes: 1 addition & 1 deletion src/app/component/ref/ref.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
[class.redundant]="redundantLink"
[attr.title]="altText">
@if (clickableLink) {
<a [href]="link | safe" target="_blank">{{ title }}</a>
<a [href]="link | safe" target="{{ !localhost ? '_blank' : '' }}">{{ title }}</a>
} @else {
<a [routerLink]="defaultView ? ['/ref', url, defaultView] : ['/ref', url]" [queryParams]="{ origin: obsoleteOrigin }">{{ title }}</a><wbr>
}
Expand Down
5 changes: 5 additions & 0 deletions src/app/component/ref/ref.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ export class RefComponent implements OnChanges, AfterViewInit, OnDestroy {
return this.ref.origin === this.store.account.origin;
}

@memo
get localhost() {
return this.ref.url.startsWith(this.config.base);
}

@memo
get repost() {
return this.ref?.sources?.length && hasTag('plugin/repost', this.ref);
Expand Down

0 comments on commit f32c6f4

Please sign in to comment.