From 7cb650dbd3381e9b3c6535707590bcb85d567797 Mon Sep 17 00:00:00 2001 From: Dessalines <tyhou13@gmx.com> Date: Tue, 13 Oct 2020 16:04:44 -0500 Subject: [PATCH] Fixing RSS for non-local communities. Fixes #53 --- src/shared/components/community.tsx | 6 +++++- src/shared/utils.ts | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/shared/components/community.tsx b/src/shared/components/community.tsx index 299456b..f430fe9 100644 --- a/src/shared/components/community.tsx +++ b/src/shared/components/community.tsx @@ -52,6 +52,7 @@ import { isBrowser, lemmyHttp, setAuth, + communityRSSUrl, } from '../utils'; import { i18n } from '../i18next'; @@ -320,7 +321,10 @@ export class Community extends Component<any, State> { <SortSelect sort={this.state.sort} onChange={this.handleSortChange} /> </span> <a - href={`/feeds/c/${this.state.communityName}.xml?sort=${this.state.sort}`} + href={communityRSSUrl( + this.state.communityRes.community.actor_id, + this.state.sort + )} target="_blank" title="RSS" rel="noopener" diff --git a/src/shared/utils.ts b/src/shared/utils.ts index b3479d3..5b14f0d 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -278,6 +278,11 @@ export function validURL(str: string) { // } } +export function communityRSSUrl(actorId: string, sort: string): string { + let url = new URL(actorId); + return `${url.origin}/feeds${url.pathname}.xml?sort=${sort}`; +} + export function validEmail(email: string) { let re = /^(([^\s"(),.:;<>@[\\\]]+(\.[^\s"(),.:;<>@[\\\]]+)*)|(".+"))@((\[(?:\d{1,3}\.){3}\d{1,3}])|(([\dA-Za-z\-]+\.)+[A-Za-z]{2,}))$/; return re.test(String(email).toLowerCase()); -- 2.44.1