Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak how repo links are displayed #170

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions frontend/src/components/RepoSidebarBlock/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
import { github } from "@/icons/github";
import { Icon } from "../Icon";
import { SidebarBlock } from "../SidebarBlock";

function getLinkLabel(url: string) {
const match = url.match(/github\.com\/([^/]+)\/([^/]+)/);
try {
const parsedUrl = new URL(url);

if (!match) {
return null;
}
switch (parsedUrl.hostname) {
case "github.com": {
const pathParts = parsedUrl.pathname.split("/");

return `${match[1]}/${match[2]}`;
return (
<>
<Icon path={github} className="mt-1.5 size-em" />
<span>
{pathParts[1]}/{pathParts[2]}
</span>
</>
);
}
default:
return `${parsedUrl.hostname}${parsedUrl.pathname}`;
}
} catch {
return url;
}
}

interface BlockProps {
Expand All @@ -20,7 +37,7 @@ export function RepoSidebarBlock(props: BlockProps) {
{props.link ? (
<a
href={props.link}
className="underline"
className="inline-flex gap-2 underline"
target="_blank"
rel="noreferrer noopener"
>
Expand Down
Loading