From f040dac647d50c97e3f9ab8058563a7fe0f29261 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 14 Apr 2020 15:43:58 -0400 Subject: [PATCH] Initial post-listing community non-local. --- ui/src/components/post-listing.tsx | 75 +++++++++++++++++------------- ui/src/utils.ts | 14 ++++-- 2 files changed, 52 insertions(+), 37 deletions(-) diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index ff863dcb0..49970dfc1 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -30,6 +30,7 @@ import { showAvatars, pictshareImage, setupTippy, + hostname, } from '../utils'; import { i18n } from '../i18next'; @@ -149,9 +150,9 @@ export class PostListing extends Component { let post = this.props.post; return ( ); @@ -311,22 +312,21 @@ export class PostListing extends Component { )} - {post.url && - !(new URL(post.url).hostname == window.location.hostname) && ( - - - {new URL(post.url).hostname} - - - - - - )} + {post.url && !(hostname(post.url) == window.location.hostname) && ( + + + {hostname(post.url)} + + + + + + )} {(isImage(post.url) || this.props.post.thumbnail_url) && ( <> {!this.state.imageExpanded ? ( @@ -447,9 +447,15 @@ export class PostListing extends Component { {this.props.showCommunity && ( {i18n.t('to')} - - {post.community_name} - + {post.local ? ( + + {post.community_name} + + ) : ( + + {hostname(post.ap_id)}/{post.community_name} + + )} )} @@ -531,8 +537,9 @@ export class PostListing extends Component { } > @@ -575,8 +582,9 @@ export class PostListing extends Component { } > @@ -607,8 +615,9 @@ export class PostListing extends Component { data-tippy-content={i18n.t('view_source')} > @@ -628,8 +637,9 @@ export class PostListing extends Component { } > @@ -646,8 +656,9 @@ export class PostListing extends Component { } > diff --git a/ui/src/utils.ts b/ui/src/utils.ts index 8ecef19b6..e2310960d 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -109,11 +109,11 @@ export const md = new markdown_it({ typographer: true, }) .use(markdown_it_container, 'spoiler', { - validate: function(params: any) { + validate: function (params: any) { return params.trim().match(/^spoiler\s+(.*)$/); }, - render: function(tokens: any, idx: any) { + render: function (tokens: any, idx: any) { var m = tokens[idx].info.trim().match(/^spoiler\s+(.*)$/); if (tokens[idx].nesting === 1) { @@ -129,7 +129,7 @@ export const md = new markdown_it({ defs: objectFlip(emojiShortName), }); -md.renderer.rules.emoji = function(token, idx) { +md.renderer.rules.emoji = function (token, idx) { return twemoji.parse(token[idx].content); }; @@ -275,7 +275,7 @@ export function debounce( let timeout: any; // Calling debounce returns a new anonymous function - return function() { + return function () { // reference the context and args for the setTimeout function var context = this, args = arguments; @@ -291,7 +291,7 @@ export function debounce( clearTimeout(timeout); // Set the new timeout - timeout = setTimeout(function() { + timeout = setTimeout(function () { // Inside the timeout function, clear the timeout variable // which will let the next execution run when in 'immediate' mode timeout = null; @@ -823,3 +823,7 @@ function hsl(num: number) { function randomHsl() { return `hsla(${Math.random() * 360}, 100%, 50%, 1)`; } + +export function hostname(url: string): string { + return new URL(url).hostname; +}