66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import "server-only";
|
|
import { MessageCircle, Send, ArrowUpRight } from "lucide-react";
|
|
import { getI18n } from "@/lib/i18n";
|
|
|
|
function communityUrl(value: string | undefined, hosts: readonly string[]) {
|
|
if (!value?.trim()) return null;
|
|
try {
|
|
const url = new URL(value.trim());
|
|
if (
|
|
url.protocol !== "https:" ||
|
|
url.username ||
|
|
url.password ||
|
|
url.port ||
|
|
!hosts.includes(url.hostname) ||
|
|
url.pathname === "/"
|
|
)
|
|
return null;
|
|
return url.href;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export async function CommunityLinks() {
|
|
const { t } = await getI18n();
|
|
const discord = communityUrl(process.env.MINEGEO_DISCORD_URL, [
|
|
"discord.gg",
|
|
"discord.com",
|
|
"www.discord.com",
|
|
"discordapp.com",
|
|
]);
|
|
const telegram = communityUrl(process.env.MINEGEO_TELEGRAM_URL, [
|
|
"t.me",
|
|
"telegram.me",
|
|
]);
|
|
if (!discord && !telegram) return null;
|
|
return (
|
|
<div className="community-links" role="group" aria-label={t("Community")}>
|
|
{discord && (
|
|
<a
|
|
className="community-link community-discord"
|
|
href={discord}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
<MessageCircle size={18} aria-hidden="true" />
|
|
{t("Join us on Discord")}
|
|
<ArrowUpRight size={14} aria-hidden="true" />
|
|
</a>
|
|
)}
|
|
{telegram && (
|
|
<a
|
|
className="community-link community-telegram"
|
|
href={telegram}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
<Send size={18} aria-hidden="true" />
|
|
{t("Follow us on Telegram")}
|
|
<ArrowUpRight size={14} aria-hidden="true" />
|
|
</a>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|